Hi Nick,
The following would be one way of doing what you want:
# function to estimate one model
foo <- function(mu = 9.244655, n = 50){
X <- rpois(n, mu)
glm(X ~ Y, family = poisson) # note I am using family = poisson
}
B <- 1000 # number of samples -- change accordingly
Y <- 1960:2009
models <- lapply(1:B, foo) # a list
To see model 1, type
models[[1]]
summary(models[[1]]) # summary
# coefficients b0 and b1 for all B models
betas <- do.call(rbind, lapply(models, function(m)
summary(m)$coefficients[1:2, 1]))
betas
See ?lapply for more information. Also, note that by exploring model[[1]]
above, e.g.
str(model[[1]])
as well as
str(summary(models[[1]]))
you can access even more information. See ?glm and ?lm for details,
especially the "Value" section in both.
*
HTH,
*
Jorge
On Mon, Mar 7, 2011 at 10:52 PM, Nicholas M. Caruso <> wrote:
> Hello, I am trying to run multiple glm models for a dataset and need some
> help
>
> First, i generated a matrix of abundance for 10000 populations based on the
> mean and variance of my dataset
>
> X <- replicate(10000, rpois(50, 9.244655))
>
> and entered the years as row names
>
> Y <- c(1960:2009)
> rownames(X)<-Y
>
> Now my issue is that I want to run a glm on each of those columns. However
> I cannot just run glm(X~Y)
>
> "Error: (subscript) logical subscript too long"
>
> I know I can run individual column glms
>
> X_glm <- glm(X[,1]~Y)
>
> but would rather not do that 10000 times.
>
> Any suggestions?
>
> Thank you for any help.
> Nick.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> 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.
>
[[alternative HTML version deleted]]