Batter up

The movie Moneyball focuses on the “quest for the secret of success in baseball”. It follows a low-budget team, the Oakland Athletics, who believed that underused statistics, such as a player’s ability to get on base, betterpredict the ability to score runs than typical statistics like home runs, RBIs (runs batted in), and batting average. Obtaining players who excelled in these underused statistics turned out to be much more affordable for the team.

In this lab we’ll be looking at data from all 30 Major League Baseball teams and examining the linear relationship between runs scored in a season and a number of other player statistics. Our aim will be to summarize these relationships both graphically and numerically in order to find which variable, if any, helps us best predict a team’s runs scored in a season.

The data

Let’s load up the data for the 2011 season.

load("more/mlb11.RData")

In addition to runs scored, there are seven traditionally used variables in the data set: at-bats, hits, home runs, batting average, strikeouts, stolen bases, and wins. There are also three newer variables: on-base percentage, slugging percentage, and on-base plus slugging. For the first portion of the analysis we’ll consider the seven traditional variables. At the end of the lab, you’ll work with the newer variables on your own.

  1. What type of plot would you use to display the relationship between runs and one of the other numerical variables? Plot this relationship using the variable at_bats as the predictor. Does the relationship look linear? If you knew a team’s at_bats, would you be comfortable using a linear model to predict the number of runs?

A: I would use scatterplots to display the relationship between runs and one other numerical variable.

According to visual examination of the plot, the relationship between runs and at_bats look linear. Yes, I would apply the linear model to predict the number of runs.

le <- lm(mlb11$runs ~ mlb11$at_bats)
plot(mlb11$runs ~ mlb11$at_bats)

abline(le)

If the relationship looks linear, we can quantify the strength of the relationship with the correlation coefficient.

cor(mlb11$runs, mlb11$at_bats)
## [1] 0.610627

Sum of squared residuals

Think back to the way that we described the distribution of a single variable. Recall that we discussed characteristics such as center, spread, and shape. It’s also useful to be able to describe the relationship of two numerical variables, such as runs and at_bats above.

  1. Looking at your plot from the previous exercise, describe the relationship between these two variables. Make sure to discuss the form, direction, and strength of the relationship as well as any unusual observations.

A: According to visual examination, observations appear scattered, and plot suggests the upward trend. There are some outliers. The relationship is not entirely linear as observations do not fall around the straight line. However, plot explains the connection between the variables with a straight line.

Just as we used the mean and standard deviation to summarize a single variable, we can summarize the relationship between these two variables by finding the line that best follows their association. Use the following interactive function to select the line that you think does the best job of going through the cloud of points.

plot_ss(x = mlb11$at_bats, y = mlb11$runs)

## Click two points to make a line.
                                
## Call:
## lm(formula = y ~ x, data = pts)
## 
## Coefficients:
## (Intercept)            x  
##  -2789.2429       0.6305  
## 
## Sum of Squares:  123721.9

After running this command, you’ll be prompted to click two points on the plot to define a line. Once you’ve done that, the line you specified will be shown in black and the residuals in blue. Note that there are 30 residuals, one for each of the 30 observations. Recall that the residuals are the difference between the observed values and the values predicted by the line:

\[ e_i = y_i - \hat{y}_i \]

The most common way to do linear regression is to select the line that minimizes the sum of squared residuals. To visualize the squared residuals, you can rerun the plot command and add the argument showSquares = TRUE.

plot_ss(x = mlb11$at_bats, y = mlb11$runs, showSquares = TRUE, leastSquares = TRUE)

## 
                                
## Call:
## lm(formula = y ~ x)
## 
## Coefficients:
## (Intercept)            x  
##  -2789.2429       0.6305  
## 
## Sum of Squares:  123721.9

Note that the output from the plot_ss function provides you with the slope and intercept of your line as well as the sum of squares.

  1. Using plot_ss, choose a line that does a good job of minimizing the sum of squares. Run the function several times. What was the smallest sum of squares that you got? How does it compare to your neighbors?

A: Sum of squares is a measure of how a data set varies around a central number, similar to mean. I got higher value 197281.2 while calculating manually using mean. Least sum of squares calculated using plot_ss function resulted in lower value 123721.9.

m.cal <- data.frame(x=mlb11$at_bats, y=mlb11$runs)
m.cal.x.mean = mean(m.cal$x)
m.cal.y.mean = mean(m.cal$y)
m.cal.x.sd = sd(m.cal$x)
m.cal.y.sd = sd(m.cal$y)

m.cal$xsq <- (m.cal$x - m.cal.x.mean)^2
m.cal$ysq <- (m.cal$y - m.cal.y.mean)^2

sum(m.cal$ysq)
## [1] 197281.2

The linear model

It is rather cumbersome to try to get the correct least squares line, i.e. the line that minimizes the sum of squared residuals, through trial and error. Instead we can use the lm function in R to fit the linear model (a.k.a. regression line).

m1 <- lm(runs ~ at_bats, data = mlb11)

The first argument in the function lm is a formula that takes the form y ~ x. Here it can be read that we want to make a linear model of runs as a function of at_bats. The second argument specifies that R should look in the mlb11 data frame to find the runs and at_bats variables.

The output of lm is an object that contains all of the information we need about the linear model that was just fit. We can access this information using the summary function.

summary(m1)
## 
## Call:
## lm(formula = runs ~ at_bats, data = mlb11)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -125.58  -47.05  -16.59   54.40  176.87 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2789.2429   853.6957  -3.267 0.002871 ** 
## at_bats         0.6305     0.1545   4.080 0.000339 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 66.47 on 28 degrees of freedom
## Multiple R-squared:  0.3729, Adjusted R-squared:  0.3505 
## F-statistic: 16.65 on 1 and 28 DF,  p-value: 0.0003388

Let’s consider this output piece by piece. First, the formula used to describe the model is shown at the top. After the formula you find the five-number summary of the residuals. The “Coefficients” table shown next is key; its first column displays the linear model’s y-intercept and the coefficient of at_bats. With this table, we can write down the least squares regression line for the linear model:

\[ \hat{y} = -2789.2429 + 0.6305 * atbats \]

One last piece of information we will discuss from the summary output is the Multiple R-squared, or more simply, \(R^2\). The \(R^2\) value represents the proportion of variability in the response variable that is explained by the explanatory variable. For this model, 37.3% of the variability in runs is explained by at-bats.

  1. Fit a new model that uses homeruns to predict runs. Using the estimates from the R output, write the equation of the regression line. What does the slope tell us in the context of the relationship between success of a team and its home runs?

A: \[\hat{runs} = 415.2389 + 1.8345 * homeruns\]

Equation is set up to predict the total number of runs a team is going to make based on a number of home runs, which would be useful in estimating if a team is going to win or lose. Since \(\beta_0 = 415.2389\) and \(\beta_1 = 1.8345\) are positive more homeruns team makes higher are chances to win the game.

m2 <- lm(runs ~ homeruns, data = mlb11)

summary(m2)
## 
## Call:
## lm(formula = runs ~ homeruns, data = mlb11)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -91.615 -33.410   3.231  24.292 104.631 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 415.2389    41.6779   9.963 1.04e-10 ***
## homeruns      1.8345     0.2677   6.854 1.90e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 51.29 on 28 degrees of freedom
## Multiple R-squared:  0.6266, Adjusted R-squared:  0.6132 
## F-statistic: 46.98 on 1 and 28 DF,  p-value: 1.9e-07

Prediction and prediction errors

Let’s create a scatterplot with the least squares line laid on top.

plot(mlb11$runs ~ mlb11$at_bats)
abline(m1)

The function abline plots a line based on its slope and intercept. Here, we used a shortcut by providing the model m1, which contains both parameter estimates. This line can be used to predict \(y\) at any value of \(x\). When predictions are made for values of \(x\) that are beyond the range of the observed data, it is referred to as extrapolation and is not usually recommended. However, predictions made within the range of the data are more reliable. They’re also used to compute the residuals.

  1. If a team manager saw the least squares regression line and not the actual data, how many runs would he or she predict for a team with 5,578 at-bats? Is this an overestimate or an underestimate, and by how much? In other words, what is the residual for this prediction?

A: Relationship between runs and atbats is described by \[\hat{runs} = -2789.2429 + 0.6305 * atbats\]

For atbats = 5,578, \[\hat{runs} = 728\]

Actual observed values from dataset, Philadelphia Phillies scored 713 runs with 5579 at_bats. So estimate from the above is overestimate. Residual for this prediction, \(R = actual\ runs - predicted\ runs = {y}_i - \hat{y}_i = 713 - 728 = -15\). Since we are dealing with runs, value is rounded to nearest zero.

subset(mlb11, at_bats>=5578)
##                     team runs at_bats hits homeruns bat_avg strikeouts
## 1          Texas Rangers  855    5659 1599      210   0.283        930
## 2         Boston Red Sox  875    5710 1600      203   0.280       1108
## 4     Kansas City Royals  730    5672 1560      129   0.275       1006
## 6          New York Mets  718    5600 1477      108   0.264       1085
## 10        Houston Astros  615    5598 1442       95   0.258       1164
## 11     Baltimore Orioles  708    5585 1434      191   0.257       1120
## 14       Cincinnati Reds  735    5612 1438      183   0.256       1250
## 16 Philadelphia Phillies  713    5579 1409      153   0.253       1024
##    stolen_bases wins new_onbase new_slug new_obs
## 1           143   96      0.340    0.460   0.800
## 2           102   90      0.349    0.461   0.810
## 4           153   71      0.329    0.415   0.744
## 6           130   77      0.335    0.391   0.725
## 10          118   56      0.311    0.374   0.684
## 11           81   69      0.316    0.413   0.729
## 14           97   79      0.326    0.408   0.734
## 16           96  102      0.323    0.395   0.717

Model diagnostics

To assess whether the linear model is reliable, we need to check for (1) linearity, (2) nearly normal residuals, and (3) constant variability.

Linearity: You already checked if the relationship between runs and at-bats is linear using a scatterplot. We should also verify this condition with a plot of the residuals vs. at-bats. Recall that any code following a # is intended to be a comment that helps understand the code but is ignored by R.

plot(m1$residuals ~ mlb11$at_bats)
abline(h = 0, lty = 3)  # adds a horizontal dashed line at y = 0

  1. Is there any apparent pattern in the residuals plot? What does this indicate about the linearity of the relationship between runs and at-bats?

A: A residual value is a measure of how much a regression line vertically misses a data point. Regression lines are the best fit for a set of data. In our case, there is no visible pattern in the residuals plot. Since residual values are equally and randomly spaced around zero on the horizontal axis, data set runs and at-bats is a good fit for linear regression.

Nearly normal residuals: To check this condition, we can look at a histogram

hist(m1$residuals)

or a normal probability plot of the residuals.

qqnorm(m1$residuals)
qqline(m1$residuals)  # adds diagonal line to the normal prob plot

  1. Based on the histogram and the normal probability plot, does the nearly normal residuals condition appear to be met?

A: Histogram suggests it is right skewed and there are some outliers in the data. Normal probability plot shows that all data points are not on the line, but they are close to the line. Normal probability plot also indicates our prediction should never really be too far off from the actual observed values. Both graphs indicate data meets Nearly Normal residuals condition.

Constant variability:

  1. Based on the plot in (1), does the constant variability condition appear to be met?

A: Looking at the scatter plot, the points have constant variance, with the residuals scattered randomly around zero on the horizontal axis. Since residuals do not show increasing or decreasing pattern, we can assume Constant Variance exists. * * *

On Your Own

A: Using the data mlb11, I believe another good predictor of runs is hits.

Relationship between runs and hits is described by \[\hat{runs} = -375.5600 + 0.7589 * hits\]

Looking at the scatterplot, it appears to be there is a linear relationship between runs and hits. However, there is one outlier New York Yankees having scored 867 runs of 1452 hits.

m3 <- lm(runs ~ hits, data = mlb11)

plot(mlb11$runs ~ mlb11$hits)
abline(m3)

summary(m3)
## 
## Call:
## lm(formula = runs ~ hits, data = mlb11)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -103.718  -27.179   -5.233   19.322  140.693 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -375.5600   151.1806  -2.484   0.0192 *  
## hits           0.7589     0.1071   7.085 1.04e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 50.23 on 28 degrees of freedom
## Multiple R-squared:  0.6419, Adjusted R-squared:  0.6292 
## F-statistic:  50.2 on 1 and 28 DF,  p-value: 1.043e-07
subset(mlb11, hits==1452)
##               team runs at_bats hits homeruns bat_avg strikeouts
## 7 New York Yankees  867    5518 1452      222   0.263       1138
##   stolen_bases wins new_onbase new_slug new_obs
## 7          147   97      0.343    0.444   0.788

A: \(R^2\) is a proportion, it is always a number between 0 and 1. Also, \(R^2 * 100\) is used to explain percent of the variation in y is accounted for by the variation in predictor x.

In our case for runs ~ at_bats \({R^2}_{runs-atbats} =\) 0.3728654

where as for runs ~ hits \({R^2}_{runs-hits} =\) 0.6419388

Though in both cases predictor x causes the change in the response y it does not mean association is causation. That is, just because a data set is characterized by having a large \(R^2\) value, it does not imply that x causes the changes in y. However, we can conclude runs ~ hits is better prediction model over runs ~ at_bats using \(R^2\) value. Data is 64 percent better explained by runs ~ hits model whereas using runs ~ at_bats only 37 percent data can be explained.

# Summary `runs` ~ `at_bats`
str(summary(le))
## List of 11
##  $ call         : language lm(formula = mlb11$runs ~ mlb11$at_bats)
##  $ terms        :Classes 'terms', 'formula'  language mlb11$runs ~ mlb11$at_bats
##   .. ..- attr(*, "variables")= language list(mlb11$runs, mlb11$at_bats)
##   .. ..- attr(*, "factors")= int [1:2, 1] 0 1
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:2] "mlb11$runs" "mlb11$at_bats"
##   .. .. .. ..$ : chr "mlb11$at_bats"
##   .. ..- attr(*, "term.labels")= chr "mlb11$at_bats"
##   .. ..- attr(*, "order")= int 1
##   .. ..- attr(*, "intercept")= int 1
##   .. ..- attr(*, "response")= int 1
##   .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> 
##   .. ..- attr(*, "predvars")= language list(mlb11$runs, mlb11$at_bats)
##   .. ..- attr(*, "dataClasses")= Named chr [1:2] "numeric" "numeric"
##   .. .. ..- attr(*, "names")= chr [1:2] "mlb11$runs" "mlb11$at_bats"
##  $ residuals    : Named num [1:30] 76 63.8 68.5 -57.2 63 ...
##   ..- attr(*, "names")= chr [1:30] "1" "2" "3" "4" ...
##  $ coefficients : num [1:2, 1:4] -2789.243 0.631 853.696 0.155 -3.267 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : chr [1:2] "(Intercept)" "mlb11$at_bats"
##   .. ..$ : chr [1:4] "Estimate" "Std. Error" "t value" "Pr(>|t|)"
##  $ aliased      : Named logi [1:2] FALSE FALSE
##   ..- attr(*, "names")= chr [1:2] "(Intercept)" "mlb11$at_bats"
##  $ sigma        : num 66.5
##  $ df           : int [1:3] 2 28 2
##  $ r.squared    : num 0.373
##  $ adj.r.squared: num 0.35
##  $ fstatistic   : Named num [1:3] 16.6 1 28
##   ..- attr(*, "names")= chr [1:3] "value" "numdf" "dendf"
##  $ cov.unscaled : num [1:2, 1:2] 1.65e+02 -2.99e-02 -2.99e-02 5.41e-06
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : chr [1:2] "(Intercept)" "mlb11$at_bats"
##   .. ..$ : chr [1:2] "(Intercept)" "mlb11$at_bats"
##  - attr(*, "class")= chr "summary.lm"
# Summary `runs` ~ `hits`
str(summary(m3))
## List of 11
##  $ call         : language lm(formula = runs ~ hits, data = mlb11)
##  $ terms        :Classes 'terms', 'formula'  language runs ~ hits
##   .. ..- attr(*, "variables")= language list(runs, hits)
##   .. ..- attr(*, "factors")= int [1:2, 1] 0 1
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:2] "runs" "hits"
##   .. .. .. ..$ : chr "hits"
##   .. ..- attr(*, "term.labels")= chr "hits"
##   .. ..- attr(*, "order")= int 1
##   .. ..- attr(*, "intercept")= int 1
##   .. ..- attr(*, "response")= int 1
##   .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> 
##   .. ..- attr(*, "predvars")= language list(runs, hits)
##   .. ..- attr(*, "dataClasses")= Named chr [1:2] "numeric" "numeric"
##   .. .. ..- attr(*, "names")= chr [1:2] "runs" "hits"
##  $ residuals    : Named num [1:30] 17.14 36.38 -6.09 -78.26 -10.6 ...
##   ..- attr(*, "names")= chr [1:30] "1" "2" "3" "4" ...
##  $ coefficients : num [1:2, 1:4] -375.56 0.759 151.181 0.107 -2.484 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : chr [1:2] "(Intercept)" "hits"
##   .. ..$ : chr [1:4] "Estimate" "Std. Error" "t value" "Pr(>|t|)"
##  $ aliased      : Named logi [1:2] FALSE FALSE
##   ..- attr(*, "names")= chr [1:2] "(Intercept)" "hits"
##  $ sigma        : num 50.2
##  $ df           : int [1:3] 2 28 2
##  $ r.squared    : num 0.642
##  $ adj.r.squared: num 0.629
##  $ fstatistic   : Named num [1:3] 50.2 1 28
##   ..- attr(*, "names")= chr [1:3] "value" "numdf" "dendf"
##  $ cov.unscaled : num [1:2, 1:2] 9.06 -6.41e-03 -6.41e-03 4.55e-06
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : chr [1:2] "(Intercept)" "hits"
##   .. ..$ : chr [1:2] "(Intercept)" "hits"
##  - attr(*, "class")= chr "summary.lm"

A: Looking at \(R^2\) percent from the table below, bat_avg variable best predicts runs. Variable explains 66% of data.

Relationship between runs and bat_avg is described by \[\hat{runs} = -642.8 + 5242.2 * {bat\_avg}\]

library(knitr)
p1 <- lm(runs ~ bat_avg, data = mlb11)
p2 <- lm(runs ~ strikeouts, data = mlb11)
p3 <- lm(runs ~ stolen_bases, data = mlb11)
p4 <- lm(runs ~ wins, data = mlb11)
p5 <- lm(runs ~ hits, data = mlb11)

best.pre.model <- data.frame("bat_avg", summary(p1)$r.squared, round(summary(p1)$r.squared * 100), stringsAsFactors = F)
best.pre.model <- rbind(best.pre.model, c("strikeouts", summary(p2)$r.squared, round(summary(p2)$r.squared * 100)))
best.pre.model <- rbind(best.pre.model, c("stolen_bases", summary(p3)$r.squared, round(summary(p3)$r.squared * 100)))
best.pre.model <- rbind(best.pre.model, c("wins", summary(p4)$r.squared, round(summary(p4)$r.squared * 100)))
best.pre.model <- rbind(best.pre.model, c("hits", summary(p5)$r.squared, round(summary(p5)$r.squared * 100)))

colnames(best.pre.model) <- c("Variable","RSq($R^2$)", "RSqPercent($R^2$%)")

kable(best.pre.model, format="pandoc", align="l", row.names = NA, caption = "Best Variable to Predicts Runs")
Best Variable to Predicts Runs
Variable RSq(\(R^2\)) RSqPercent(\(R^2\)%)
bat_avg 0.656077134646863 66
strikeouts 0.169357932236312 17
stolen_bases 0.00291399266657395 0
wins 0.36097117944668 36
hits 0.641938767239419 64
# Get beta 0 and beta 1 values
summary(p1)
## 
## Call:
## lm(formula = runs ~ bat_avg, data = mlb11)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -94.676 -26.303  -5.496  28.482 131.113 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   -642.8      183.1  -3.511  0.00153 ** 
## bat_avg       5242.2      717.3   7.308 5.88e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 49.23 on 28 degrees of freedom
## Multiple R-squared:  0.6561, Adjusted R-squared:  0.6438 
## F-statistic: 53.41 on 1 and 28 DF,  p-value: 5.877e-08
# Grapically
plot(mlb11$runs ~ mlb11$bat_avg)
abline(p1)

A: Looking at \(R^2\) percent from the table below, new_obs variable best predicts runs. Variable explains 93% of data.

Relationship between runs and new_obs is described by \[\hat{runs} = -686.61 + 1919.36 * {new\_obs}\]

library(knitr)
p1 <- lm(runs ~ bat_avg, data = mlb11)
p2 <- lm(runs ~ strikeouts, data = mlb11)
p3 <- lm(runs ~ stolen_bases, data = mlb11)
p4 <- lm(runs ~ wins, data = mlb11)
p5 <- lm(runs ~ hits, data = mlb11)
p6 <- lm(runs ~ new_onbase, data = mlb11)
p7 <- lm(runs ~ new_slug, data = mlb11)
p8 <- lm(runs ~ new_obs, data = mlb11)

best.pre.model <- data.frame("bat_avg", summary(p1)$r.squared, round(summary(p1)$r.squared * 100), stringsAsFactors = F)
best.pre.model <- rbind(best.pre.model, c("strikeouts", summary(p2)$r.squared, round(summary(p2)$r.squared * 100)))
best.pre.model <- rbind(best.pre.model, c("stolen_bases", summary(p3)$r.squared, round(summary(p3)$r.squared * 100)))
best.pre.model <- rbind(best.pre.model, c("wins", summary(p4)$r.squared, round(summary(p4)$r.squared * 100)))
best.pre.model <- rbind(best.pre.model, c("hits", summary(p5)$r.squared, round(summary(p5)$r.squared * 100)))

best.pre.model <- rbind(best.pre.model, c("new_onbase", summary(p6)$r.squared, round(summary(p6)$r.squared * 100)))
best.pre.model <- rbind(best.pre.model, c("new_slug", summary(p7)$r.squared, round(summary(p7)$r.squared * 100)))
best.pre.model <- rbind(best.pre.model, c("new_obs", summary(p8)$r.squared, round(summary(p8)$r.squared * 100)))

colnames(best.pre.model) <- c("Variable","RSq($R^2$)", "RSqPercent($R^2$%)")

kable(best.pre.model, format="pandoc", align="l", row.names = NA, caption = "Best Variable to Predicts Runs")
Best Variable to Predicts Runs
Variable RSq(\(R^2\)) RSqPercent(\(R^2\)%)
bat_avg 0.656077134646863 66
strikeouts 0.169357932236312 17
stolen_bases 0.00291399266657395 0
wins 0.36097117944668 36
hits 0.641938767239419 64
new_onbase 0.849105251446139 85
new_slug 0.896870368409638 90
new_obs 0.934927126351814 93
# Get beta 0 and beta 1 values
summary(p8)
## 
## Call:
## lm(formula = runs ~ new_obs, data = mlb11)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -43.456 -13.690   1.165  13.935  41.156 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -686.61      68.93  -9.962 1.05e-10 ***
## new_obs      1919.36      95.70  20.057  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 21.41 on 28 degrees of freedom
## Multiple R-squared:  0.9349, Adjusted R-squared:  0.9326 
## F-statistic: 402.3 on 1 and 28 DF,  p-value: < 2.2e-16
# Grapically
plot(mlb11$runs ~ mlb11$new_obs)
abline(p8)

A: Looking at scatterplot, residuals are randomly scattered around zero on the horizontal axis. This indicates Linearity condition is met.

Histogram suggests data is normally distributed and data is not skewed. This indicates there are no outliers. Normal probability plot shows that all data points are not on the line, but they are close to the line. Both graphs show enough evidence that data meets Nearly Normal condition.

Looking at scatterplot, the points have constant variance, with the residuals scattered randomly around zero on the horizontal axis. Since residuals do not show increasing or decreasing pattern, we can assume Constant Variance exists.

# Linearity and Constant variability
plot(p8$residuals ~ mlb11$new_obs)
abline(h = 0, lty = 3)  # adds a horizontal dashed line at y = 0

# Nearly normal residuals using Histogram
hist(p8$residuals)

# Nearly normal residuals using Normal probability plot 
qqnorm(p8$residuals)
qqline(p8$residuals)  # adds diagonal line to the normal prob plot

This is a product of OpenIntro that is released under a Creative Commons Attribution-ShareAlike 3.0 Unported. This lab was adapted for OpenIntro by Andrew Bray and Mine Çetinkaya-Rundel from a lab written by the faculty and TAs of UCLA Statistics.