install.packages(“rmarkdown”)
# set seed replace 12345678 with your student IDseed = 17069600
# loads in data for the full populationpop<-read.csv("HW1.csv", head = TRUE)names(pop) <- c("X", "Y")
# sets the seed for the random number generatorset.seed(seed)
# assigns a "random" sample of 12 from the population to 'data'data<-pop[sample(nrow(pop), 12, replace=FALSE),]# use this datadata
## X Y## 658 9 8## 610 7 6## 794 10 7## 369 10 7## 381 8 10## 624 4 4## 188 8 6## 485 7 6## 914 11 7## 64 10 7## 654 10 8## 531 7 6
# regressionmodel <- lm(Y ~ X, data=data)summary(model)
## ## Call:## lm(formula = Y ~ X, data = data)## ## Residuals:## Min 1Q Median 3Q Max ## -0.9670 -0.5587 -0.3699 -0.0408 3.3495 ## ## Coefficients:## Estimate Std. Error t value Pr(>|t|) ## (Intercept) 3.1398 1.6342 1.921 0.0836 .## X 0.4388 0.1894 2.316 0.0430 *## ---## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1## ## Residual standard error: 1.241 on 10 degrees of freedom## Multiple R-squared: 0.3492, Adjusted R-squared: 0.2841 ## F-statistic: 5.366 on 1 and 10 DF, p-value: 0.04303
# creates plotplot(data$X, data$Y, main=c(paste("Scatterplot")), xlim=c(0,15), ylim=c(0,15), xaxs = "i", yaxs = "i", xlab="X", ylab="Y")abline(lm(Y ~ X, data=data))