The quakes data set contains information about the locations of earthquakes near Fiji.

head(quakes)
##      lat   long depth mag stations
## 1 -20.42 181.62   562 4.8       41
## 2 -20.62 181.03   650 4.2       15
## 3 -26.00 184.10    42 5.4       43
## 4 -17.97 181.66   626 4.1       19
## 5 -20.42 181.96   649 4.0       11
## 6 -19.68 184.31   195 4.0       12
summary(quakes)
##       lat              long           depth            mag      
##  Min.   :-38.59   Min.   :165.7   Min.   : 40.0   Min.   :4.00  
##  1st Qu.:-23.47   1st Qu.:179.6   1st Qu.: 99.0   1st Qu.:4.30  
##  Median :-20.30   Median :181.4   Median :247.0   Median :4.60  
##  Mean   :-20.64   Mean   :179.5   Mean   :311.4   Mean   :4.62  
##  3rd Qu.:-17.64   3rd Qu.:183.2   3rd Qu.:543.0   3rd Qu.:4.90  
##  Max.   :-10.72   Max.   :188.1   Max.   :680.0   Max.   :6.40  
##     stations     
##  Min.   : 10.00  
##  1st Qu.: 18.00  
##  Median : 27.00  
##  Mean   : 33.42  
##  3rd Qu.: 42.00  
##  Max.   :132.00

Visualize

plot(quakes$depth, quakes$mag, xlab="depth (km)", ylab="mag (numeric Richter Magnitude)", main="Earthquakes Near Fiji")

Build model

quakes.lm <- lm(mag ~ depth, data=quakes)
quakes.lm
## 
## Call:
## lm(formula = mag ~ depth, data = quakes)
## 
## Coefficients:
## (Intercept)        depth  
##    4.754599    -0.000431

\[ \widehat{mag} = 4.754599 - 0.000431 * depth \] For every 1 km increase in depth, the magnitude decreases by 0.000431 on the Richter scale. The intercept means that at 0 km, the magnitude is 4.754599.

plot(mag ~ depth, data=quakes)
abline(quakes.lm)

## Model Quality Evaluation

summary(quakes.lm)
## 
## Call:
## lm(formula = mag ~ depth, data = quakes)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.72012 -0.29642 -0.03694  0.19818  1.70014 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  4.755e+00  2.179e-02 218.168  < 2e-16 ***
## depth       -4.310e-04  5.756e-05  -7.488 1.54e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3921 on 998 degrees of freedom
## Multiple R-squared:  0.05319,    Adjusted R-squared:  0.05225 
## F-statistic: 56.07 on 1 and 998 DF,  p-value: 1.535e-13

\[ -0.29642 \neq 1.5 * 0.3921\]

\[ 0.19818 \neq 1.5 * 0.3921 \]

Diagnostic plots

par(mfrow=c(2,2))
plot(quakes.lm)

In the Residuals vs Fitted plot, the residuals do not appear to be evenly distributed. In the Q-Q plot, the right tail is “heavier” than what would be expected for residuals that are normally distributed. The distribution is right-skewed. Overall, a linear model is not appropriate for capturing the relationship between magnitude and depth.