fix two parameters to be equal

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

fix two parameters to be equal

Postby tontym » Mon Feb 21, 2022 9:55 pm

Hi -
I have a multistate model with two groups and three states. After the first few occasions, the group structure doesn't matter and I would like to set survival and transition probabilities to be equal for the two groups, but still varying by state and time, depending on the specific model I'm running. I have read a lot about how to fix parameters to a specific value, but is it possible within Rmark to fix two parameters to be equivalent? I'm using a pim.type="time" for all S, psi, and p.
tontym
 
Posts: 5
Joined: Tue Aug 24, 2021 12:55 pm

Re: fix two parameters to be equal

Postby jhines » Tue Feb 22, 2022 9:40 am

To set parameters to be equal, you can add a column to the design-data data-frame. If you examine the matrix created by "make.design.data", you'll see a list variable for each parameter, S, psi, and p. Each of those list variables contains a row for every possible classification for the parameter. For example, S can be estimated by group, strata, age, time or cohort. The formula for S will contain zero or more names of the columns in that matrix. If you have two groups, and your formula for S is "~group", then RMark will create a model where all possible S parameters which have group=1 to be equal and all possible S parameters which have group=2 to be something else. If your formula is “~group*stratum”, with 2 groups and 3 strata, then RMark will create a model with 6 survival parameters, one for each combination of group and strata and will map each possible classification (row of the design data) to one of those 6 values.

A model with state, group and time would have a formula of S~group*stratum*time and map those classifications to one of 2*3*10 possible S parameters (assuming 2 groups, 3 strata, 11 occasions). The trick to setting S’s equal for 2 groups after a particular occasion would be to create a new “group” column in the design data matrix for S. This column, let’s call it “grpX” will contain the same values as the “group” column for the rows where time <= 3 (assuming you want S to be equal for the groups after occasion 3). For all rows where time >= 3, set this grpX variable to equal to a third group value (3). This 3rd group would be the set of survival rates for both groups combined.

Here's some sample R code:

Code: Select all
dd <- make.design.data(data=procdata, …)

#  create new group variable, grpX, set equal to group
dd$S$grpX <- dd$S$group

# change grpX to 3 for all rows where time > 3
dd$S$grpX[dd$S$time > 3] <- 3

#  make sure grpX is a factor variable
dd$S$grpX <- factor(dd$S$grpX, levels=c(1,2,3))

#  create RMark formula for new group*stratum*time model
SgrpX <- list(formula=~grpX*stratum*time)

#  run Mark function
modSgrpX <- mark(data=procdata, ddl=dd, model.parameters=list(S=SgrpX, psi=…)



Now, all rows in the design data with time>3 will have the same grpX value, so the two groups will have the same set of survival rates for each time and strata.

If I left something out, feel free to email me directly (jhines@usgs.gov)
jhines
 
Posts: 632
Joined: Fri May 16, 2003 9:24 am
Location: Laurel, MD, USA

Re: fix two parameters to be equal

Postby tontym » Tue Feb 22, 2022 9:18 pm

Thank you so much!
tontym
 
Posts: 5
Joined: Tue Aug 24, 2021 12:55 pm

Re: fix two parameters to be equal

Postby jlaake » Mon Feb 28, 2022 9:46 am

Thanks to Jim for answering this question. While it is a subtle difference, I think it is important to consider this as constraining two parameters to be equal rather than fixing parameters. In RMark fix implies the real values are assigned specific values. Whenever you're constraining parameters to be the same you should think about the design matrix because that is what it does.
jlaake
 
Posts: 1479
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: fix two parameters to be equal

Postby tontym » Sun Mar 13, 2022 8:42 pm

I have a somewhat related question. I have a multistate model with three states (A,B,C) and 10 occasions. All parameter estimates are constrained to two seasons, "summer" (occasions 1-5) and "winter" (occasions 6-10). I would like to run models such as :
S ~ stratum*season
p ~ stratum*season
Psi ~ stratum:tostratum*season

However, I also want to constrain some transitions to be equal during some seasons, such as upstream transitions in summer. and downstream transitions in winter. So B->A is equal to C->B in summer. A->B is equal to B->C in winter.

I started by following the advice in this forum: viewtopic.php?f=21&t=515
Code: Select all
# create dummy variable "BgrdPsi"
cap.ddl$Psi$BgrdPsi=NA

# summer background transition rate
cap.ddl$Psi$BgrdPsi[
  cap.ddl$Psi$stratum=="B"&cap.ddl$Psi$tostratum=="A"&cap.ddl$Psi$Season=="S"|
    cap.ddl$Psi$stratum=="C"&cap.ddl$Psi$tostratum=="B"&cap.ddl$Psi$Season=="S"]=1
# winter background transition rate
cap.ddl$Psi$BgrdPsi[
  cap.ddl$Psi$stratum=="A"&cap.ddl$Psi$tostratum=="B"&cap.ddl$Psi$Season=="W"|
    cap.ddl$Psi$stratum=="B"&cap.ddl$Psi$tostratum=="C"&cap.ddl$Psi$Season=="W"]=2


I'm not sure how to specify that all the other design data columns should be separate, but following the earlier constraint by season?
tontym
 
Posts: 5
Joined: Tue Aug 24, 2021 12:55 pm

Re: fix two parameters to be equal

Postby jlaake » Sun Mar 13, 2022 10:14 pm

Are there constraints other than what you listed? Please describe your transition in more detail. For example you specify B to A and C to B being equal but can they go C to A? Likewise A to C in winterer. Can they go upstream in winter and downstream in summer?
jlaake
 
Posts: 1479
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: fix two parameters to be equal

Postby tontym » Mon Mar 14, 2022 8:40 pm

Sorry for being unclear, the exact details for my model are a bit more complicated and I was trying to simplify. To be more descriptive, I have some transitions that do not occur at all in some seasons. For those, I added a column "fix" and set to zero. Each season there are few transitions that are uncommon, but greater than zero. Rather than fixing those transitions to zeros and manually editing capture histories to remove those transitions and losing survival data, I was hoping to constrain those uncommon transitions to be equal as a "background transition rate".

So for psi I already have:
1) season constraints
2) an additional grouping variable with three levels
3) occasion-specific temperature and flow
I would like to add:
4) some transitions constrained to be equal within a season
tontym
 
Posts: 5
Joined: Tue Aug 24, 2021 12:55 pm

Re: fix two parameters to be equal

Postby jlaake » Mon Mar 14, 2022 9:23 pm

Well as my first post to this thread said, constraining parameters to be equal is done with the design matrix so I can't really help without knowing which transitions are not fixed. For example, you can't use stratum: tostratum in the formula and have equality on some of those parameters because that would specify all separate parameters. You would have to restrict the stratum: tostratum to only apply to those that are not being constrained to be equal. You only have 3 strata so there are only 6 combinations. Assuming subtract.stratum is the default of A,B,C, then the combinations are AB,AC,BA,BC,CA,CB. Now you said some of these are fixed to 0 so they can be dropped. You can create ~-1+stratum:tostratum as ~-1+AB+AC+BA+BC+CA+CB. Any fixed would be dropped. If you wanted those to differ by season it would be -1+season:(AB+AC+BA+BC+CA+CB). Now that is more simply specified as -1+season:stratum: tostratum but that doesn't allow you to constrain some to be equal. To do so you can use longer formula andcreate a 0/1 variable which is 1 for the combinations that are the same and you would drop the separate terms that are being constrained. Since you want these to vary based on season, you would want to expand formula further to have separate summer and winter components. If you still struggle with this contact me off list. jefflaake@gmail.com
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 2 guests