R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

#1a. plot(Lungs\(age,Lungs\)FEV,main=“Forced Exhalation Volume vs. Age”,xlab=“Child’s Age in Years”,ylab=“Forced Exhalation Volume in Liters”) the.model<-lm(FEV~age,data=Lungs) abline(the.model,col=“green”,lwd=2)

#1b. #The units of X seem fixed as each cluster of points are in a vertical straight line for each age.

#1c. #Yes the variance seems to be constant as it seems like the line seems equidistant from each point above and below it.

#1d. the.model$coefficients #The line is Y^=0.43+(0.22)X1

#1e. se<-summary(the.model)$sigma print(se) #Se is 0.57

#2a. xa<-data.frame(age=10) ya<-predict(the.model,xa) print(ya) xb<-data.frame(age=15) yb<-predict(the.model,xb) print(yb) #The expected average difference in FEV is 3.76 - 2.65 = 1.11 liters.

#2b. xc<-data.frame(age=8) yc<-predict(the.model,xc) print(yc) #The FEV for a child aged 8 is estimated to be 2.21 liters.

#2c. Lungs\(ei<-the.model\)residuals reorder.Lungs<-Lungs[order(abs(the.model$residuals)),] tail(reorder.Lungs) #The rows with the highest absolute errors are # age FEV ei #559 11 4.637 1.762901 #517 13 5.083 1.764819 #504 10 4.591 1.938942 #624 15 5.793 2.030737 #452 12 5.224 2.127860

#2d. #I don’t agree because the regression line may not necessarily go through (0,0), as a lot of the time the line will have an intercept, so the average error may not be 0

#3a. plot(Fitness\(Tread,Fitness\)Run,main=“Run vs. Tread”,xlab=“Treadmill High Intensity Time”,ylab=“10K Run Time in Minutes”) the.model<-lm(Run~Tread,data=Fitness) abline(the.model,col=“green”,lwd=2)

#3b. the.model$coefficients #The equation for the line is Y^=59.92+(-1.96)X1

#3c. #As an athlete spends more time doing high intensity training on the treadmill, the time it takes them to run 10 kilometers decreases.

#3d. #Yes, becauset the time is not negative, and time can only be positive.

#3e. SSE<-round(sum(the.model$residuals^2),2) print(SSE) #The SSE is about 66.42

#4a. #The expected time it would increase by is (1.96)*2=3.92 minutes

#4b. Fitness\(ei<-the.model\)residuals fitnesseissquared<-Fitness\(ei*Fitness\)ei fitnesseissquaredsum<-sum(fitnesseissquared) print(fitnesseissquaredsum) #The sum of the residuals squared is 66.42

#4c. #The estimated error associated with the first row is 0.22

#4d. xa<-data.frame(Tread=8.5) ya<-predict(the.model,xa) print(ya) #The average value of Y at X=8.5 is 43.26