In: Math
Please use R to do it.
Using the SATGPA data set in Stat2Data package. Test by using α= .05
Question: Test if the proportion of MathSAT greater than VerbalSAT is 0.60
> library(Stat2Data)
> data("SATGPA")
> data(SATGPA)
> SATGPA
Let p bet the true proportion of MathSAT greater than VerbalSAT. We want to test if the proportion of MathSAT greater than VerbalSAT is 0.60, that is we want to test if p=0.60
The hypotheses are
The hypothesized value of proportion is
The standard error of proportions is
let be the sample proportion of MathSAT greater than VerbalSAT
The test statistics is
This is a 2 tailed test. The p-value is
We will reject the null hypothesis if the p-value is less than alpha=0.05.
R code to do all the above (all statements starting with # are comments and can be removed)
#install the package for the first time
install.packages('Stat2Data')
#load the library
library(Stat2Data)
#load the data
data(SATGPA)
#check some records
head(SATGPA)
#calculate the sample size
n<-nrow(SATGPA)
#calculate the sample proportion
phat<-sum(SATGPA$MathSAT>SATGPA$VerbalSAT)/n
#set the hypothesized value of p
p0<-0.60
#calculate the standard error of proportion
se<-sqrt(p0*(1-p0)/n)
#calculate the test statistics
z<-(phat-p0)/se
#calculate the p-value for 2 sided test
pval<-2*(1-pnorm(z))
#print the statsitics
sprintf('The sample proportion is %.4f',phat)
sprintf('The standard error is %.4f',se)
sprintf('The test statistics is %.2f',z)
sprintf('The p-value is %.4f',pval)
if (pval<0.05) {
sprintf('Reject the null hypothesis')
} else {
sprintf('Fail to reject the null hypothesis')
}
#get this
We fail to reject the null hypothesis.
We conclude that there is no sufficient evidence to reject the claim that the proportion of MathSAT greater than VerbalSAT is 0.60
Or
We conclude that the proportion of MathSAT greater than VerbalSAT is 0.60