I have this loop.
with_progress({
# Initialize the progress bar
pb <- progressor(along = unique(pct_women_exec$ticker))
# Precompute unique tickers
unique_tickers <- unique(pct_women_exec$ticker)
# Use lapply to fit models for each ticker
fitted_models <- lapply(unique_tickers, function(ticker) {
# Subset the data and external regressors for the current ticker
y <- pct_women_exec[pct_women_exec$ticker == ticker, "ret.RF"]
X1 <- data.frame(Mkt.RF = pct_women_exec[pct_women_exec$ticker == ticker, "Mkt.RF"])
X2 <- data.frame(event_dummy = pct_women_exec[pct_women_exec$ticker == ticker, "event_dummy"])
X2 <- as.matrix(X2)
X <- cbind(as.matrix(X1), X2)
# Define the specifications
spec <- ugarchspec(variance.model = list(model = "sGARCH", external.regressors=X2), mean.model = list(armaOrder= c(0, 0), include.mean = TRUE, external.regressors=X))
# Fitting the model
fit <- ugarchfit(data=y, spec=spec)
# Extract the standard deviation of sigma
sigma_sd <- sd(sigma(fit))
# Update the progress bar
pb()
# Return the fitted model and the standard deviation of sigma
return(fit)
})
})
How can I access, extract and store the p-values for all of my estimated models for the diagnostics tests posted in the picture? I need it to assess the fit of my estimated models.
I tried all kinds of code but in particular I am given the error saying that I cannot access an S4 object using $.