This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#non-parametric tests in R | |
dengue.fewer <-c(3000,3200,3500,5068,5679,6200,6300,7020) | |
scrub.typhus<-c(4400,4500,5900,6839,7561,9047,12300,14000) | |
wilcox.test(dengue.fewer,scrub.typhus) | |
t.test(dengue.fewer,scrub.typhus,var.equal=T) | |
ttest.wilcox.examples <- function(x,y,z,k) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Conducting t-tests in R. | |
t.test(death_rt) | |
t.test(lifeexpf, lifeexpm) | |
t.test(lifeexpf, lifeexpm, var.equal=T) | |
t.test(lifeexpf, lifeexpm, paired=T) | |
#A function for creating random examples of t-tests | |
ttest.for.examination <- function(x,y,z,k) | |
{ | |
subjects <- x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Visualising Hypothesis Tests in R | |
#The red distribution is what you can expect to see if you plot repeated samples when the null hypothesis is true. | |
#You can recognize the Ho because it sounds like: "there was no difference", for instance: "The intervention did not affect the tumor marker." | |
#one tailed test | |
#rare in health sciences, more common in industrial process control | |
x=seq(50,140,length=200) | |
y1=dnorm(x,80, 10) | |
plot(x,y1,type='l',lwd=2,col='red') | |
y2=dnorm(x,110, 10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Shapiro test shows whether the variables have a normal distribution | |
shapiro.test(lifeexpf) | |
shapiro.test(lifeexpm) | |
shapiro.test(birth_rt) | |
shapiro.test(death_rt) | |
shapiro.test(world[,2]) | |
shapiro.test(world[,3]) | |
shapiro.test(world[,5]) | |
#We are alomst 100% sure that NONE of the variables follows a normal distribution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Probability Distributions in R | |
#BINOMINAL DISTRIBUTION | |
?dbinom | |
x <- 0:30 | |
#binominal - density | |
plot(x, dbinom(x, 30, 0.5), type = "h") | |
#binominal - cumulative distribution function | |
plot(x, pbinom(x, 30, 0.5), type = "h") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Principal Component Analysis with R using the library FacoMineR | |
#1)preliminaries | |
#adding the file to R | |
auto<-read.table("auto2004.csv", header=TRUE, sep=",") | |
#viewing the structure of the file | |
str(auto) | |
#attaching the file to the R memory | |
attach(auto) | |
#installing the library FactoMineR | |
library(FactoMineR) |