search for: modelinfunction

Displaying 1 result from an estimated 1 matches for "modelinfunction".

Did you mean: model_function
2011 Jul 29
1
Environment of a LM created in a function
...unction. The following code illustrates my usual approach: ---------------8<--------------- set.seed(123) dat <- data.frame(x = rep(rep(1:3, each = 3), 4), y = rep(1:3, 12)) dat$z1 <- rnorm(36, dat$x + dat$y) dat$z2 <- rnorm(36, dat$x + 2*dat$y) dat$z3 <- rnorm(36, dat$x + 3*dat$y) modelInFunction <- function(resp, expl, df) { fo <- as.formula(paste(resp, paste(expl, collapse = " + "), sep = " ~ ")) lm(fo, data = df) } ex <- c("x", "y") resp <- paste("z", 1:3, sep = "") models <- lapply(resp, modelInFunction, ex...