Re: [R] MCMC_glm models

From: Jorge Ivan Velez <jorgeivanvelez_at_gmail.com>
Date: Tue, 08 Mar 2011 00:37:51 -0500

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_at_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]]



R-help_at_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. Received on Tue 08 Mar 2011 - 05:47:51 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 08 Mar 2011 - 06:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive