1 Testing Hypotheses about proportions

Step 1: Formulate Hypotheses (PARAMETERS)

#Step 1:  Formulate Hypotheses (PARAMETERS)
# Assign the value from H0 to p
p0 <- .9

Step 2: Calcualte the standardized test statistic

n <- 400
phat <- 330/400 #or a percent if given

zstat <- (phat - p0)/sqrt(p0*(1-p0)/n)

cat("The standardized test statistic is",zstat)
The standardized test statistic is -5

Step 3: Calcualte the P-value

#P-value = P(get what you got or more when Ho is true)

#less than
LTPval <- pnorm(zstat)
#greater than
GTPval <- 1-pnorm(zstat)
#not equal
NEPval <- 2*pnorm(-abs(zstat))

cat("P-value is")
P-value is
list(Less=LTPval,Greater=GTPval,NotEqual=NEPval)
$Less
[1] 2.866516e-07

$Greater
[1] 0.9999997

$NotEqual
[1] 5.733031e-07

Step 4: Conclusion

#Statistical conclusion: A) Reject Ho if P-val < alpha (use .05 if none given)
#                         B) Fail to reject Ho if P-val > alpha

#English conclusion: A) There IS evidence of Ha (written to match problem)
#                     B) There is NOT evidence of Ha.

# End of Hypotheses about proportions

1.1 Checking assumptions

# Check assumptions

#Independence
#Randomization
#Less than 10% of the population in the sample
#Success/Failure

n <- 400

n*p0 > 10 
[1] TRUE
n*(1-p0) >10
[1] TRUE
#need this to be TRUE TRUE to continue

2 Testing Hypotheses about mean \(\mu\)

Step 0: Find(or enter) the sample mean (\(\bar{y}\)) and standard deviation (\(s\)) and \(n\)

ybar <- 12.5
s <- 2

n <- 25

Step 1: Formulate Hypotheses (PARAMETERS)

#Step 1:  Formulate Hypotheses (PARAMETERS)

mu0 <- 10 #This is the value in H0 : mu = mu0

Step 2: Calcualte the standardized test statistic

# Step 2:  Calcualte the standardized test statistic
tstat <- (ybar - mu0)/(s/sqrt(n))

cat("The t-stat is",tstat)
The t-stat is 6.25

Step 3: Calcualte the P-value

#P-value = P(get what you got or more when Ho is true)

df <- n - 1 # degrees of freedom

#less
LTPval<- pt(tstat,df)

#more
GTPval<- 1-pt(tstat,df)

#not equal
NEPval <- 2*pt(-abs(tstat), df)

list(Less=LTPval,Greater=GTPval,NotEqual=NEPval)
$Less
[1] 0.9999991

$Greater
[1] 9.242959e-07

$NotEqual
[1] 1.848592e-06

Step 4: Conclusion

#Statistical conclusion: A) Reject Ho if P-val < alpha (use .05 if none given)
#                         B) Fail to reject Ho if P-val > alpha

#English conclusion: A) There IS evidence of Ha (written to match problem)
#                     B) There is NOT evidence of Ha.

# End of Hypotheses about the mean

2.1 Sample size to estimate \(\mu\) within a given ME

You write it!

CIlev <- .95
s <- 29.31
ME <- 0.02

alpha <- 1-CIlev
alphaovertwo <- alpha/2
oneminusalphaovertwo <- 1- alpha/2
zinCI <- qnorm(oneminusalphaovertwo)

nprelim <- (zinCI * s/ME)^2
df <- nprelim-1

tstar <- qt(oneminusalphaovertwo,df)

nfinal <- (tstar * s/ME)^2
ceiling(nfinal)
[1] 8250267