# Load necessary library
library(astsa)
# Load the varve data
data("varve")
# Log-transform the varve data to stabilize variance
log_varve <- log(varve)
# Difference the log-transformed series to obtain a stationary series
diff_log_varve <- diff(log_varve)
# Fit an MA(1) model to the differenced series
ima_model <- arima(diff_log_varve, order = c(0, 0, 1))
# Display the summary of the fitted model
summary(ima_model)
## Length Class Mode
## coef 2 -none- numeric
## sigma2 1 -none- numeric
## var.coef 4 -none- numeric
## mask 2 -none- logical
## loglik 1 -none- numeric
## aic 1 -none- numeric
## arma 7 -none- numeric
## residuals 633 ts numeric
## call 3 -none- call
## series 1 -none- character
## code 1 -none- numeric
## n.cond 1 -none- numeric
## nobs 1 -none- numeric
## model 10 -none- list
# Plot the residuals to check the model fit
ts.plot(ima_model$residuals, main = "Residuals of the MA(1) Model", ylab = "Residuals")

acf(ima_model$residuals, main = "ACF of Residuals")

pacf(ima_model$residuals, main = "PACF of Residuals")

# Perform diagnostic checks
Box.test(ima_model$residuals, lag = 10, type = "Ljung-Box")
##
## Box-Ljung test
##
## data: ima_model$residuals
## X-squared = 20.441, df = 10, p-value = 0.02535