Model formula for sin link (fully time varying) in RMark

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

Model formula for sin link (fully time varying) in RMark

Postby nathan_whitmore » Tue Jan 16, 2024 8:52 pm

Hi there,

I'm new to RMark and to ensure I understand what I'm doing I'm attempting to fully replicate my program MARK results in RMark. I’m using a Huggins closed capture approach so am playing around with differing parametrisations of p (initial capture) and c (recapture) being shared or not between models. The results in MARK were created with a sin link, and as the default for RMark is a logit link my understanding is I have to drop the intercept in the model formula in order to specify the use of an identity matrix e.g.

Code: Select all
p.group.equals.c.group = list(formula = ~-1 + group, share = TRUE, link="sin")


Code: Select all
p.group.diff.c.group = list(p=list(formula=~ -1 + group, link = "sin"),
                               c=list(formula=~ -1 + group, link = "sin"))


Okay so far so good – with all these and other simple models I get the same answer between MARK and RMark. Where I stumble is with a fully time varying model…

Code: Select all
p.time.group.equals.c.time.group = list(formula = ~ -1  + time * group, share = TRUE,  link = "sin")


which returns the error:

Cannot use sin link with non-identity design matrix. Error in mark(model.parameters = model.parameters, initial = initial, : Misspecification of model or internal error in code


What might I be doing wrong in this last example?
nathan_whitmore
 
Posts: 4
Joined: Mon Jun 28, 2021 12:24 am

Re: Model formula for sin link (fully time varying) in RMark

Postby darryl » Tue Jan 16, 2024 9:39 pm

Hi Nathan
It's not immediately apparent what the problem is, but with these types of issues it can be useful to break the model fitting process into a series of steps rather just using the mark() function to fit the model, which is actually a wrapper function (at least I presume that's what you're doing).

If you use the functions:
process.data()
make.design.data()
make.mark.model()

the output of that 3rd function will give you the design matrix that RMark is building before it tries to actually fit the model in MARK. Check the help documentation for usage and arguments for these functions.

Cheers
Darryl
darryl
 
Posts: 498
Joined: Thu Jun 12, 2003 3:04 pm
Location: Dunedin, New Zealand

Re: Model formula for sin link (fully time varying) in RMark

Postby jlaake » Tue Jan 16, 2024 9:42 pm

Use ~-1+time:group and it should work.
jlaake
 
Posts: 1479
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Model formula for sin link (fully time varying) in RMark

Postby nathan_whitmore » Tue Jan 16, 2024 10:40 pm

Hi there,

Thanks Jeff - that works perfectly.

And yeah, Darryl - your tip is super helpful as I totally wanted to know how to check the design matrices before running the model proper (so could confirm the formula matched the model I envisioned).

Have a great evening.

Cheers,
Nathan
nathan_whitmore
 
Posts: 4
Joined: Mon Jun 28, 2021 12:24 am

Re: Model formula for sin link (fully time varying) in RMark

Postby jlaake » Wed Jan 17, 2024 10:09 am

If you have 2 factor variables say fac1 and fac2 and you use fac1:fac2 it creates a column in the design matrix for all combinations of the levels of each factor variable. Let's say they are a,b for fac1 and 1,2,3 for fac2. Then you will get a1,a2,a3,b1,b2,b3 columns which will provide 6 parameters for the 6 cells. By default the formula will add an intercept which would be one more parameter too many so you have to include -1 to remove the intercept or the model will be over-parameterized which means there is no data to estimate the additional parameter.

Darryl's idea works and a similar one is to add run=FALSE to mark function. If you don't have individual covariates (variables with capture histories) then you can also use model.matrix with the formula and design data for a specific parameter. The only downside in that is that it can contain columns with all zero values that RMark removes. So the best way to do it is what Darryl suggests.

The other place this approach is useful is with multistate models in which the state transitions from one state to the others can be specified as ~-1+stratum:tostratum because the strata you can move to differ across strata if by default staying in the same stratum is computed by subtraction.

This material is described in the workshop notes in the RMark documentation archive. A link to the archive is given each time you type library(RMark).
jlaake
 
Posts: 1479
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA


Return to RMark

Who is online

Users browsing this forum: No registered users and 1 guest

cron