question about multi-state model in RMark versus MARK

I am having trouble reproducing estimates from MARK when using a multi-state model in RMark and I am hoping someone might spot my mistake and correct it. I do obtain the same correct estimates with MARK and RMark with an initial model, but not with a second, more-complex model.
I feel bad asking such a detailed question, but I am at a loss and appreciate any help you can offer.
I am using the following set of fake data:
There are four states and six visits. For simplicity I constrain survival and detection probability to one.
All animals begin in State 1. Animals in State 1 can move to States 1, 2 or 3. Animals in State 2 must remain there. Animals in State 3 can move to States 3 or 4. Animals in State 4 must remain there.
The simplest model under this scenario has three constant parameters. Here are the estimates from Program MARK. These estimates are correct, as far as I can tell:
Model.1 of the RMark code below returns the same estimates as those above.
However, if I try to constrain Psi 1 to 2, Psi 1 to 3, and Psi 3 to 4 to zero between some visits and Psi 1 to 3 is allowed to take on two different estimates (using the following design matrix) I get the correct answer with MARK, but not with RMark.
Here is the design matrix:
Here are the correct estimates from Program MARK using the design matrix immediately above:
However, model.2 in RMark, does not constrain Psi 1 to 2 to a constant value for the first three time periods. Rather, RMark allows Psi 1 to 2 to differ between the second and third time period even though I think I specifically constrain Psi 1 to 2 to have the same value for each of the first three time periods.
Why does RMark allow the estimate for Psi 1 to 2 to differ among the first three visits versus between the third and fourth visit even though I, apparently, have constrained Psi 1 to 2 to be constant among the first four visits?
Here is the R code.
I feel bad asking such a detailed question, but I am at a loss and appreciate any help you can offer.
I am using the following set of fake data:
- Code: Select all
111333 9 ;
111334 3 ;
111344 4 ;
111222 16 ;
112222 32 ;
122222 64 ;
There are four states and six visits. For simplicity I constrain survival and detection probability to one.
All animals begin in State 1. Animals in State 1 can move to States 1, 2 or 3. Animals in State 2 must remain there. Animals in State 3 can move to States 3 or 4. Animals in State 4 must remain there.
The simplest model under this scenario has three constant parameters. Here are the estimates from Program MARK. These estimates are correct, as far as I can tell:
- Code: Select all
Real Function Parameters of {initial DM}
95% Confidence Interval
Parameter Estimate Standard Error Lower Upper
---------------- -------------- -------------- -------------- --------------
1:S 1:State 1 1.0000000 0.0000000 1.0000000 1.0000000 Fixed
2:Psi 1 to 2 0.5000000 0.0334077 0.4348928 0.5651072
3:Psi 1 to 3 0.0714286 0.0172076 0.0442159 0.1134020
4:Psi 1 to 4 0.0000000 0.0000000 0.0000000 0.0000000 Fixed
5:Psi 3 to 4 0.2500000 0.0818317 0.1241150 0.4394984
Model.1 of the RMark code below returns the same estimates as those above.
However, if I try to constrain Psi 1 to 2, Psi 1 to 3, and Psi 3 to 4 to zero between some visits and Psi 1 to 3 is allowed to take on two different estimates (using the following design matrix) I get the correct answer with MARK, but not with RMark.
Here is the design matrix:
- Code: Select all
Survival: 0 0 0 0;
Psi 1-2: 1 0 0 0;
Psi 1-2: 1 0 0 0;
Psi 1-2: 1 0 0 0;
Psi 1-2: 0 0 0 0;
Psi 1-2: 0 0 0 0;
Psi 1-3: 0 1 0 0;
Psi 1-3: 0 1 0 0;
Psi 1-3: 0 0 1 0;
Psi 1-3: 0 0 0 0;
Psi 1-3: 0 0 0 0;
Psi 3-4: 0 0 0 0;
Psi 3-4: 0 0 0 0;
Psi 3-4: 0 0 0 0;
Psi 3-4: 0 0 0 1;
Psi 3-4: 0 0 0 1;
Psi 1-4: 0 0 0 0;
Here are the correct estimates from Program MARK using the design matrix immediately above:
- Code: Select all
Parameter Estimate Standard Error Lower Upper
-------------------- -------------- -------------- -------------- --------------
1:S 1:State 1 1.0000000 0.0000000 1.0000000 1.0000000 Fixed
2:Psi 1 to 2 0.5000000 0.6705308E-005 0.4999868 0.5000131
3:Psi 1 to 2 0.5000000 0.6705308E-005 0.4999868 0.5000131
4:Psi 1 to 2 0.5000000 0.0883884 0.3333739 0.6666261
5:Psi 1 to 2 0.0000000 0.0000000 0.0000000 0.0000000 Fixed
6:Psi 1 to 2 0.0000000 0.0000000 0.0000000 0.0000000 Fixed
7:Psi 1 to 3 0.1067929E-009 0.3003999E-006 -.5886770E-006 0.5888906E-006
8:Psi 1 to 3 0.1067929E-009 0.3003999E-006 -.5886770E-006 0.5888906E-006
9:Psi 1 to 3 0.5000000 0.0883884 0.3333739 0.6666261
10:Psi 1 to 3 0.0000000 0.0000000 0.0000000 0.0000000 Fixed
11:Psi 1 to 3 0.0000000 0.0000000 0.0000000 0.0000000 Fixed
12:Psi 3 to 4 0.0000000 0.0000000 0.0000000 0.0000000 Fixed
13:Psi 3 to 4 0.0000000 0.0000000 0.0000000 0.0000000 Fixed
14:Psi 3 to 4 0.0000000 0.0000000 0.0000000 0.0000000 Fixed
15:Psi 3 to 4 0.2499999 0.0818317 0.1241149 0.4394982
16:Psi 3 to 4 0.2499999 0.0818317 0.1241149 0.4394982
17:Psi 1 to 4 0.0000000 0.0000000 0.0000000 0.0000000 Fixed
However, model.2 in RMark, does not constrain Psi 1 to 2 to a constant value for the first three time periods. Rather, RMark allows Psi 1 to 2 to differ between the second and third time period even though I think I specifically constrain Psi 1 to 2 to have the same value for each of the first three time periods.
Why does RMark allow the estimate for Psi 1 to 2 to differ among the first three visits versus between the third and fourth visit even though I, apparently, have constrained Psi 1 to 2 to be constant among the first four visits?
Here is the R code.
library(RMark)
setwd('C:/Users/markm/simple R programs/')
my.data = convert.inp("fakeJan23.inp")
n.visits <- dim(my.data)[1]
mstrat.processed = process.data(my.data, model="Multistrata", time.intervals = rep(1, n.visits-1) )
mstrat.ddl = make.design.data(mstrat.processed)
#
# Additions to the design matrix
#
mstrat.ddl$Psi$mystrat12 = 0
mstrat.ddl$Psi$mystrat12[ mstrat.ddl$Psi$stratum == 1 & mstrat.ddl$Psi$to2 == 1 & mstrat.ddl$Psi$time %in% c(1,2,3)] = 1
mstrat.ddl$Psi$mystrat13a = 0
mstrat.ddl$Psi$mystrat13a[mstrat.ddl$Psi$stratum == 1 & mstrat.ddl$Psi$to3 == 1 & mstrat.ddl$Psi$time %in% c(1:2)] = 1
mstrat.ddl$Psi$mystrat13b = 0
mstrat.ddl$Psi$mystrat13b[mstrat.ddl$Psi$stratum == 1 & mstrat.ddl$Psi$to3 == 1 & mstrat.ddl$Psi$time %in% c(3) ] = 1
mstrat.ddl$Psi$mystrat34 = 0
mstrat.ddl$Psi$mystrat34[ mstrat.ddl$Psi$stratum == 3 & mstrat.ddl$Psi$to4 == 1 & mstrat.ddl$Psi$time %in% c(4:5)] = 1
#############################################################
#
# Constrain survival and p = 1 and constrain some transitions = 0
#
pre.S = as.numeric(row.names(mstrat.ddl$S[ mstrat.ddl$S$time %in% c(1:(n.visits-1)), ]))
pre.p = as.numeric(row.names(mstrat.ddl$p[ mstrat.ddl$p$time %in% c(2: n.visits ), ]))
pre.P12 = as.numeric(row.names(mstrat.ddl$Psi[ mstrat.ddl$Psi$stratum == 1 & mstrat.ddl$Psi$to2 == 1 & mstrat.ddl$Psi$time %in% c(4:5), ]))
pre.P13 = as.numeric(row.names(mstrat.ddl$Psi[ mstrat.ddl$Psi$stratum == 1 & mstrat.ddl$Psi$to3 == 1 & mstrat.ddl$Psi$time %in% c(4:5), ]))
pre.P14 = as.numeric(row.names(mstrat.ddl$Psi[ mstrat.ddl$Psi$stratum == 1 & mstrat.ddl$Psi$to4 == 1, ]))
pre.P21 = as.numeric(row.names(mstrat.ddl$Psi[ mstrat.ddl$Psi$stratum == 2 & mstrat.ddl$Psi$to1 == 1, ]))
pre.P23 = as.numeric(row.names(mstrat.ddl$Psi[ mstrat.ddl$Psi$stratum == 2 & mstrat.ddl$Psi$to3 == 1, ]))
pre.P24 = as.numeric(row.names(mstrat.ddl$Psi[ mstrat.ddl$Psi$stratum == 2 & mstrat.ddl$Psi$to4 == 1, ]))
pre.P31 = as.numeric(row.names(mstrat.ddl$Psi[ mstrat.ddl$Psi$stratum == 3 & mstrat.ddl$Psi$to1 == 1, ]))
pre.P32 = as.numeric(row.names(mstrat.ddl$Psi[ mstrat.ddl$Psi$stratum == 3 & mstrat.ddl$Psi$to2 == 1, ]))
pre.P34 = as.numeric(row.names(mstrat.ddl$Psi[ mstrat.ddl$Psi$stratum == 3 & mstrat.ddl$Psi$to4 == 1 & mstrat.ddl$Psi$time %in% c(1:3), ]))
pre.P41 = as.numeric(row.names(mstrat.ddl$Psi[ mstrat.ddl$Psi$stratum == 4 & mstrat.ddl$Psi$to1 == 1, ]))
pre.P42 = as.numeric(row.names(mstrat.ddl$Psi[ mstrat.ddl$Psi$stratum == 4 & mstrat.ddl$Psi$to2 == 1, ]))
pre.P43 = as.numeric(row.names(mstrat.ddl$Psi[ mstrat.ddl$Psi$stratum == 4 & mstrat.ddl$Psi$to3 == 1, ]))
#####################################################################
#
# This works
#
S.stratum = list(formula =~ 1, link="sin",
fixed = list(index = c(pre.S), value = 1))
p.stratum = list(formula =~ 1, link="sin",
fixed = list(index = c(pre.p), value = 1))
Psi.s = list(formula =~ -1 + stratum:tostratum,
fixed = list(index = c( pre.P14,
pre.P21, pre.P23, pre.P24,
pre.P31, pre.P32,
pre.P41, pre.P42, pre.P43), value = 0))
model.1 <- mark(mstrat.processed, mstrat.ddl,
model.parameters=list(S = S.stratum, p = p.stratum, Psi = Psi.s))
########################################################################
#
# This does not works
#
S.stratum = list(formula =~ 1, link="sin",
fixed = list(index = c(pre.S), value = 1))
p.stratum = list(formula =~ 1, link="sin",
fixed = list(index = c(pre.p), value = 1))
Psi.s = list(formula =~ -1 + mystrat12 + mystrat13a + mystrat13b + mystrat34,
fixed = list(index = c(pre.P12, pre.P13, pre.P14,
pre.P21, pre.P23, pre.P24,
pre.P31, pre.P32, pre.P34,
pre.P41, pre.P42, pre.P43), value = 0))
model.2 <- mark(mstrat.processed, mstrat.ddl,
model.parameters=list(S = S.stratum, p = p.stratum, Psi = Psi.s))
########################################################################