library(ISwR) data(energy) energy attach(energy) ###Normality Test tapply(expend, stature, shapiro.test) t.test(expend~stature, var.equal=T) ###Varyans Test var.test(expend~stature) ###Independent T Test t.test(expend~stature, var.equal=T) ###Summary tapply(expend,stature,mean) tapply(expend,stature,sd) xbar<-tapply(expend,stature,mean) s<-tapply(expend,stature,sd) n<-tapply(expend,stature,length) m<-tapply(expend,stature, min) ma<-tapply(expend,stature, max) cbind(mean=xbar, std.dev=s, n=n, min=m, max=ma) ###Welch Two Sample t-test t.test(expend~stature) ### WILCOXON.TEST wilcox.test(expend~stature) ###Wilcoxon rank sum test with continuity correction data: expend by stature W = 12, p-value = 0.002122 alternative hypothesis: true location shift is not equal to 0 Warning message: In wilcox.test.default(x = c(7.53, 7.48, 8.08, 8.09, 10.15, 8.4, : cannot compute exact p-value with ties ###################################################### ###PAIRED T TEST data(intake) attach(intake) intake shapiro.test(intake$pre) shapiro.test(intake$post) t.test(pre, post, paired=T) summary(pre) summary(post) ###WILCOXON SIGN TEST wilcox.test(pre, post, paired=T) ####ANOVA data(red.cell.folate) attach(red.cell.folate) summary(red.cell.folate) anova(lm(folate~ventilation)) aov(lm(folate~ventilation)) aov(formula = lm(folate ~ ventilation)) ###Coefficients lm(formula = folate ~ ventilation) ###HOMOGENEITY OF VARIANCES(Bartlett test or Levene test ) bartlett.test(folate~ventilation) levene.test(folate~ventilation) ### we need to install package(car) ###POST HOC TEST pairwise.t.test(red.cell.folate$folate, red.cell.folate$ventilation, p.adjust.method = "bonferroni") pairwise.t.test(red.cell.folate$folate, red.cell.folate$ventilation, p.adjust.method = "holm") boxplot(folate ~ ventilation, xlab="ventilation", ylab="folate", las=1,) ###KRUSKAL WALLIS H TEST kruskal.test(folate~ventilation) pairwise.wilcox.test(red.cell.folate$folate, red.cell.folate$ventilation, p.adjust.method = "bonferroni")