[R] Nested variables
DanielWC
daniel.carstensen at gmail.com
Tue Jun 2 12:30:29 CEST 2009
Hi again
I read the chapter and it says that I can nest B in A by writing A/B. But it
doesnt seem to work properly. The package I use is pscl, I am trying to
model zero inflated data. Here is the full model:
zip1<-zeroinfl(Visitation ~ Habitat/Site + Sps + TP + Resource +
Sps*Habitat/Site + Sps*Resource + Sps*TP + TP*Resource + TP*Habitat/Site |
TP + Sps + Resource + Habitat/Site + TP*Sps + Sps*Resource + TP*Resource +
TP*Habitat/Site, data = data1)
where as you can see I have tried to include Habitat/Site. But it doesnt
seem like its possible to create interaction links that way. I would like
create the interaction link between say Sps and Habitat/Site. If I write
Sps*Habitat/Site R somehow thinks that its a 3-way interaction link and
still includes habitat as a single variable. Here is the summary just so you
can see:
Count model coefficients (poisson with log link):
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.8643338 0.3450539 11.199 < 2e-16 ***
Habitat -3.2757473 0.4871726 -6.724 1.77e-11 ***
Sps -0.3332371 0.1117680 -2.982 0.00287 **
TP -0.3857513 0.0975556 -3.954 7.68e-05 ***
Resource 0.0130935 0.0009545 13.717 < 2e-16 ***
Habitat:Site 0.2487012 0.0415908 5.980 2.24e-09 ***
Habitat:Sps 0.5432845 0.1230434 4.415 1.01e-05 ***
Sps:Resource -0.0041420 0.0002632 -15.738 < 2e-16 ***
Sps:TP 0.0438085 0.0189411 2.313 0.02073 *
TP:Resource -0.0009413 0.0002887 -3.260 0.00111 **
Habitat:TP 0.1549435 0.1205884 1.285 0.19883
Habitat:Site:Sps -0.0305628 0.0107794 -2.835 0.00458 **
Habitat:Site:TP -0.0096408 0.0098497 -0.979 0.32768
Zero-inflation model coefficients (binomial with logit link):
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.3160850 0.8200631 -1.605 0.1085
TP 0.2808474 0.2657544 1.057 0.2906
Sps 0.8023648 0.1281520 6.261 3.82e-10 ***
Resource -0.0075967 0.0035817 -2.121 0.0339 *
Habitat -1.3122811 1.1348922 -1.156 0.2476
Habitat:Site 0.1390498 0.0984716 1.412 0.1579
TP:Sps -0.0189088 0.0406299 -0.465 0.6417
Sps:Resource -0.0005548 0.0006843 -0.811 0.4175
TP:Resource 0.0007100 0.0008454 0.840 0.4010
TP:Habitat 0.7195254 0.3666809 1.962 0.0497 *
TP:Habitat:Site -0.0782610 0.0314229 -2.491 0.0128 *
Thanks again
Mark Difford wrote:
>
> Daniel,
>
>>> Yes I am trying to model such data, and i need R to know that Site is
>>> nested within Habitat.
>>> Do I use some kind of command before running the model (like factor()
>>> and so on) or do i
>>> write it in the model formula. If so, how?
>
> You still are not telling the list enough, since nesting specifications
> are sometimes package/program specific. You could help yourself by reading
> some of R's basic documentation about how to specify a nested model. Then
> "it" will tell you what to do.
>
> ?formula
>
> Or read §11.1 of "An Introduction to R" (one of R's manuals).
>
> Regards, Mark.
>
>
> DanielWC wrote:
>>
>> Hi.
>> Yes I am trying to model such data, and i need R to know that Site is
>> nested within Habitat. Do I use some kind of command before running the
>> model (like factor() and so on) or do i write it in the model formula. If
>> so, how?
>>
>> Thanks
>>
>>
>>
>> Douglas Bates-2 wrote:
>>>
>>> On Fri, May 29, 2009 at 7:50 AM, DanielWC <daniel.carstensen at gmail.com>
>>> wrote:
>>>
>>>> Hello
>>>> I am working with a biological data including variables called Habitat
>>>> and
>>>> Site, example:
>>>
>>>> Habitat Site
>>>
>>>> Forest Low
>>>> Forest Low
>>>> Forest High
>>>> Forest High
>>>
>>>> I want to tell R that the Site variable is nested within the Forest
>>>> variable
>>>> (that it is not a new variable).
>>>> Does anyone know how to do this?
>>>
>>> If you could explain what you mean by "tell R", it would help. Are
>>> you trying to model such data and you want to know how to express the
>>> relationship between such factors in a model formula?
>>>
>>> ______________________________________________
>>> 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.
>>>
>>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Nested-variables-tp23779402p23830019.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list