#Z test means z.test.pvalue<-function(xbar, mu, sigma, n, tails){ z=(xbar-mu)*sqrt(n)/sigma if (z<0) {pv=pnorm(z, lower.tail = T)} else {pv=pnorm(z,lower.tail = F)} z<-round(z,2) v1<-c(z, pv) v2<-c(z, 2*pv) if(tails==1) {return(v1)} if (tails==2) {return(v2)} } z.test.pvalue(9.5,10,0.8,20,2) #Z test proportions z.test.prop.pvalue<-function(x, n, p, tails){ z=(x/n - p)/sqrt(p*(1-p)/n) if (z<0) {pv=pnorm(z, lower.tail = T)} else {pv=pnorm(z,lower.tail = F)} z<-round(z, 2) v1<-c(z, pv) v2<-c(z, 2*pv) if(tails==1) {return(v1)} if(tails==2) {return(v2)} } # t test means t.test.pvalue<-function(xbar, mu, s, n, tails){ t=(xbar-mu)*sqrt(n)/s if (t<0) {pv=pt(t, n-1,lower.tail = T)} else {pv=pt(t, n-1,lower.tail = F)} t<-round(t,2) v1<-c(t, pv) v2<-c(t, 2*pv) if(tails==1) {return(v1)} if (tails==2) {return(v2)} } t.test.pvalue(57,60,3.0,20,2)#example t test with summary # 2 SAMPLES #two proportions: #prop.test(x=c(x1,x2), n=c(n1,n2), alternative="*", correct=F, conf.level= ) prop.test(x=c(38,23), n=c(85,90),alternative ="greater", correct=F ) # two porportions example # two means t test: install.packages("BSDA") require(BSDA) #tsum.test(mean1,s1,n1,mean2,s2,n2,alt="two.sided",conf.level=.95) # "two.sided", "less", "greater" tsum.test(5.9,4.1,42,4.1,3.7,47, alt="greater",conf.level=.99) #exapmle two means t test with summary # t.test(x, y , alternative = " * " mu =0, paired = FALSE, var.equal = FALSE, conf.level = ) # where x and y are vectors of raw data. x<-c(495,760,556,904,520,1005,743,660)# question 6 on Practice 9 y<-c(722,562,880,520,500,1250,750,1640,518,904,1150,805,480,970,605) t.test(x, y , alternative ="less", mu =0, paired = FALSE, var.equal = FALSE)