install.packages(“rmarkdown”)
# sets wd to the path on my computer;
setwd("C:\\Users\\hmon1\\Desktop\\10B+Homework\\") #this is where you downloaded the HW1.csv file
# loads in data for the full population
pop<-read.csv("HW8.csv", header = T)
# sets the seed for the random number generator
set.seed(48183130) #use your student ID instead of 12345678
# assigns a "random" sample of 29 from the population to 'data'
data<-data.frame(X=as.numeric(pop[sample(1:nrow(pop), 29, replace=FALSE),]))
#creates a frequency table to fill in your homework
tmpX = c(); tmpf = c() # initialize vectors to save values
for (xi in unique(sort(data$X))){ # for each unique value of X
tmpX = c(tmpX,xi) # save that value to the vector tmpX
tmpf = c(tmpf,sum(data$X == xi)) # save the number of times that value appears in data
# in the vectof tmpf
}
table = data.frame(X=tmpX, f = tmpf) #fill in the table on your homework
table
## X f
## 1 10 3
## 2 11 4
## 3 12 8
## 4 13 3
## 5 14 4
## 6 15 3
## 7 16 4
# calculates standard deviation
sd <- sd(data$X)
n <- length(data$X)
sd
## [1] 1.915069
n
## [1] 29
# calculates standard error of sampling distribution
SE <-sd/sqrt(n)
SE
## [1] 0.3556193
# one sample t-test
t.test(data$X,mu=15)
##
## One Sample t-test
##
## data: data$X
## t = -5.9149, df = 28, p-value = 2.302e-06
## alternative hypothesis: true mean is not equal to 15
## 95 percent confidence interval:
## 12.1681 13.6250
## sample estimates:
## mean of x
## 12.89655
# creates histogram
low <- (min(data$X)-2)
high <- (max(data$X)+2)
hist(data$X, main="Histogram", xlab = "X", breaks=seq(low,high,by=1), xlim=c(low,high), right=F)
axis(side=1, at=seq(low,high,1))