The two-sample Z-test in R

We can run such a test in R, using the package BSDA, and its function z.test. Lets try it.

# install.packages("BSDA")   #first install the library, if you have not this library installed....simply remove the # sign and run this line
library ("BSDA")           #load the library

Drug_Mean=9.78   
Drug_SDSD=4.05
Drug_n =900   #sample size for the drug treatment

Placebo_Mean=15.10
Placebo_SD=4.28
Placebo_n=1000 #sample size for the placebo treatment

zsum.test(mean.x=Drug_Mean, sigma.x = Drug_SDSD, n.x = Drug_n,
          mean.y = Placebo_Mean, sigma.y = Placebo_SD, n.y = Placebo_n, 
          alternative = "two.sided", mu = 0,conf.level = 0.95)


#the parameters needed to run a Z-test are self-explanatory, similar to the one-sample test. x would indicate the data for the drug and y the data for the placebo. In this case, we are testing a two-tail hypothesis.
Z-test results for two samples from R

Figure 11.4: Z-test results for two samples from R