Nested models in RMark?

posts related to the RMark library, which may not be of general interest to users of 'classic' MARK

Nested models in RMark?

Postby megpetrie » Wed Aug 20, 2014 4:21 pm

Hello,

I'm wondering if there is any way to specify nesting a variable within a factor in RMark models?

Thanks!
megpetrie
 
Posts: 23
Joined: Tue Feb 06, 2007 4:48 pm

Re: Nested models in RMark?

Postby jlaake » Wed Aug 20, 2014 5:01 pm

Please explain further what you mean. What is the variable? What is the factor and what do you mean by nesting?

If v is a numeric variable and f is a factor then

~v*f

describes a set of linear equations that differ for each level of f. If there are 3 levels of f then the above would describe

b0 + b1*v
bo+b2 + (b1+b3)*v
b0+b4 + (b1+b5)*v

If that is not what you are describing, explain further.

--jeff
jlaake
 
Posts: 1480
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Nested models in RMark?

Postby megpetrie » Wed Aug 20, 2014 5:30 pm

Thanks Jeff,

I do want to nest a numeric variable within a factor variable.
I think v*f will work just fine, I'm wondering though, does v*f differ from v:f in this case?

Megan
megpetrie
 
Posts: 23
Joined: Tue Feb 06, 2007 4:48 pm

Re: Nested models in RMark?

Postby jlaake » Wed Aug 20, 2014 5:38 pm

When you have a query like that it helps if you create a simple example in R and use model.matrix to see the design matrix it specifies. ~v:f produces separate slopes but a common intercept.

Code: Select all
> f=c("red","blue","black")
> v=3:1
> df=data.frame(f=f,v=v)
> model.matrix(~v:f,df)
  (Intercept) v:fblack v:fblue v:fred
1           1        0       0      3
2           1        0       2      0
3           1        1       0      0
attr(,"assign")
[1] 0 1 1 1
attr(,"contrasts")
attr(,"contrasts")$f
[1] "contr.treatment"

> model.matrix(~v*f,df)
  (Intercept) v fblue fred v:fblue v:fred
1           1 3     0    1       0      3
2           1 2     1    0       2      0
3           1 1     0    0       0      0
attr(,"assign")
[1] 0 1 2 2 3 3
attr(,"contrasts")
attr(,"contrasts")$f
[1] "contr.treatment"
jlaake
 
Posts: 1480
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA


Return to RMark

Who is online

Users browsing this forum: Bing [Bot] and 4 guests