multistate phi confidence interval using the delta method

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

multistate phi confidence interval using the delta method

Postby lrmont » Wed May 19, 2021 9:48 am

Dear All
I have been searching for previous discussions on this topic for a couple of days, but could not find a solution to my problem, so I decided to post as a new topic.
I am using a multistate model in RMark to calculate a tradeoff bewtween survival and reproduction, associated with a covariate (forearm length, proxy for body size) in bats. I have found no differences in apparent survival between strata (N - non breeder, B - breeder). I have predicted real values and 95% CI of S and Psi(N-B) for the observed range of the covariate. I would also like to calculate these for the transition phi = S*Psi(N-B).

In the Mark book chapter 10, there is mention to the possibility to calculate a standard error for phi using the Delta method, referring to Appendix B. I was able to calculate the phi standard error in probability scale with the output of covariate.predictions(), using deltamethod.special(), and assuming S and Psi(N-B) were independent. However, to estimate the phi confidence limits I would need to estimate the standard error in logit scale. I am sure I am probably approaching the problem from the wrong way, but could not find a similar problem discussed online.

Thank you for your time. I really appreciate any help that I can get.
Leandro
lrmont
 
Posts: 7
Joined: Tue May 30, 2017 10:00 am
Location: UENF, Rio de Janeiro, Brazil

Re: multistate phi confidence interval using the delta metho

Postby jlaake » Wed May 19, 2021 9:36 pm

Don't assume covariance is 0. Use covariate.predictions to get both S and Psi together and it will provide variances and covariances. Once you get variance of product z=xy then compute log(z/(1-z)) and apply delta method to compute variance of z, compute conf interval, and back transform end points to get confidence interval for z.

Will have to do delta method by hand for z.

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

Re: multistate phi confidence interval using the delta metho

Postby lrmont » Thu May 20, 2021 3:49 pm

Thanks Jeff
I have managed to obtain the confidence interval after your guidance. What I was missing was that once I had an estimate of the variance of the product, I had to use the delta method a second time to calculate the standard error of the logit transformation. Thanks for pointing that out.
Leandro
lrmont
 
Posts: 7
Joined: Tue May 30, 2017 10:00 am
Location: UENF, Rio de Janeiro, Brazil

Re: multistate phi confidence interval using the delta metho

Postby mbeatty » Thu Jan 18, 2024 6:07 pm

Hello,

I am tying to something similar to what is described in this post but have been unsuccessful. I am trying to use the deltamethod.special to get standard errors on Phi ( S X Psi) from a Multistrata model in RMark. Do I need to combine the Psi and S vcv matrices into one matrix to be able to reference them together in the deltamethod.special() function? They are vastly different sizes and the Psi vcv matrix is very large. I have 6 stratums, a fixed time covariate covering 26 years, and 2 age categories. I am not sure what code portions would be most helpful to share but would be happy to. Any suggestions would be greatly appreciated, thank you.
mbeatty
 
Posts: 3
Joined: Thu Jan 18, 2024 5:51 pm

Re: multistate phi confidence interval using the delta metho

Postby jlaake » Fri Jan 19, 2024 5:27 pm

Even if you don't have individual covariates, you'll need to use covariate.predictions to get the var-cov matrix of S and Psi. Presumably you don't want to multiply all S by all Psi as that wouldn't make sense. Can you better explain what you are trying to do and I can create a simple example with the mstrata data set and then you can go from there.
jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: multistate phi confidence interval using the delta metho

Postby mbeatty » Sat Jan 20, 2024 4:15 pm

Thank you for your quick response! The end product that I am interested in is the joint movement and survival probabilities for each stratum r and year t with associated stand errors, that you describe for MARK in Ch10.1-10.2 in the manual:
\phi^{rs}_t = S^r_t * \sum_{r \neq s} \psi^{rs}_t
\phi^{rr}_t = S^r_t * \psi^{rr}_t

where \psi^{rr}_t is the probability that an adult survives and remains in stratum r from year t to t +1 and \psi^{rs}_t the probability that an adult survives and moves from stratum r to s.

I have used get.real to extract the var-cov matrices of S and Psi:

Code: Select all
Slist<- get.real(top1, "S", se = TRUE, vcv = TRUE)

Code: Select all
Psilist<- get.real(top1, "Psi", vcv = TRUE)


but then was unsure how to apply the deltamethod.special to multiply them together as in the above equation? Or perhaps that is the wrong way to go about getting Phi? Thank you.
mbeatty
 
Posts: 3
Joined: Thu Jan 18, 2024 5:51 pm

Re: multistate phi confidence interval using the delta metho

Postby jlaake » Sat Jan 20, 2024 10:13 pm

ok. That would be Evan that wrote that in section 10.1. Not me. Regardless I assume that you didn't want a sum operator. If that is correct then what you want is for each strata the product of S for the strata and Psi for each transition from the stratum to all the other stratum including staying in the same stratum.

As I wrote earlier, you have to use covariate.predictions and not get.real. The latter works with only one parameter at a time and you need to extract both S and Psi together to get the covariances between S and Psi. This is easiest to do with the function covariate.predictions even if you don't have individual covariates.

You provide the set of indices for the parameters that you want and it provides the real estimates and the var-cov matrix. So for example, you might provide the indices for time 1 for S in stratum A and the Psi for time 1 for stratum A to all the other strata. It would return the real values and their var-cov matrix. From there you would have to use deltamethod and specify the formula for the products. Now this gets messy because the formula for staying is 1-sum of moving to other strata. As an example, if you pass deltamethod a vector (SA,PsiAB,PsiAC) for strata A,B,C then you would specify list(~x1*x2,~x1*x3,~x1*(1-x2-x3)). This list will get longer as the number of strata increase but it is quite plausible to do it this way. As long as you don't need covariances between all of your calculations, it would be easiest to loop over time and strata and store the results.

So it might actually be easier to write code to implement the delta method for this particular case and I'm willing to do that for you but I really want to understand why you want this computation. What question are you asking that you need this product? in other words, how are you using it?

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

Re: multistate phi confidence interval using the delta metho

Postby mbeatty » Sun Jan 21, 2024 11:52 am

Hi Jeff,

Thank you for the detailed explanation and apologies for my errors. I think the only value that is strictly necessary is \phi^{rr}. I will explain below. I need it for each year t and age class (juvenile (J), adult (A)), not just stratum. I used the sum operator because I only use the total transition probability of surviving and leaving the stratum from year t to t+1 (1-\phi^{rr}_t). I may misunderstand and the sum is already implied?

I am using these values to estimate annual source-sink dynamics using the C^r metric (sensu Runge et al 2006, https://www.journals.uchicago.edu/doi/full/10.1086/503531 ). An important piece of my final interpretation is to compare the C^r and R^r metrics (the contribution of a stratum to the metapopulation vs itself, in a given year, respectively). I am using the same theory as in that paper but adding an annual component, t,: C^r_t.

I have been able to calculate C^r_t with uncertainity:

C^r_t = \phi^{rr}_{At} + \sum_{r \neq s}\phi^{rs}_{At} + \beta^r_{At}(\phi^{rr}_{Jt} + \sum_{r \neq s}\phi^{rs}_{Jt})

because

\phi^{rr}_{At} + \sum_{r \neq s}\phi^{rs}_{At} = S^r_t

if you assume apparent survival approximates true survival, which we do in this case.

However to calculate R^r_t I need \phi^{rr} separately:

R^r_t  = \phi^{rr}_{At} +   \beta^r_{At}(\phi^{rr}_{Jt}) .

Up to this point I have been doing the calculations of phi manually (S x Psi), but without the SE's on Phi I can't have any uncertainty on R^r, which I would ideally have.

There is one further complication that I am not sure will matter: each stratum interacts with the time covariate differently based a continuous covariate that dictates when they are allowed to vary annually. For example, for one stratum, survival and movement are estimated as constant 1997-2004 and then can vary after that, but for another stratum survival and movement are constant from 1997-2009 can then vary after that.

I could provide further detail if it is helpful. I greatly appreciate you time and feedback on this! Thank you,

Meghan
mbeatty
 
Posts: 3
Joined: Thu Jan 18, 2024 5:51 pm

Re: multistate phi confidence interval using the delta metho

Postby jlaake » Wed Jan 24, 2024 7:53 pm

I worked with Meghan offlist and learned that she was primarily interested in the product of survival and staying in the same stratum. I wrote the following function to compute the point estimates and std errors using deltamethod function in msm. I show an example using the mstrata example data set but it will work with any MS model which uses the default of subtract.stratum values of computing the probability of staying by subtraction. It computes the point estimate and std error of each record in the S design data and then returns the S design data with the estimates so you can do whatever you want with it. Depending on the model, many of the values can be identical. If anyone other than Meghan uses this please let me know if you have any questions or problems. It can be easily modified to produce the other result she described of surviving and leaving by summing Psi rather than subtracting sum from 1. Brownie points given to anyone that can devise a better name for the function. If folks think this could be useful, I could add to RMark package. Otherwise feel free to use.

Code: Select all
library(RMark)
library(msm)
data(mstrata)
mstrata.proc=process.data(mstrata,model="Multistrata")
mstrata.ddl=make.design.data(mstrata.proc)
model=mark(mstrata.proc,mstrata.ddl)

compute_Phi_stay=function(ddl,model)
{
 nstrata=length(levels(ddl$S$stratum))
 Srep=do.call("rbind",lapply(split(ddl$S,ddl$S$stratum),
   function(x) x[rep(1:nrow(x),nstrata-1),]))
 ddl$Psi$SIndex=Srep$model.index
 x=ddl$Psi
 x=split(x,x$SIndex)
 est=lapply(x, function(x){
      covariate.predictions(model,indices=c(x$SIndex[1],x$model.index))})

 deltaformula=as.formula(paste("~x1*(1-",paste(paste("x",(2:length(levels(ddl$S$stratum))),sep=""),collapse="-"),")",sep=""))

 x=do.call("rbind",lapply(1:length(est), function(i) {
  data.frame(estimate=as.vector(est[[i]]$estimates$estimate[1]*(1-sum(est[[i]]$estimates$estimate[2:nrow(est[[i]]$estimates)]))),
                                                            se=as.vector(deltamethod(deltaformula,est[[i]]$estimates$estimate,est[[i]]$vcv) ) )}))
 return(cbind(ddl$S,x))
}

compute_Phi_stay(mstrata.ddl,model)
jlaake
 
Posts: 1417
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 7 guests