Load data

df <- as.data.frame(readxl::read_excel("/mnt/hdd/earthquake.xlsx"))

required_cols <- c("magnitude", "depth", "latitude", "longitude")

# Inspect first rows
knitr::kable(head(df), caption = "First six rows of the earthquake dataset")
First six rows of the earthquake dataset
…1 depth latitude longitude magnitude
NA NA NA NA NA
1 33 -52.26 -151.70 6.7
2 36 45.53 -29.07 5.8
3 57 41.85 -37.22 5.8
4 67 29.19 -38.85 6.2
5 30 -21.66 -10.19 6.0

Fit linear model

model <- lm(magnitude ~ depth + latitude + longitude, data = df)
summary(model)
## 
## Call:
## lm(formula = magnitude ~ depth + latitude + longitude, data = df)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.24306 -0.17120 -0.08398  0.11212  0.64516 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.0109921  0.0277381 216.705   <2e-16 ***
## depth       -0.0002133  0.0001964  -1.086    0.280    
## latitude    -0.0001949  0.0005980  -0.326    0.745    
## longitude   -0.0002683  0.0003035  -0.884    0.379    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2118 on 95 degrees of freedom
##   (1 observation deleted due to missingness)
## Multiple R-squared:  0.01982,    Adjusted R-squared:  -0.01113 
## F-statistic: 0.6404 on 3 and 95 DF,  p-value: 0.5909

Target location

new_loc <- data.frame(depth = 12, latitude = 28.7, longitude = 77.1)
new_loc
##   depth latitude longitude
## 1    12     28.7      77.1

(a) 95% Confidence interval for the average magnitude at the location

ci_mean <- predict(model, newdata = new_loc, interval = "confidence", level = 0.95)
ci_mean_rounded <- round(ci_mean, 4)
ci_mean_rounded
##      fit    lwr   upr
## 1 5.9822 5.9093 6.055
cat(sprintf("\nInterpretation: With 95%% confidence the true mean magnitude at the location (depth=12, lat=28.7, lon=77.1) lies between %0.4f and %0.4f.\n",
            ci_mean_rounded[1, "lwr"], ci_mean_rounded[1, "upr"]))
## 
## Interpretation: With 95% confidence the true mean magnitude at the location (depth=12, lat=28.7, lon=77.1) lies between 5.9093 and 6.0550.

(b) 95% Prediction interval for an individual earthquake magnitude at the location

pi_ind <- predict(model, newdata = new_loc, interval = "prediction", level = 0.95)
pi_ind_rounded <- round(pi_ind, 4)
pi_ind_rounded
##      fit    lwr   upr
## 1 5.9822 5.5554 6.409
cat(sprintf("\nInterpretation: A single new earthquake magnitude observed at that location has a 95%% prediction interval from %0.4f to %0.4f.\n",
            pi_ind_rounded[1, "lwr"], pi_ind_rounded[1, "upr"]))
## 
## Interpretation: A single new earthquake magnitude observed at that location has a 95% prediction interval from 5.5554 to 6.4090.

End of report.