Here, you’ll find code for running each of the models used in lab this week with the “lab_06.inp” data set. You’ll also find the model-selection table, model-specific results, and results based on some follow-up work with the output from the top model.
# Lab 06 for WILD 502 at Montana State University
library(RMark)
## This is RMark 2.2.4
## Documentation available at http://www.phidot.org/software/mark/rmark/RMarkDocumentation.zip
ms <- convert.inp("http://www.montana.edu/rotella/documents/502/lab_06.inp",
group.df = NULL, covariates = NULL)
head(ms)
## ch freq
## 1 A000000 55
## 2 ACC0000 1
## 3 ACCCC00 1
## 4 A00CCC0 1
## 5 AA00000 5
## 6 AAC0000 3
options(width = 150)
# Process data
ms.pr = process.data(ms, begin.time = 1, model = "Multistrata")
#
# Create default design data
ms.ddl = make.design.data(ms.pr)
# examine the data
# Because the output is so long, here, only the head of each
# piece of design data is shown
head(ms.ddl$S)
## par.index model.index group cohort age time occ occ.cohort stratum Cohort Age Time A B C
## 1 1 1 1 1 0 1 1 1 A 0 0 0 1 0 0
## 2 2 2 1 1 1 2 2 1 A 0 1 1 1 0 0
## 3 3 3 1 1 2 3 3 1 A 0 2 2 1 0 0
## 4 4 4 1 1 3 4 4 1 A 0 3 3 1 0 0
## 5 5 5 1 1 4 5 5 1 A 0 4 4 1 0 0
## 6 6 6 1 1 5 6 6 1 A 0 5 5 1 0 0
head(ms.ddl$p)
## par.index model.index group cohort age time occ occ.cohort stratum Cohort Age Time A B C
## 1 1 64 1 1 1 2 1 1 A 0 1 0 1 0 0
## 2 2 65 1 1 2 3 2 1 A 0 2 1 1 0 0
## 3 3 66 1 1 3 4 3 1 A 0 3 2 1 0 0
## 4 4 67 1 1 4 5 4 1 A 0 4 3 1 0 0
## 5 5 68 1 1 5 6 5 1 A 0 5 4 1 0 0
## 6 6 69 1 1 6 7 6 1 A 0 6 5 1 0 0
head(ms.ddl$Psi)
## par.index model.index group cohort age time occ occ.cohort stratum tostratum Cohort Age Time A B C toA toB toC
## 1 1 127 1 1 0 1 1 1 A B 0 0 0 1 0 0 0 1 0
## 2 2 128 1 1 1 2 2 1 A B 0 1 1 1 0 0 0 1 0
## 3 3 129 1 1 2 3 3 1 A B 0 2 2 1 0 0 0 1 0
## 4 4 130 1 1 3 4 4 1 A B 0 3 3 1 0 0 0 1 0
## 5 5 131 1 1 4 5 5 1 A B 0 4 4 1 0 0 0 1 0
## 6 6 132 1 1 5 6 6 1 A B 0 5 5 1 0 0 0 1 0
Here, we set up a function that contains the structures for ‘S’, ‘p’, and ‘Psi’. It will run all combinations of the structures for each parameter type when executed.
run.ms = function() {
# Define range of models for S;
# Note: when you use RMark, "S.stratum = list(formula = ~ stratum)"
# will create 3 beta's: 1st beta = intercept (state A = baseline),
# 2nd beta = intercept adjustment for state B,
# 3rd beta = intercept adjustment for state C
# i.e., RMark's default design matrix using treatment contrasts
# Below, I use "S.stratum = list(formula = ~ -1 + stratum)" instead,
# which creates a Design Matrix that's an identity matrix such that
# the 3 resulting betas are each used alone to estimate rates for
# survival in states A, B and C.
# Also, RMark will use logit links for survival and detection and
# the multinomial logit for the probabilities of leaving a stratum
S.dot = list(formula = ~ 1)
S.stratum = list(formula = ~ -1 + stratum)
#
# Define range of models for p
p.dot = list(formula = ~ 1)
p.stratum = list(formula = ~ stratum)
#
# Define range of models for Psi; what is denoted as s for Psi
# in the Mark example for Psi is accomplished by -1+stratum:tostratum,
# which nests tostratum within stratum.
Psi.s = list(formula = ~ -1 + stratum:tostratum)
# Create model list and run assortment of models
ms.model.list = create.model.list("Multistrata")
# NOTE: if you do not want to see the output for each model, add the text
# ", output=FALSE" after "ddl=ms.ddl" below. Here, I don't do that
# so you can see the output for each model, but this might not be
# desired if you have a lot of models!
ms.results = mark.wrapper(ms.model.list,
data = ms.pr, ddl = ms.ddl)
#
# Return model table and list of models
#
return(ms.results)
}
It’s very simple to then run the function and each of the models. As implemented here, the output from each of the models appears in the console where it can be reviewed when the function written above is called. If you don’t want the output from every model to appear automatically, see the note above the “mark.wrapper” command for how to set the option of suppressing the output. One can also examine model-specific output in other ways as shown below.
ms.results = run.ms()
##
## S.dot.p.dot.Psi.s
##
## Output summary for Multistrata model
## Name : S(~1)p(~1)Psi(~-1 + stratum:tostratum)
##
## Npar : 8
## -2lnL: 6086.525
## AICc : 6102.592
##
## Beta
## estimate se lcl ucl
## S:(Intercept) 1.1116167 0.0700263 0.9743652 1.2488682
## p:(Intercept) -0.4766315 0.0619776 -0.5981076 -0.3551555
## Psi:stratumB:tostratumA -1.3060046 0.2376435 -1.7717858 -0.8402234
## Psi:stratumC:tostratumA -2.8736357 0.2017240 -3.2690147 -2.4782567
## Psi:stratumA:tostratumB -0.4988933 0.2995349 -1.0859816 0.0881951
## Psi:stratumC:tostratumB -1.7266264 0.1197577 -1.9613515 -1.4919013
## Psi:stratumA:tostratumC 0.6428163 0.2195161 0.2125647 1.0730679
## Psi:stratumB:tostratumC 0.2772310 0.1473783 -0.0116306 0.5660926
##
##
## Real Parameter S
## Stratum:A
## 1 2 3 4 5 6
## 1 0.7524304 0.7524304 0.7524304 0.7524304 0.7524304 0.7524304
## 2 0.7524304 0.7524304 0.7524304 0.7524304 0.7524304
## 3 0.7524304 0.7524304 0.7524304 0.7524304
## 4 0.7524304 0.7524304 0.7524304
## 5 0.7524304 0.7524304
## 6 0.7524304
##
## Stratum:B
## 1 2 3 4 5 6
## 1 0.7524304 0.7524304 0.7524304 0.7524304 0.7524304 0.7524304
## 2 0.7524304 0.7524304 0.7524304 0.7524304 0.7524304
## 3 0.7524304 0.7524304 0.7524304 0.7524304
## 4 0.7524304 0.7524304 0.7524304
## 5 0.7524304 0.7524304
## 6 0.7524304
##
## Stratum:C
## 1 2 3 4 5 6
## 1 0.7524304 0.7524304 0.7524304 0.7524304 0.7524304 0.7524304
## 2 0.7524304 0.7524304 0.7524304 0.7524304 0.7524304
## 3 0.7524304 0.7524304 0.7524304 0.7524304
## 4 0.7524304 0.7524304 0.7524304
## 5 0.7524304 0.7524304
## 6 0.7524304
##
##
## Real Parameter p
## Stratum:A
## 2 3 4 5 6 7
## 1 0.3830479 0.3830479 0.3830479 0.3830479 0.3830479 0.3830479
## 2 0.3830479 0.3830479 0.3830479 0.3830479 0.3830479
## 3 0.3830479 0.3830479 0.3830479 0.3830479
## 4 0.3830479 0.3830479 0.3830479
## 5 0.3830479 0.3830479
## 6 0.3830479
##
## Stratum:B
## 2 3 4 5 6 7
## 1 0.3830479 0.3830479 0.3830479 0.3830479 0.3830479 0.3830479
## 2 0.3830479 0.3830479 0.3830479 0.3830479 0.3830479
## 3 0.3830479 0.3830479 0.3830479 0.3830479
## 4 0.3830479 0.3830479 0.3830479
## 5 0.3830479 0.3830479
## 6 0.3830479
##
## Stratum:C
## 2 3 4 5 6 7
## 1 0.3830479 0.3830479 0.3830479 0.3830479 0.3830479 0.3830479
## 2 0.3830479 0.3830479 0.3830479 0.3830479 0.3830479
## 3 0.3830479 0.3830479 0.3830479 0.3830479
## 4 0.3830479 0.3830479 0.3830479
## 5 0.3830479 0.3830479
## 6 0.3830479
##
##
## Real Parameter Psi
## Stratum:A To:B
## 1 2 3 4 5 6
## 1 0.1730398 0.1730398 0.1730398 0.1730398 0.1730398 0.1730398
## 2 0.1730398 0.1730398 0.1730398 0.1730398 0.1730398
## 3 0.1730398 0.1730398 0.1730398 0.1730398
## 4 0.1730398 0.1730398 0.1730398
## 5 0.1730398 0.1730398
## 6 0.1730398
##
## Stratum:A To:C
## 1 2 3 4 5 6
## 1 0.5419813 0.5419813 0.5419813 0.5419813 0.5419813 0.5419813
## 2 0.5419813 0.5419813 0.5419813 0.5419813 0.5419813
## 3 0.5419813 0.5419813 0.5419813 0.5419813
## 4 0.5419813 0.5419813 0.5419813
## 5 0.5419813 0.5419813
## 6 0.5419813
##
## Stratum:B To:A
## 1 2 3 4 5 6
## 1 0.1045797 0.1045797 0.1045797 0.1045797 0.1045797 0.1045797
## 2 0.1045797 0.1045797 0.1045797 0.1045797 0.1045797
## 3 0.1045797 0.1045797 0.1045797 0.1045797
## 4 0.1045797 0.1045797 0.1045797
## 5 0.1045797 0.1045797
## 6 0.1045797
##
## Stratum:B To:C
## 1 2 3 4 5 6
## 1 0.5093753 0.5093753 0.5093753 0.5093753 0.5093753 0.5093753
## 2 0.5093753 0.5093753 0.5093753 0.5093753 0.5093753
## 3 0.5093753 0.5093753 0.5093753 0.5093753
## 4 0.5093753 0.5093753 0.5093753
## 5 0.5093753 0.5093753
## 6 0.5093753
##
## Stratum:C To:A
## 1 2 3 4 5 6
## 1 0.0457665 0.0457665 0.0457665 0.0457665 0.0457665 0.0457665
## 2 0.0457665 0.0457665 0.0457665 0.0457665 0.0457665
## 3 0.0457665 0.0457665 0.0457665 0.0457665
## 4 0.0457665 0.0457665 0.0457665
## 5 0.0457665 0.0457665
## 6 0.0457665
##
## Stratum:C To:B
## 1 2 3 4 5 6
## 1 0.144108 0.144108 0.144108 0.144108 0.144108 0.144108
## 2 0.144108 0.144108 0.144108 0.144108 0.144108
## 3 0.144108 0.144108 0.144108 0.144108
## 4 0.144108 0.144108 0.144108
## 5 0.144108 0.144108
## 6 0.144108
##
## S.stratum.p.dot.Psi.s
##
## Output summary for Multistrata model
## Name : S(~-1 + stratum)p(~1)Psi(~-1 + stratum:tostratum)
##
## Npar : 10
## -2lnL: 5892.768
## AICc : 5912.869
##
## Beta
## estimate se lcl ucl
## S:stratumA -0.4642516 0.1193060 -0.6980913 -0.2304119
## S:stratumB 0.7454683 0.1286044 0.4934037 0.9975329
## S:stratumC 2.0873483 0.1701348 1.7538841 2.4208125
## p:(Intercept) -0.3591727 0.0617317 -0.4801668 -0.2381785
## Psi:stratumB:tostratumA -1.2837971 0.2396377 -1.7534870 -0.8141072
## Psi:stratumC:tostratumA -2.7987912 0.1945105 -3.1800318 -2.4175506
## Psi:stratumA:tostratumB -0.5390295 0.3038562 -1.1345877 0.0565287
## Psi:stratumC:tostratumB -1.6991583 0.1160604 -1.9266366 -1.4716800
## Psi:stratumA:tostratumC 0.5313663 0.2253168 0.0897454 0.9729872
## Psi:stratumB:tostratumC 0.2513707 0.1492102 -0.0410812 0.5438227
##
##
## Real Parameter S
## Stratum:A
## 1 2 3 4 5 6
## 1 0.3859777 0.3859777 0.3859777 0.3859777 0.3859777 0.3859777
## 2 0.3859777 0.3859777 0.3859777 0.3859777 0.3859777
## 3 0.3859777 0.3859777 0.3859777 0.3859777
## 4 0.3859777 0.3859777 0.3859777
## 5 0.3859777 0.3859777
## 6 0.3859777
##
## Stratum:B
## 1 2 3 4 5 6
## 1 0.6781905 0.6781905 0.6781905 0.6781905 0.6781905 0.6781905
## 2 0.6781905 0.6781905 0.6781905 0.6781905 0.6781905
## 3 0.6781905 0.6781905 0.6781905 0.6781905
## 4 0.6781905 0.6781905 0.6781905
## 5 0.6781905 0.6781905
## 6 0.6781905
##
## Stratum:C
## 1 2 3 4 5 6
## 1 0.8896674 0.8896674 0.8896674 0.8896674 0.8896674 0.8896674
## 2 0.8896674 0.8896674 0.8896674 0.8896674 0.8896674
## 3 0.8896674 0.8896674 0.8896674 0.8896674
## 4 0.8896674 0.8896674 0.8896674
## 5 0.8896674 0.8896674
## 6 0.8896674
##
##
## Real Parameter p
## Stratum:A
## 2 3 4 5 6 7
## 1 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599
## 2 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599
## 3 0.4111599 0.4111599 0.4111599 0.4111599
## 4 0.4111599 0.4111599 0.4111599
## 5 0.4111599 0.4111599
## 6 0.4111599
##
## Stratum:B
## 2 3 4 5 6 7
## 1 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599
## 2 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599
## 3 0.4111599 0.4111599 0.4111599 0.4111599
## 4 0.4111599 0.4111599 0.4111599
## 5 0.4111599 0.4111599
## 6 0.4111599
##
## Stratum:C
## 2 3 4 5 6 7
## 1 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599
## 2 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599
## 3 0.4111599 0.4111599 0.4111599 0.4111599
## 4 0.4111599 0.4111599 0.4111599
## 5 0.4111599 0.4111599
## 6 0.4111599
##
##
## Real Parameter Psi
## Stratum:A To:B
## 1 2 3 4 5 6
## 1 0.1775923 0.1775923 0.1775923 0.1775923 0.1775923 0.1775923
## 2 0.1775923 0.1775923 0.1775923 0.1775923 0.1775923
## 3 0.1775923 0.1775923 0.1775923 0.1775923
## 4 0.1775923 0.1775923 0.1775923
## 5 0.1775923 0.1775923
## 6 0.1775923
##
## Stratum:A To:C
## 1 2 3 4 5 6
## 1 0.5179538 0.5179538 0.5179538 0.5179538 0.5179538 0.5179538
## 2 0.5179538 0.5179538 0.5179538 0.5179538 0.5179538
## 3 0.5179538 0.5179538 0.5179538 0.5179538
## 4 0.5179538 0.5179538 0.5179538
## 5 0.5179538 0.5179538
## 6 0.5179538
##
## Stratum:B To:A
## 1 2 3 4 5 6
## 1 0.1080797 0.1080797 0.1080797 0.1080797 0.1080797 0.1080797
## 2 0.1080797 0.1080797 0.1080797 0.1080797 0.1080797
## 3 0.1080797 0.1080797 0.1080797 0.1080797
## 4 0.1080797 0.1080797 0.1080797
## 5 0.1080797 0.1080797
## 6 0.1080797
##
## Stratum:B To:C
## 1 2 3 4 5 6
## 1 0.5017175 0.5017175 0.5017175 0.5017175 0.5017175 0.5017175
## 2 0.5017175 0.5017175 0.5017175 0.5017175 0.5017175
## 3 0.5017175 0.5017175 0.5017175 0.5017175
## 4 0.5017175 0.5017175 0.5017175
## 5 0.5017175 0.5017175
## 6 0.5017175
##
## Stratum:C To:A
## 1 2 3 4 5 6
## 1 0.0489528 0.0489528 0.0489528 0.0489528 0.0489528 0.0489528
## 2 0.0489528 0.0489528 0.0489528 0.0489528 0.0489528
## 3 0.0489528 0.0489528 0.0489528 0.0489528
## 4 0.0489528 0.0489528 0.0489528
## 5 0.0489528 0.0489528
## 6 0.0489528
##
## Stratum:C To:B
## 1 2 3 4 5 6
## 1 0.1470083 0.1470083 0.1470083 0.1470083 0.1470083 0.1470083
## 2 0.1470083 0.1470083 0.1470083 0.1470083 0.1470083
## 3 0.1470083 0.1470083 0.1470083 0.1470083
## 4 0.1470083 0.1470083 0.1470083
## 5 0.1470083 0.1470083
## 6 0.1470083
##
## S.dot.p.stratum.Psi.s
##
## Note: only 9 parameters counted of 10 specified parameters
## AICc and parameter count have been adjusted upward
##
## Output summary for Multistrata model
## Name : S(~1)p(~stratum)Psi(~-1 + stratum:tostratum)
##
## Npar : 10 (unadjusted=9)
## -2lnL: 5995.745
## AICc : 6015.847 (unadjusted=6013.8283)
##
## Beta
## estimate se lcl ucl
## S:(Intercept) 1.474684 0.1179889 1.2434255 1.705942
## p:(Intercept) -2.652245 0.1606817 -2.9671812 -2.337309
## p:stratumB 16.913796 606.7860600 -1172.3869000 1206.214500
## p:stratumC 2.497013 0.2068805 2.0915271 2.902499
## Psi:stratumB:tostratumA 1.315230 0.1613394 0.9990045 1.631455
## Psi:stratumC:tostratumA -1.770241 0.2333675 -2.2276409 -1.312840
## Psi:stratumA:tostratumB -3.191027 0.2311199 -3.6440221 -2.738032
## Psi:stratumC:tostratumB -2.365604 0.1195781 -2.5999768 -2.131231
## Psi:stratumA:tostratumC -1.383577 0.1771157 -1.7307237 -1.036430
## Psi:stratumB:tostratumC 1.016607 0.1661630 0.6909276 1.342286
##
##
## Real Parameter S
## Stratum:A
## 1 2 3 4 5 6
## 1 0.8137683 0.8137683 0.8137683 0.8137683 0.8137683 0.8137683
## 2 0.8137683 0.8137683 0.8137683 0.8137683 0.8137683
## 3 0.8137683 0.8137683 0.8137683 0.8137683
## 4 0.8137683 0.8137683 0.8137683
## 5 0.8137683 0.8137683
## 6 0.8137683
##
## Stratum:B
## 1 2 3 4 5 6
## 1 0.8137683 0.8137683 0.8137683 0.8137683 0.8137683 0.8137683
## 2 0.8137683 0.8137683 0.8137683 0.8137683 0.8137683
## 3 0.8137683 0.8137683 0.8137683 0.8137683
## 4 0.8137683 0.8137683 0.8137683
## 5 0.8137683 0.8137683
## 6 0.8137683
##
## Stratum:C
## 1 2 3 4 5 6
## 1 0.8137683 0.8137683 0.8137683 0.8137683 0.8137683 0.8137683
## 2 0.8137683 0.8137683 0.8137683 0.8137683 0.8137683
## 3 0.8137683 0.8137683 0.8137683 0.8137683
## 4 0.8137683 0.8137683 0.8137683
## 5 0.8137683 0.8137683
## 6 0.8137683
##
##
## Real Parameter p
## Stratum:A
## 2 3 4 5 6 7
## 1 0.0658508 0.0658508 0.0658508 0.0658508 0.0658508 0.0658508
## 2 0.0658508 0.0658508 0.0658508 0.0658508 0.0658508
## 3 0.0658508 0.0658508 0.0658508 0.0658508
## 4 0.0658508 0.0658508 0.0658508
## 5 0.0658508 0.0658508
## 6 0.0658508
##
## Stratum:B
## 2 3 4 5 6 7
## 1 0.9999994 0.9999994 0.9999994 0.9999994 0.9999994 0.9999994
## 2 0.9999994 0.9999994 0.9999994 0.9999994 0.9999994
## 3 0.9999994 0.9999994 0.9999994 0.9999994
## 4 0.9999994 0.9999994 0.9999994
## 5 0.9999994 0.9999994
## 6 0.9999994
##
## Stratum:C
## 2 3 4 5 6 7
## 1 0.4612697 0.4612697 0.4612697 0.4612697 0.4612697 0.4612697
## 2 0.4612697 0.4612697 0.4612697 0.4612697 0.4612697
## 3 0.4612697 0.4612697 0.4612697 0.4612697
## 4 0.4612697 0.4612697 0.4612697
## 5 0.4612697 0.4612697
## 6 0.4612697
##
##
## Real Parameter Psi
## Stratum:A To:B
## 1 2 3 4 5 6
## 1 0.0318387 0.0318387 0.0318387 0.0318387 0.0318387 0.0318387
## 2 0.0318387 0.0318387 0.0318387 0.0318387 0.0318387
## 3 0.0318387 0.0318387 0.0318387 0.0318387
## 4 0.0318387 0.0318387 0.0318387
## 5 0.0318387 0.0318387
## 6 0.0318387
##
## Stratum:A To:C
## 1 2 3 4 5 6
## 1 0.1940536 0.1940536 0.1940536 0.1940536 0.1940536 0.1940536
## 2 0.1940536 0.1940536 0.1940536 0.1940536 0.1940536
## 3 0.1940536 0.1940536 0.1940536 0.1940536
## 4 0.1940536 0.1940536 0.1940536
## 5 0.1940536 0.1940536
## 6 0.1940536
##
## Stratum:B To:A
## 1 2 3 4 5 6
## 1 0.4974501 0.4974501 0.4974501 0.4974501 0.4974501 0.4974501
## 2 0.4974501 0.4974501 0.4974501 0.4974501 0.4974501
## 3 0.4974501 0.4974501 0.4974501 0.4974501
## 4 0.4974501 0.4974501 0.4974501
## 5 0.4974501 0.4974501
## 6 0.4974501
##
## Stratum:B To:C
## 1 2 3 4 5 6
## 1 0.369028 0.369028 0.369028 0.369028 0.369028 0.369028
## 2 0.369028 0.369028 0.369028 0.369028 0.369028
## 3 0.369028 0.369028 0.369028 0.369028
## 4 0.369028 0.369028 0.369028
## 5 0.369028 0.369028
## 6 0.369028
##
## Stratum:C To:A
## 1 2 3 4 5 6
## 1 0.134705 0.134705 0.134705 0.134705 0.134705 0.134705
## 2 0.134705 0.134705 0.134705 0.134705 0.134705
## 3 0.134705 0.134705 0.134705 0.134705
## 4 0.134705 0.134705 0.134705
## 5 0.134705 0.134705
## 6 0.134705
##
## Stratum:C To:B
## 1 2 3 4 5 6
## 1 0.0742713 0.0742713 0.0742713 0.0742713 0.0742713 0.0742713
## 2 0.0742713 0.0742713 0.0742713 0.0742713 0.0742713
## 3 0.0742713 0.0742713 0.0742713 0.0742713
## 4 0.0742713 0.0742713 0.0742713
## 5 0.0742713 0.0742713
## 6 0.0742713
##
## S.stratum.p.stratum.Psi.s
##
## Output summary for Multistrata model
## Name : S(~-1 + stratum)p(~stratum)Psi(~-1 + stratum:tostratum)
##
## Npar : 12
## -2lnL: 5891.565
## AICc : 5915.709
##
## Beta
## estimate se lcl ucl
## S:stratumA -0.6542802 0.2199809 -1.0854427 -0.2231176
## S:stratumB 0.6171376 0.1631260 0.2974108 0.9368645
## S:stratumC 1.9723290 0.1779899 1.6234688 2.3211892
## p:(Intercept) 2.4058795 14.0707400 -25.1727710 29.9845300
## p:stratumB -2.6858063 14.2695360 -30.6540980 25.2824850
## p:stratumC -2.8361285 14.0803700 -30.4336540 24.7613970
## Psi:stratumB:tostratumA -2.0303744 1.2990084 -4.5764309 0.5156822
## Psi:stratumC:tostratumA -3.5467525 1.0995542 -5.7018788 -1.3916262
## Psi:stratumA:tostratumB 0.2310262 1.3867729 -2.4870487 2.9491010
## Psi:stratumC:tostratumB -1.7695390 0.2743942 -2.3073515 -1.2317264
## Psi:stratumA:tostratumC 1.3558860 1.2303641 -1.0556276 3.7673995
## Psi:stratumB:tostratumC 0.3331423 0.3321455 -0.3178630 0.9841475
##
##
## Real Parameter S
## Stratum:A
## 1 2 3 4 5 6
## 1 0.3420257 0.3420257 0.3420257 0.3420257 0.3420257 0.3420257
## 2 0.3420257 0.3420257 0.3420257 0.3420257 0.3420257
## 3 0.3420257 0.3420257 0.3420257 0.3420257
## 4 0.3420257 0.3420257 0.3420257
## 5 0.3420257 0.3420257
## 6 0.3420257
##
## Stratum:B
## 1 2 3 4 5 6
## 1 0.6495673 0.6495673 0.6495673 0.6495673 0.6495673 0.6495673
## 2 0.6495673 0.6495673 0.6495673 0.6495673 0.6495673
## 3 0.6495673 0.6495673 0.6495673 0.6495673
## 4 0.6495673 0.6495673 0.6495673
## 5 0.6495673 0.6495673
## 6 0.6495673
##
## Stratum:C
## 1 2 3 4 5 6
## 1 0.8778611 0.8778611 0.8778611 0.8778611 0.8778611 0.8778611
## 2 0.8778611 0.8778611 0.8778611 0.8778611 0.8778611
## 3 0.8778611 0.8778611 0.8778611 0.8778611
## 4 0.8778611 0.8778611 0.8778611
## 5 0.8778611 0.8778611
## 6 0.8778611
##
##
## Real Parameter p
## Stratum:A
## 2 3 4 5 6 7
## 1 0.9172745 0.9172745 0.9172745 0.9172745 0.9172745 0.9172745
## 2 0.9172745 0.9172745 0.9172745 0.9172745 0.9172745
## 3 0.9172745 0.9172745 0.9172745 0.9172745
## 4 0.9172745 0.9172745 0.9172745
## 5 0.9172745 0.9172745
## 6 0.9172745
##
## Stratum:B
## 2 3 4 5 6 7
## 1 0.4304717 0.4304717 0.4304717 0.4304717 0.4304717 0.4304717
## 2 0.4304717 0.4304717 0.4304717 0.4304717 0.4304717
## 3 0.4304717 0.4304717 0.4304717 0.4304717
## 4 0.4304717 0.4304717 0.4304717
## 5 0.4304717 0.4304717
## 6 0.4304717
##
## Stratum:C
## 2 3 4 5 6 7
## 1 0.3940669 0.3940669 0.3940669 0.3940669 0.3940669 0.3940669
## 2 0.3940669 0.3940669 0.3940669 0.3940669 0.3940669
## 3 0.3940669 0.3940669 0.3940669 0.3940669
## 4 0.3940669 0.3940669 0.3940669
## 5 0.3940669 0.3940669
## 6 0.3940669
##
##
## Real Parameter Psi
## Stratum:A To:B
## 1 2 3 4 5 6
## 1 0.2051912 0.2051912 0.2051912 0.2051912 0.2051912 0.2051912
## 2 0.2051912 0.2051912 0.2051912 0.2051912 0.2051912
## 3 0.2051912 0.2051912 0.2051912 0.2051912
## 4 0.2051912 0.2051912 0.2051912
## 5 0.2051912 0.2051912
## 6 0.2051912
##
## Stratum:A To:C
## 1 2 3 4 5 6
## 1 0.6319447 0.6319447 0.6319447 0.6319447 0.6319447 0.6319447
## 2 0.6319447 0.6319447 0.6319447 0.6319447 0.6319447
## 3 0.6319447 0.6319447 0.6319447 0.6319447
## 4 0.6319447 0.6319447 0.6319447
## 5 0.6319447 0.6319447
## 6 0.6319447
##
## Stratum:B To:A
## 1 2 3 4 5 6
## 1 0.051961 0.051961 0.051961 0.051961 0.051961 0.051961
## 2 0.051961 0.051961 0.051961 0.051961 0.051961
## 3 0.051961 0.051961 0.051961 0.051961
## 4 0.051961 0.051961 0.051961
## 5 0.051961 0.051961
## 6 0.051961
##
## Stratum:B To:C
## 1 2 3 4 5 6
## 1 0.5522552 0.5522552 0.5522552 0.5522552 0.5522552 0.5522552
## 2 0.5522552 0.5522552 0.5522552 0.5522552 0.5522552
## 3 0.5522552 0.5522552 0.5522552 0.5522552
## 4 0.5522552 0.5522552 0.5522552
## 5 0.5522552 0.5522552
## 6 0.5522552
##
## Stratum:C To:A
## 1 2 3 4 5 6
## 1 0.0240305 0.0240305 0.0240305 0.0240305 0.0240305 0.0240305
## 2 0.0240305 0.0240305 0.0240305 0.0240305 0.0240305
## 3 0.0240305 0.0240305 0.0240305 0.0240305
## 4 0.0240305 0.0240305 0.0240305
## 5 0.0240305 0.0240305
## 6 0.0240305
##
## Stratum:C To:B
## 1 2 3 4 5 6
## 1 0.1421008 0.1421008 0.1421008 0.1421008 0.1421008 0.1421008
## 2 0.1421008 0.1421008 0.1421008 0.1421008 0.1421008
## 3 0.1421008 0.1421008 0.1421008 0.1421008
## 4 0.1421008 0.1421008 0.1421008
## 5 0.1421008 0.1421008
## 6 0.1421008
Once the models are run, we can examine the model-selection table. We can also examine model-specific output.
options(width = 150)
ms.results
## model npar AICc DeltaAICc weight Deviance
## 3 S(~-1 + stratum)p(~1)Psi(~-1 + stratum:tostratum) 10 5912.869 0.00000 0.8053141 1031.471
## 4 S(~-1 + stratum)p(~stratum)Psi(~-1 + stratum:tostratum) 12 5915.709 2.83969 0.1946859 1030.268
## 2 S(~1)p(~stratum)Psi(~-1 + stratum:tostratum) 10 6015.847 102.97730 0.0000000 1134.448
## 1 S(~1)p(~1)Psi(~-1 + stratum:tostratum) 8 6102.592 189.72225 0.0000000 1225.228
names(ms.results)
## [1] "S.dot.p.dot.Psi.s" "S.dot.p.stratum.Psi.s" "S.stratum.p.dot.Psi.s" "S.stratum.p.stratum.Psi.s" "model.table"
# examine the output from top-ranked model (#3) and
# store top model in object with short name
top = ms.results$S.stratum.p.dot.Psi.s
# look at summary of top model's output
summary(top, showall = FALSE)
## Output summary for Multistrata model
## Name : S(~-1 + stratum)p(~1)Psi(~-1 + stratum:tostratum)
##
## Npar : 10
## -2lnL: 5892.768
## AICc : 5912.869
##
## Beta
## estimate se lcl ucl
## S:stratumA -0.4642516 0.1193060 -0.6980913 -0.2304119
## S:stratumB 0.7454683 0.1286044 0.4934037 0.9975329
## S:stratumC 2.0873483 0.1701348 1.7538841 2.4208125
## p:(Intercept) -0.3591727 0.0617317 -0.4801668 -0.2381785
## Psi:stratumB:tostratumA -1.2837971 0.2396377 -1.7534870 -0.8141072
## Psi:stratumC:tostratumA -2.7987912 0.1945105 -3.1800318 -2.4175506
## Psi:stratumA:tostratumB -0.5390295 0.3038562 -1.1345877 0.0565287
## Psi:stratumC:tostratumB -1.6991583 0.1160604 -1.9266366 -1.4716800
## Psi:stratumA:tostratumC 0.5313663 0.2253168 0.0897454 0.9729872
## Psi:stratumB:tostratumC 0.2513707 0.1492102 -0.0410812 0.5438227
##
##
## Real Parameter S
## Stratum:A
## 1 2 3 4 5 6
## 1 0.3859777 0.3859777 0.3859777 0.3859777 0.3859777 0.3859777
## 2 0.3859777 0.3859777 0.3859777 0.3859777 0.3859777
## 3 0.3859777 0.3859777 0.3859777 0.3859777
## 4 0.3859777 0.3859777 0.3859777
## 5 0.3859777 0.3859777
## 6 0.3859777
##
## Stratum:B
## 1 2 3 4 5 6
## 1 0.6781905 0.6781905 0.6781905 0.6781905 0.6781905 0.6781905
## 2 0.6781905 0.6781905 0.6781905 0.6781905 0.6781905
## 3 0.6781905 0.6781905 0.6781905 0.6781905
## 4 0.6781905 0.6781905 0.6781905
## 5 0.6781905 0.6781905
## 6 0.6781905
##
## Stratum:C
## 1 2 3 4 5 6
## 1 0.8896674 0.8896674 0.8896674 0.8896674 0.8896674 0.8896674
## 2 0.8896674 0.8896674 0.8896674 0.8896674 0.8896674
## 3 0.8896674 0.8896674 0.8896674 0.8896674
## 4 0.8896674 0.8896674 0.8896674
## 5 0.8896674 0.8896674
## 6 0.8896674
##
##
## Real Parameter p
## Stratum:A
## 2 3 4 5 6 7
## 1 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599
## 2 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599
## 3 0.4111599 0.4111599 0.4111599 0.4111599
## 4 0.4111599 0.4111599 0.4111599
## 5 0.4111599 0.4111599
## 6 0.4111599
##
## Stratum:B
## 2 3 4 5 6 7
## 1 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599
## 2 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599
## 3 0.4111599 0.4111599 0.4111599 0.4111599
## 4 0.4111599 0.4111599 0.4111599
## 5 0.4111599 0.4111599
## 6 0.4111599
##
## Stratum:C
## 2 3 4 5 6 7
## 1 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599
## 2 0.4111599 0.4111599 0.4111599 0.4111599 0.4111599
## 3 0.4111599 0.4111599 0.4111599 0.4111599
## 4 0.4111599 0.4111599 0.4111599
## 5 0.4111599 0.4111599
## 6 0.4111599
##
##
## Real Parameter Psi
## Stratum:A To:B
## 1 2 3 4 5 6
## 1 0.1775923 0.1775923 0.1775923 0.1775923 0.1775923 0.1775923
## 2 0.1775923 0.1775923 0.1775923 0.1775923 0.1775923
## 3 0.1775923 0.1775923 0.1775923 0.1775923
## 4 0.1775923 0.1775923 0.1775923
## 5 0.1775923 0.1775923
## 6 0.1775923
##
## Stratum:A To:C
## 1 2 3 4 5 6
## 1 0.5179538 0.5179538 0.5179538 0.5179538 0.5179538 0.5179538
## 2 0.5179538 0.5179538 0.5179538 0.5179538 0.5179538
## 3 0.5179538 0.5179538 0.5179538 0.5179538
## 4 0.5179538 0.5179538 0.5179538
## 5 0.5179538 0.5179538
## 6 0.5179538
##
## Stratum:B To:A
## 1 2 3 4 5 6
## 1 0.1080797 0.1080797 0.1080797 0.1080797 0.1080797 0.1080797
## 2 0.1080797 0.1080797 0.1080797 0.1080797 0.1080797
## 3 0.1080797 0.1080797 0.1080797 0.1080797
## 4 0.1080797 0.1080797 0.1080797
## 5 0.1080797 0.1080797
## 6 0.1080797
##
## Stratum:B To:C
## 1 2 3 4 5 6
## 1 0.5017175 0.5017175 0.5017175 0.5017175 0.5017175 0.5017175
## 2 0.5017175 0.5017175 0.5017175 0.5017175 0.5017175
## 3 0.5017175 0.5017175 0.5017175 0.5017175
## 4 0.5017175 0.5017175 0.5017175
## 5 0.5017175 0.5017175
## 6 0.5017175
##
## Stratum:C To:A
## 1 2 3 4 5 6
## 1 0.0489528 0.0489528 0.0489528 0.0489528 0.0489528 0.0489528
## 2 0.0489528 0.0489528 0.0489528 0.0489528 0.0489528
## 3 0.0489528 0.0489528 0.0489528 0.0489528
## 4 0.0489528 0.0489528 0.0489528
## 5 0.0489528 0.0489528
## 6 0.0489528
##
## Stratum:C To:B
## 1 2 3 4 5 6
## 1 0.1470083 0.1470083 0.1470083 0.1470083 0.1470083 0.1470083
## 2 0.1470083 0.1470083 0.1470083 0.1470083 0.1470083
## 3 0.1470083 0.1470083 0.1470083 0.1470083
## 4 0.1470083 0.1470083 0.1470083
## 5 0.1470083 0.1470083
## 6 0.1470083
# store and examine estimates of 'S' and 'p'
# First examine the first 5 rows of output
# to see how things are stored
head(top$results$real)
## estimate se lcl ucl fixed note
## S sA g1 c1 a0 o1 t1 0.3859777 0.0282754 0.3322355 0.4426505
## S sB g1 c1 a0 o1 t1 0.6781905 0.0280677 0.6209079 0.7305732
## S sC g1 c1 a0 o1 t1 0.8896674 0.0167003 0.8524420 0.9184007
## p sA g1 c1 a1 o1 t2 0.4111599 0.0149457 0.3822127 0.4407353
## Psi sA toB g1 c1 a0 o1 t1 0.1775923 0.0388522 0.1136354 0.2667141
## Psi sA toB g1 c1 a1 o2 t2 0.1775923 0.0388522 0.1136354 0.2667141
# for 'S' in top model there are 3 estimates
top.S = top$results$real[1:3, ]
top.S
## estimate se lcl ucl fixed note
## S sA g1 c1 a0 o1 t1 0.3859777 0.0282754 0.3322355 0.4426505
## S sB g1 c1 a0 o1 t1 0.6781905 0.0280677 0.6209079 0.7305732
## S sC g1 c1 a0 o1 t1 0.8896674 0.0167003 0.8524420 0.9184007
# for 'p' in top model there is 1 estimate
# and it's in the 4th row of output
top.p = top$results$real[4, ]
top.p
## estimate se lcl ucl fixed note
## p sA g1 c1 a1 o1 t2 0.4111599 0.0149457 0.3822127 0.4407353
# Store and examine the estimates of 'Psi'
Psilist = get.real(top, "Psi", vcv = TRUE)
Psi.values = Psilist$estimates
top.psi = TransitionMatrix(Psi.values[Psi.values$time == 1, ],
vcv.real = Psilist$vcv.real)
top.psi
## $TransitionMat
## A B C
## A 0.30445393 0.1775923 0.5179538
## B 0.10807975 0.3902028 0.5017175
## C 0.04895279 0.1470083 0.8040389
##
## $se.TransitionMat
## A B C
## A 0.045792166 0.03885222 0.04924723
## B 0.021542328 0.03418639 0.03478658
## C 0.009026569 0.01450754 0.01624228
##
## $lcl.TransitionMat
## A B C
## A 0.22269748 0.1136354 0.4219556
## B 0.07252654 0.3256205 0.4339237
## C 0.03400270 0.1207849 0.7702428
##
## $ucl.TransitionMat
## A B C
## A 0.40075036 0.2667141 0.6126447
## B 0.15809074 0.4588782 0.5694482
## C 0.06999972 0.1777740 0.8339355
To see how results of such modeling can be used, you worked out how numbers of animals in each habitat would change through time in each patch type if they were projected forward in time using the survival and transition rates you estimated. Here, we see how to use R to do the work.
# store the point estimates of 'S' and 'Psi'
phi.hat = matrix(top.S$estimate, 3, 1)
# for Psi, transpose before storing
# for ease of use in code below
psi.hat = t(top.psi$TransitionMat)
# set up a population with 1,000 animals in each patch type
N0 = matrix(c(1000, 1000, 1000), 3, 1)
# Subject animals to survival process
(N0.surv = N0 * phi.hat)
## [,1]
## [1,] 385.9777
## [2,] 678.1905
## [3,] 889.6674
# Move survivors according to transition matrix
# using matrix multiplication
(N1 = psi.hat %*% N0.surv)
## [,1]
## A 234.3628
## B 463.9670
## C 1255.5058
# Note: we can do survial & transition in 1 step instead
psi.hat %*% (N0 * phi.hat)
## [,1]
## A 234.3628
## B 463.9670
## C 1255.5058
# Repeat the process for years 2-5 using 1-step approach
N2 = psi.hat %*% (N1 * phi.hat)
N3 = psi.hat %*% (N2 * phi.hat)
N4 = psi.hat %*% (N3 * phi.hat)
N5 = psi.hat %*% (N4 * phi.hat)
# view output
N.t = cbind(N0, N1, N2, N3, N4, N5)
# calculate overall population size for each year
Pop.t = apply(N.t, 2, sum)
# view output
rbind(N.t, Pop.t)
## [,1] [,2] [,3] [,4] [,5] [,6]
## A 1000 234.3628 116.2281 83.90118 66.75387 54.23506
## B 1000 463.9670 303.0510 232.40022 186.95317 152.21134
## C 1000 1255.5058 1102.8203 915.22965 750.53855 613.83865
## Pop.t 3000 1953.8356 1522.0994 1231.53105 1004.24559 820.28505
# Calculate propotions in each patch over time
(ppn.patch = apply(N.t, 2, prop.table))
## [,1] [,2] [,3] [,4] [,5] [,6]
## A 0.3333333 0.1199501 0.0763604 0.06812754 0.06647166 0.06611733
## B 0.3333333 0.2374647 0.1991006 0.18870837 0.18616280 0.18555908
## C 0.3333333 0.6425852 0.7245390 0.74316409 0.74736554 0.74832359
# Calculate annual survival rate across patches
(yrly.surv = Pop.t[2:5] / Pop.t[1:4])
## [1] 0.6512785 0.7790315 0.8091003 0.8154448
# Note that this result matches what you get if you
# calculate the weighted mean of phi for each year
# across patches based on the numbers or ppn in
# each of the patches as shown for 2nd year below
(yr2.surv = weighted.mean(phi.hat, ppn.patch[, 2]))
## [1] 0.7790315