#inference of a binomial proportion # Two-sided p-value binom.test(6,7,0.15,alternative="two.sided") # Install and load package "binom" library(binom) # Compute point and interval estimate binom.confint(x=6,n=7,conf.level=0.95,methods='all') #################################################################### #inference for a median sodium=c(72.1, 72.8, 72.9, 73.3, 73.3, 73.3, 73.9, 74.0, 74.2, 74.2, 74.3, 74.6, 74.7, 75.0, 75.1, 75.1, 75.2, 75.3, 75.3, 75.3, 75.4, 76.1, 76.5, 76.5, 76.6, 76.9, 77.1, 77.2, 77.4, 77.4, 77.7, 78.0, 78.3, 78.6, 78.8, 78.9, 79.7, 80.3, 80.5, 81.0) sum(sodium>75) #total number of obs. that >75 #test for Ha: median > 75 is equivalent to test for Ha: p > 0.5 binom.test(sum(sodium>75),40,0.5,alternative="greater") #################################################################### #Input raw data drug1=c(74,55,61,41,53,74,52,31,50,58,54,53,69,60,61,54,57) drug2=c(63,58,49,47,50,69,67,40,44,38,56,38,47,41,46,47,44) #Wilcoxon signed-rank test (two sided) wilcox.test(drug1, drug2, paired=TRUE, alternative="two.sided") #################################################################### #Input raw data drug1=c(0.7,-1.6,-0.2,-1.2,-0.1,3.4,3.7,0.8,0.0,2.0) drug2=c(1.9,0.8,1.1,0.1,-0.1,4.4,5.5,1.6,4.6,5.4) #Wilcoxon rank-sum test (two sided) wilcox.test(drug1, drug2, paired=FALSE, alternative="two.sided") #################################################################### #input data as a list gizzards<-list(site.I=c(46,28,46,37,32,41,42,45,38,44), site.II=c(42,60,32,42,45,58,27,51,42,52), site.III=c(38,33,26,25,28,28,26,27,27,27), site.IV=c(31,30,27,29,30,25,25,24,27,30)) kruskal.test(gizzards) #install and load the PMCMRplus package library(PMCMRplus) ##ALL pairwise comparisons, Dwass, Steel, Critchlow-Fligner procedure, large sample approximation dscfAllPairsTest(gizzards) #################################################################### #input data collagen=c(7.1,7.1,7.2,8.3,9.4,10.5,11.4) proline=c(2.8,2.9,2.8,2.6,3.5,4.6,5.0) x=data.frame(collagen,proline) #compute and test Spearman's correlation coefficient cor.test(x$collagen, x$proline, method = "spearm") #################################################################### #import data x=read.table("R://Teaching/Training materials/R course/non-parametric/6-mp.dat", header=TRUE) #show first 10 observations x[1:10,] #install and load the survival package library(survival) #compute Kaplan-Meier estimate and confidence intervals surv=survfit(Surv(time, delta) ~ group, conf.type = "log-log") summary(surv) #Kaplan-Meier curves plot(surv, lty = 1:2, xlab = "Time of remission (weeks)", ylab = "Survival probability") #plot(surv, conf.int = T, lty = 1:2, xlab = "Time of remission (weeks)", ylab = "Survival probability") legend('topright', c("control", "6-MP"), lty = 1:2, lwd = 2) #median survival time and confidence interval survfit(Surv(time, delta) ~ group, conf.type = "log-log") #log-rank test for differnces between the two groups survdiff(Surv(time, delta) ~ group)