ORDMS Models

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

ORDMS Models

Postby kpearson » Mon Sep 01, 2014 8:02 pm

Is there any way to fit an age structure model across secondary sampling periods without a linear trend? It appears that under the ORDMS model, age is only specified across primary sampling periods. I was able to change the age structure in the .ddl file from 0 to appropriate ages for each secondary sampling period, but when I ran the model it evaluated it as if it were a linear trend.

Also, is it possible to change the default intercept in a time varying model from the first time period to a different time period?

Thanks!
kpearson
 
Posts: 5
Joined: Mon Sep 01, 2014 5:43 pm

Re: ORDMS Models

Postby gstauffer » Tue Sep 02, 2014 9:25 am

I think you are asking whether you can model age across secondary occasions within a primary occasion, i.e., age that changes from one secondary occasion to the next. As far as I know this is not possible for pent and p because the PIMS are vectors rather than triangular. So you can model only time, either as a trend or otherwise. The PIM for phi is triangular, so you can model "age", although it really is "time since entry", as pointed out in the MARK book (chapter 15 nicely explains the PIMS for secondary occasions, page 43-44). That might work for you if "time since entry" really does represent age.

If you really want secondary parameters to be modeled as a function of age (i.e., p in one primary occasion differs from p in another primary occasion – because an individual is a year older), you could define states as ages, since each state has its own PIMs. Then you'd need to constrain state transitions appropriately.

Regarding your second question, by default the lowest factor level (e.g., the first time period) is represented by the intercept. If you want to change this, just create a factor variable in the design data where the lowest level defines the time period that you want to be represented by the intercept.
gstauffer
 
Posts: 17
Joined: Thu Sep 03, 2009 11:51 am

Re: ORDMS Models

Postby kpearson » Tue Sep 02, 2014 6:53 pm

Sorry for not being clear in my question. I am trying to model "time since arrival" across secondary sampling periods which should be equivalent to "age" in the design data for Phi. However, "age" is 0 across secondary sampling occasions. I known how to fit this model in both the design matrix and PIMS in Mark but can't seem to get it to work in RMark. I was able to change the factor variable for "age" to reflect time since arrival but instead of creating the appropriate corresponding design matrix, RMark creates a linear trend on "age". If there is a way to code this correctly in RMark, please let me know.

Thanks again!
kpearson
 
Posts: 5
Joined: Mon Sep 01, 2014 5:43 pm

Re: ORDMS Models

Postby jlaake » Tue Sep 02, 2014 7:40 pm

If it is modelling it as a linear trend, that means the value you are using the design data is numeric and not a factor variable. You'll need to change it to a factor variable if you want it to be treated in that way. Do a summary or str on the design data for the parameter of interest.

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

Re: ORDMS Models

Postby gstauffer » Wed Sep 03, 2014 12:22 pm

If you code
Code: Select all
ddl$Phi$age=as.factor(ddl$Phi$Time-ddl$Phi$Cohort)

it should create the factor variable you want.
gstauffer
 
Posts: 17
Joined: Thu Sep 03, 2009 11:51 am

Re: ORDMS Models

Postby kpearson » Wed Sep 03, 2014 4:49 pm

Thank you both for the help! It appears to be modeling "time since arrival" correctly now.
kpearson
 
Posts: 5
Joined: Mon Sep 01, 2014 5:43 pm

Re: ORDMS Models

Postby jlaake » Wed Sep 03, 2014 5:06 pm

It is essential that you understand the structure of the underlying design data. If it is a numeric variable then you'll get a slope and if it is a factor variable you'll get a step function ( ie a value for each level). As Glenn showed you can translate from one to the other. If nx is numeric then

fx=factor(nx)

will give you a factor variable. Here is an example

Code: Select all
> nx=1:3
> str(nx)
 int [1:3] 1 2 3
> fx=factor(nx)
> fx
[1] 1 2 3
Levels: 1 2 3



If you use a factor variable in a formula you get a column in the design matrix for each level:

Code: Select all
> model.matrix(~fx,data.frame(fx=fx))
  (Intercept) fx2 fx3
1           1   0   0
2           1   1   0
3           1   0   1


and if you use a numeric variable you get an intercept and a slope

Code: Select all
> model.matrix(~nx,data.frame(nx=nx))
  (Intercept) nx
1           1  1
2           1  2
3           1  3


If you want to change a factor into a numeric use

newnx=as.numeric(as.character(fx))

for example:

Code: Select all
> newnx=as.numeric(as.character(fx))
> newnx
[1] 1 2 3


Note that in this case you could also use
Code: Select all
> as.numeric(fx)
[1] 1 2 3


But in general that does not work as shown below:
Code: Select all
> fx=factor(10:12)
> newnx=as.numeric(as.character(fx))
> newnx
[1] 10 11 12
> as.numeric(fx)
[1] 1 2 3


If you want to change which factor level is treated as the intercept use relevel

Code: Select all
 
# here 10 is the intercept
>  model.matrix(~fx,data.frame(fx=fx))
  (Intercept) fx11 fx12
1           1    0    0
2           1    1    0
3           1    0    1

# now 11 is the intercept
> fx=relevel(fx,"11")
>  model.matrix(~fx,data.frame(fx=fx))
  (Intercept) fx10 fx12
1           1    1    0
2           1    0    0
3           1    0    1

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

Re: ORDMS Models

Postby kpearson » Wed Sep 03, 2014 8:21 pm

Thanks again for your help! As you may have guessed I am new to RMark and R, so providing the additional detail and code cleared things up. I was able to remedy both of my issues.
kpearson
 
Posts: 5
Joined: Mon Sep 01, 2014 5:43 pm


Return to RMark

Who is online

Users browsing this forum: No registered users and 0 guests