Winter 2025 ……………………………….. Score ____ / 20

Homework #1

[Heidi Van Ness]

___________________________________________

highlight and click “Run” the line below before knitting

install.packages(“rmarkdown”)

# set seed replace 12345678 with your student ID
seed = 7894492
# loads in data for the full population
pop<-read.csv("HW1.csv", header = T)
set.seed(seed + 25)
# 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 data table for 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) 
table
##    X f
## 1 10 5
## 2 11 1
## 3 12 3
## 4 13 8
## 5 14 5
## 6 15 3
## 7 16 4
# one sample t-test
t.test(data$X,mu=15)
## 
##  One Sample t-test
## 
## data:  data$X
## t = -5.2819, df = 28, p-value = 1.284e-05
## alternative hypothesis: true mean is not equal to 15
## 95 percent confidence interval:
##  12.36794 13.83896
## sample estimates:
## mean of x 
##  13.10345
# 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))