statistics

profilenada1994

* attached the HW that need to be done aug, 8th at 8.00 pm PST ( 5 hours from now )

* I will email the Datasets file to you because I couldnt attached it here.

Code for Data Analysis: 

In R go to File< New Script (New Document on MAC) – A new script window will pop up. You should write all of your code in a script window and not directly in the console.

The R code can be uploaded directly into R by copying and pasting everything below R Code DA5 into a script window.

Note: Any time you see # this means that R will not read what follows. I will use this to make comments about the following command. 

R Code DA5

#Upload Data

NFL2015DATA = read.csv(file.choose(), header = TRUE)



#Look at data

head(NFL2015DATA)



# Attach Data Set! Very Important Step!

# This allows you to not call the variable every time!



attach(NFL2015DATA)



# Create a scatterplot to visualize the relationship between TotPts and PercentWins

plot(TotPts, PercentWins, main = "Relationship between Total Season Points

     and Percent of Wins for 2015 Season", pch = 16, col = "darkgreen",

     xlab = "Total Points for 2015 Season", ylab = "Win Percentage for Regular 2015 Season")



# Calculate the correlation coefficient between TotPts and PercentWins

cor(TotPts, PercentWins)



# Obtain the least squares regression line and t test for the slope p-value

mod = lm(PercentWins~TotPts)

summary(mod)



# Calculate the 95% CI for the slope.

confint(mod, level = 0.95)



# Plot the residuals for the analysis between TotPts and PercentWins

plot(TotPts, mod$residuals, main = "Residuals")

abline(h = 0, lty =2, lwd = 2)



# Create a scatterplot to visualize the relationship between TotPts and PercentWins

# add least squares regression line to plot

plot(TotPts, PercentWins, main = "Relationship between Total Season Points

     and Percent of wins for 2015 Season", pch = 16, col = "darkgreen",

     xlab = "Total Points for 2015 Season", ylab = "Win Percentage for Regular 2015 Season")

abline(mod$coef[1], mod$coef[2], lwd = 2,col = "blue")



# Predict the Percent of wins for the Seattle Seahawks that had a Total Season Point value of 423. 

predict(mod, data.frame(TotPts = 423))



# Calculate a 95% confidence interval for when the Percent of wins when Total Season Points is 423.

predict(mod, data.frame(TotPts = 423), interval = "confidence", level = 0.95)



# Calculate a 95% prediction interval for when the Percent of wins when Total Season Points is 423.

predict(mod, data.frame(TotPts = 423), interval = "prediction", level = 0.95)



#PART II OTHER POSSIBLE MODELS (STUDENTS_ YOU DONT NEED TO DO THIS...) 

mod2 = lm(PercentWins~TD_TOTAL+FGM+PCT_XPTSM+SFTY+X2PT_CONVERSION)

summary(mod2)



# Look for collinearity 

pairs(cbind(PercentWins,TD_TOTAL,FGM,PCT_XPTSM,SFTY,X2PT_CONVERSION))



# Use this model

mod3 = lm(PercentWins~TD_TOTAL+FGM)

summary(mod3)

anova(mod3)

  • 10 years ago
  • 30
Answer(2)

Purchase the answer to view it

blurred-text
  • attachment
    r_homework.docx

Purchase the answer to view it

blurred-text
  • attachment
    st314_analysis_5_0.docx