Dear R-help: I am writing a function based on glm and would like some variations of weights. In the code below, I couldn't understand why the second glm function fails and don't know how to fix it:
Error in eval(extras, data, env) : object 'newweights' not found Calls: print ... eval -> <Anonymous> -> model.frame.default -> eval -> eval Execution halted ### R code y <- rnorm(100) x <- rnorm(100) data <- data.frame(cbind(x, y)) weights <- rep(1, 100) n <- 100 myglm <- function(formula, data, weights){ ## this works print(glm(formula, data, family=gaussian(), weights)) ## this is not working newweights <- rep(1, n) glm(formula, data, family=gaussian(), weights=newweights) } myglm(y~., data, weights) [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.