install.packages(“rmarkdown”)
setwd("C:/Users/hmon1/Desktop/10A Homework") #this is where you downloaded the HW4.csv file
pop<-read.csv("HW4.csv")
set.seed(48183130) #use your student ID instead of 12345678
data<-data.frame(X=pop[sample(1:nrow(pop), 200, replace=FALSE),])
popp<-mean(pop$X) #calculates population proportion
popp
## [1] 0.2
sdpop<-sqrt(popp*(1-popp)) #calculates standard deviation of population proportion
sdpop
## [1] 0.4
sampp<-mean(data$X) #calculates proportion of sample
sampp
## [1] 0.185
n<-length(data$X) #creates sample size n
sesampd<-round((sqrt((popp*(1-popp))/n)),3) #calculates standard error of sampling distribution
sesampd
## [1] 0.028
Z<-round(((sampp-popp)/sesampd),2) #calculates standard score
Z
## [1] -0.54
prob<-round(pnorm(Z), digits=4) #calculates probability of getting your proportion or less
prob
## [1] 0.2946