Page 1 of 1

Coding TSM models in RMark...

PostPosted: Mon Jun 01, 2015 7:00 pm
by aber_r16
I was able to recreate the model I had constructed via MARK (both with the PIMS and DM) in R by adding a TSM column to the design data (1 for 1st age group of each cohort, 0 for second age group) - remember I'm trying to model a simple population (no sex, no age) with transience.


Code to add column

CODE: SELECT ALL
hist1.ddl$Phi$tsm=0
hist1.ddl$Phi$tsm[hist1.ddl$Phi$age==0]=1


This additional column allowed me to run

Phi(2m-tt)p(t)

CODE: SELECT ALL
Phi.timeXtsm<-list(formula=~tsm*time)

#Fully time dependant TSM model
m2<-mark(hist1.proc,
hist1.ddl,
model="CJS",
model.name="Phi(2m-tt)p(t)",
model.parameters=list(Phi=Phi.timeXtsm,
p=p.time))


Phi(2m-**)p(t)

CODE: SELECT ALL
m3<-mark(hist1.proc,
hist1.ddl,
model="CJS",
model.name="Phi(2m-**)p(t)",
model.parameters=list(Phi=Phi.tsm,
p=p.time))


What I can not figure out is how to run

Phi(2m-t*)p(t) or Phi(2m-*t)

I feel I understand the linear model way of thinking with the full model being

P(2m-tt)
Phi-BInt+BTSM+Bt1+Bt2+Bt3+Bt4+BTSM*t2+BTSM*t3+BTSM*t4+error

P(2m-**)
Phi=BInt+BTSM+error

But what is the formula for the models with time varying Phi in only one of the two age groups?

Thanks! R


Since this is now an RMark question, I'll ask that you copy the last part of this thread, and start a new on in the RMark sub-forum.
egc
Site Admin

Posts: 154
Joined: Thu May 15, 2003 11:25 am

Re: Coding TSM models in RMark...

PostPosted: Tue Jun 02, 2015 12:49 pm
by jlaake
There are lots of ways to limit the time variation to a single age group, but one way is to define tsm=1 for the age in which you want time variation and 0 otherwise. Then use ~tsm:time. The intercept is the constant value where tsm=0 and tsm:time creates time variation where tsm=1.

If you are reading this and new to RMark, please read the newly posted workshop notes. They contain about 8 pages describing formulas and model.matrix which creates the DM. The colon operator specifies an interaction. An interaction of a factor and a numeric variable is a product of sorts. Since tsm is 0 or 1 then the factor variable time will be limited to tsm=1 because it is zeroed out where tsm=0.

Hope this helps. The best way to improve your understanding of formulas and design matrices, is to create a small dataframe with factor and numeric variables and explore the various formula operators.

regards --jeff