1

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",...)
}
Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98
  • Please save the RStudio tag for problems with the editor (e.g., if something work on the R command line but not in RStudio). – Gregor Thomas Nov 15 '18 at 18:09
  • 3
    I don't see any reference to R-squared in your code, but suggested duplicate: [How to pull out the R-squared value from a linear regression](https://stackoverflow.com/q/5587676/903061). – Gregor Thomas Nov 15 '18 at 18:10

0 Answers0