Professional Documents
Culture Documents
2 Hypothesis Testing in R
Winter 2021
Mon: 4:30-6:20pm
Wed: 5:00-6:50pm
Professor: Clarence Au
Date: Apr 14th, 2021
Learning Objectives
12.7 Perform hypothesis tests using R.
Textbook
Practice Questions
Review – Finding P-values
Image
R CODE
n<-2000
p<-0.86/100
p.hat<-0.53/100
Example SD<-sqrt(p*(1-p)/n)
z<-(p.hat-p)/SD
p.value<-pnorm(z, 0, 1,
lower.tail=TRUE)
input
function_name<-function(var){
Do something a function
return(new_variable) }
output
function_name(var1, var2…)
Building a Hypothesis Testing Function
n p0 ^α
𝑝 Alternative (One sided/two sided)
q = 1- p 1) Negative (do
SD() nothing)
2) Positive (set to
negative z)
p-value = pnorm(z, 0, 1, lower.tail= TRUE)
1) One sided (<, >) =
1xpnorm
2) Two sided (≠) =
2xpnorm