I'm working on getting this to work - need to figure out how to extract 
pieces properly.

In the mean time, I may have figured out an alternate method to group 
the factors by the following:

>  stems139$SpeciesF <- factor(stems139$Species)

>  stems139GLM <- glm(Stems ~ Time*SizeClassF*Species, family=poisson, 
data=stems139)

>  summary(stems139GLM)

Call:

glm(formula = Stems ~ Time * SizeClassF * Species, family = poisson,

data = stems139)

Deviance Residuals:

Min1QMedian3QMax

-4.2308-1.0107-0.6786-0.339316.7415

Coefficients:

Estimate Std. Error z value Pr(>|z|)

(Intercept)-0.6717940.118678-5.661 1.51e-08 ***

TimeVTM-0.5738000.197698-2.902 0.003703 **

SizeClassF2-0.7661720.210684-3.637 0.000276 ***

SizeClassF3-1.960095 0.337764-5.803 6.51e-09 ***

SizeClassF4-2.6532420.462693-5.734 9.79e-09 ***

SpeciesABMA1.8240950.12789514.262< 2e-16 ***

SpeciesJUOC-0.0882930.171666-0.514 0.607022

SpeciesPIAL1.9479200.12685615.355 < 2e-16 ***

SpeciesPICO2.8634070.12201823.467 < 2e-16 ***

SpeciesPIJE-0.5250100.194664-2.697 0.006997 **

SpeciesPIMO0.3720490.1542512.412 0.015866 *

SpeciesTSME1.9194050.12708515.103< 2e-16 ***

TimeVTM:SizeClassF2-0.6201220.411567-1.507 0.131879

TimeVTM:SizeClassF30.7561220.4716121.603 0.108875

TimeVTM:SizeClassF40.9102730.6180141.473 0.140778

The problem now though, is that R for some reason does not list factor 1 
in the output.  Why would this be?

On 2/8/2011 2:21 PM, Dennis Murphy wrote:
> Hi:
>
> One approach would be to use dlply() from the plyr package to generate 
> the models and assign the results to a list, something like the following:
>
> library(plyr)
> # function to run the GLM in each data subset - the argument is a 
> generic data subset d
> gfun <- function(d) glm(Stems ~ Time, data = d, family = poisson)
> mlist <- dlply(stems139, .(SizeClass, Species), gfun)
>
> To see the result, try mlist[[1]] or summary(mlist[[1]]) to execute 
> the print and summary methods on the first fitted model. Each output 
> list object from glm() is a list component of mlist, so mlist is 
> actually a list of lists.
>
> You can extract various pieces from mlist by using ldply() with a 
> suitable extraction function or by use of the do.call/lapply combination.
>
> All of this is untested since no minimal example was provided per 
> instructions in the Posting Guide...
>
> HTH,
> Dennis
>
>
> On Tue, Feb 8, 2011 at 11:54 AM, Christopher R. Dolanc 
> <crdolanc@ucdavis.edu <mailto:crdolanc@ucdavis.edu>> wrote:
>
>     I'm having a hard time figuring out how to group results by
>     certain factors in R.  I have data with the following headings:
>
>     [1] "Time"      "Plot"      "LatCat"    "Elevation" "ElevCat"  
>     "Aspect"    "AspCat"    "Slope"
>     [9] "SlopeCat"  "Species"   "SizeClass" "Stems"
>
>     and I'm trying to use a GLM to test differences in "Stems" for
>     different categories/factors - most importantly, I want to group
>     things so that I see results by "SizeClass" and then by "Species".
>      This is pretty easy in SAS using the "Group By" command, but in
>     R, I haven't figured it out.
>
>     I've tried using the following code:
>
>     > stems139GLM <- glm(Stems ~ Time | SizeClass | Species,
>     family=poisson, data=stems139)
>
>     but R gives me this message:
>
>     Error in pmax(exp(eta), .Machine$double.eps) :
>      cannot mix 0-length vectors with others
>     In addition: Warning messages:
>     1: In Ops.factor(Time, SizeClass) : | not meaningful for factors
>     2: In Ops.factor(Time | SizeClass, Species) : | not meaningful for
>     factors
>
>     I'd appreciate any help.
>
>     Thanks.
>
>     -- 
>     Christopher R. Dolanc
>     PhD Candidate
>     Ecology Graduate Group
>     University of California, Davis
>     Lab Phone: (530) 752-2644 (Barbour lab)un
>
>     ______________________________________________
>     R-help@r-project.org <mailto: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.
>
>

-- 
Christopher R. Dolanc
PhD Candidate
Ecology Graduate Group
University of California, Davis
Lab Phone: (530) 752-2644 (Barbour lab)


	[[alternative HTML version deleted]]

