So, I need to get R-squared index from a linear model, I tried to apply a summary function in a loop but it only showed 1st Quartile, 3rd Quartile, mean, median and etc.
Here is the code, thanks for your help in advance.
function_model <- function(n, n_sim, x_mean, x_sd, eps_mean, eps_sd, alpha, beta, ...) {
matrix_results <- matrix(ncol=2, nrow=n_sim)
for (i in 1:n_sim) {
x <- runif(n, min = 0, max = 6)
eps <- rnorm(n, mean=0, sd = x^2)
y <- alpha + beta * x + eps
matrix_results[i,] <- lm(y ~ x)$coefficients
}
z <- lm(y ~ x)
par(mfrow=c(1, 2))
hist(matrix_results[, 1], main="Histogram of Alpha", xlab="Alpha",...)
hist(matrix_results[, 2], main="Histogram of Beta", xlab="Beta",...)
}