Robust Design with time varying individual covariates

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

Robust Design with time varying individual covariates

Postby Mmelot » Thu Mar 14, 2019 7:07 pm

Hello,

I am working on a research project on killerwhales. My data are based on a 10 year photo ID monitoring program, based on opportunistic observation from fisheries (non regular time interval). I have temporary migration and I am consequently using a Robust design. Unfortunatly I have some issues with the data formating of individual time varying covariates. I want to add my level of marking as a covariates for p because it is is changing depending of the year ( new scarf on the dorsal fin for example).
I added it to my database before processing it. I obtain this database with different Mk for each individuals by occasion (Mk1, Mk2,....Mk102) ,following the trap dependance individual covariates example.

Then I prepare my database FD
Code: Select all
time.intervals<-c(0,3,0,0,5,0,0,0,5,0,0,8,0,0,5,0,0,0,0,0,0,0,1,
                 0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,3,0,0,0,4,
                 0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,


M.proc<-process.data(FD,model="Robust", time.intervals=time.intervals)
design.p=list(time.varying=c("Mk"))
design.parameters=list(p=design.p)
M.ddl=make.design.data(M.proc,parameter=design.parameters)
p.effort2.ind<-list(formula=~Mk, share=TRUE)
model.2.ind=mark(M.proc,M.ddl, model = "Robust",
           time.intervals=time.intervals,
           design.parameters = design.parameters,
           model.parameters=list(S=list(formula=~1),
           GammaDoublePrime=list(formula=~1),
           p=p.effort2.ind),threads=2)

And I got this erros message:

Code: Select all
Error in make.mark.model(data.proc, title = title, parameters = model.parameters,  :
  The following individual covariates are not allowed because they are factor variables:  Mk1,Mk4,Mk9,Mk14,Mk22,Mk27,Mk28,Mk29,Mk32,Mk36,Mk37,Mk38,Mk39,Mk41,Mk43,Mk45
Error in mark(M.proc, M.ddl, model = "Robust", time.intervals = time.intervals,  :
  Misspecification of model or internal error in code


Indeed this number are used as session factors when I'm looking in M.design.
I was trying to change the indexation of Mk, but I didn't find any that is recognised when I run my model.
Code: Select all
Error in make.mark.model(data.proc, title = title, parameters = model.parameters,  :
 
Error: Variable Mk used in formula is not defined in data

Error in mark(M.proc, M.ddl, model = "Robust", time.intervals = time.intervals,  :
  Misspecification of model or internal error in code


Do you have any idea of how I label my covariates to be able to run it ?

Regards
Mmelot
 
Posts: 4
Joined: Thu Mar 14, 2019 6:28 pm

Re: Robust Design with time varying individual covariates

Postby jlaake » Mon Mar 18, 2019 11:48 am

A few things here.

Most importantly you should not be using individual covariates with MARK models that estimate abundance like the robust design because you don't know the covariate values for the unmarked individuals to estimate p for first capture. For models that condition on first capture like CJS you can use individual covariates because p is only modeled for subsequent recapture events.

I think you may be confusing syntax from my marked package when you use time.varying as an argument for the design. That is not an argument in RMark and is not in any of the help files(although I did find a stray comment in the code about time.varying even though it is not used in code).

If RMark reports the Mk values are factor variables the problem is when you read them into the data (FD). Try str(FD) to examine the values of your data. Regardless, not to be used with Robust model.

You made reference to M.design but I didn't see that in your code.

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

Re: Robust Design with time varying individual covariates

Postby cooch » Mon Mar 18, 2019 3:53 pm

jlaake wrote:A few things here.

Most importantly you should not be using individual covariates with MARK models that estimate abundance like the robust design because you don't know the covariate values for the unmarked individuals to estimate p for first capture.


Unless you're using the Huggins models, which condition only on encountered animals.
cooch
 
Posts: 1628
Joined: Thu May 15, 2003 4:11 pm
Location: Cornell University

Re: Robust Design with time varying individual covariates

Postby jlaake » Mon Mar 18, 2019 4:57 pm

Evan- Thanks for making this important clarification. My "robust design" should have been "Robust model" which is what they were using. They should be using the RDHuggins model or some variant.
jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Robust Design with time varying individual covariates

Postby Mmelot » Mon Mar 18, 2019 10:50 pm

Hello,

First of all thanks a lot for your answers.
Yes Indeed I need to use a RDHuggins. If I understood well, I have to make c varying depending of my level of markying, to consider this variable in the probability of resighting an individual which already has been observed at least once?

For the second thing,
I had a look in FD using str(FD) and got
Code: Select all
'data.frame':   169 obs. of  310 variables:
 $ ch        : chr  "0000010000001101010000011000011000011110000000000000000000000000000000000000000000000000000000000000000" "0000010000001101010000011001011000111110100100000010111010011001000110000110000010101011011100111101100" "0000010000001101010000011000010000011110000101000000101010110001000110000110011010101011001101001000000" "1000010000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" ...
 $ Mk1       : Factor w/ 3 levels "0","1","V9": 1 1 1 2 1 2 1 1 1 2 ...
 $ Mk2       : Factor w/ 3 levels "0","1","V11": 1 1 1 1 2 2 2 1 1 1 ...
 $ Mk3       : Factor w/ 3 levels "0","1","V14": 1 1 1 1 1 1 1 1 1 1 ...
 $ Mk4       : Factor w/ 3 levels "0","1","V19": 1 1 1 1 1 1 2 1 1 1 ...
 $ Mk5       : Factor w/ 3 levels "0","1","V21": 1 1 1 1 2 1 1 1 1 1 ...
 $ Mk6       : Factor w/ 3 levels "0","1","V26": 2 2 2 2 1 1 1 1 2 1 ...
 $ Mk7       : Factor w/ 3 levels "0","1","V29": 1 1 1 1 1 1 1 1 2 1 ...
 $ Mk8       : Factor w/ 3 levels "0","1","V30": 1 1 1 1 1 2 2 2 2 2 ...
 $ Mk9       : Factor w/ 3 levels "0","1","V32": 1 1 1 1 1 1 1 1 1 1 ...
 $ Mk10      : Factor w/ 3 levels "0","1","V37": 1 1 1 1 1 1 1 1 1 1 ...



So all my Mk look the same
Same after processing the data
Code: Select all
List of 17
 $ data            :'data.frame':   169 obs. of  311 variables:
  ..$ ch        : chr [1:169] "0000010000001101010000011000011000011110000000000000000000000000000000000000000000000000000000000000000" "0000010000001101010000011001011000111110100100000010111010011001000110000110000010101011011100111101100" "0000010000001101010000011000010000011110000101000000101010110001000110000110011010101011001101001000000" "1000010000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" ...
  ..$ Mk1       : Factor w/ 3 levels "0","1","V9": 1 1 1 2 1 2 1 1 1 2 ...
  ..$ Mk2       : Factor w/ 3 levels "0","1","V11": 1 1 1 1 2 2 2 1 1 1 ...
  ..$ Mk3       : Factor w/ 3 levels "0","1","V14": 1 1 1 1 1 1 1 1 1 1 ...
  ..$ Mk4       : Factor w/ 3 levels "0","1","V19": 1 1 1 1 1 1 2 1 1 1 ...
  ..$ Mk5       : Factor w/ 3 levels "0","1","V21": 1 1 1 1 2 1 1 1 1 1 ...


But when I ran my model the error is still the same and just concern very specific value of Mk
Code: Select all
M.proc<-process.data(FD,model="Robust", time.intervals=time.intervals)
M.ddl=make.design.data(M.proc)

model.1=mark(M.proc,M.ddl, model = "RDHuggins",
         time.intervals=time.intervals,
         model.parameters=list(S=list(formula=~1),
         GammaDoublePrime=list(formula=~1),
       p=p.effort1, c= list(formula=~Mk,share=TRUE)),threads=2)

Error in make.mark.model(data.proc, title = title, parameters = model.parameters,  :
  The following individual covariates are not allowed because they are factor variables:  Mk1,Mk4,Mk9,Mk14,Mk22,Mk27,Mk28,Mk29,Mk32,Mk36,Mk37,Mk38,Mk39,Mk41,Mk43,Mk45
Error in mark(M.proc, M.ddl, model = "RDHuggins", time.intervals = time.intervals,  :
  Misspecification of model or internal error in code


And when I'm looking in my M.ddl using str(M.ddl), the value problematic value of Mk correspond to the session factors.

Code: Select all
$ c               :'data.frame':   87 obs. of  9 variables:
  ..$ par.index  : int [1:87] 1 2 3 4 5 6 7 8 9 10 ...
  ..$ model.index: num [1:87] 449 450 451 452 453 454 455 456 457 458 ...
  ..$ group      : Factor w/ 1 level "1": 1 1 1 1 1 1 1 1 1 1 ...
  ..$ time       : Factor w/ 10 levels "2","3","4","5",..: 1 1 2 1 2 3 1 2 1 2 ...
  ..$ session    : Factor w/ 16 levels "1","4","9","14",..: 1 2 2 3 3 3 4 4 5 5 ...
  ..$ Time       : num [1:87] 0 0 1 0 1 2 0 1 0 1 ...
  ..$ c          : num [1:87] 1 1 1 1 1 1 1 1 1 1 ...
  ..$ effort1    : int [1:87] 223 23 23 2086 2086 2086 697 697 4508 4508 ...
  ..$ effort2    : int [1:87] 41 34 34 41 41 41 71 71 61 61 ...


Is this only due to the name of my Mk and how could I change it ?
Thank you again for your help.
Mmelot
 
Posts: 4
Joined: Thu Mar 14, 2019 6:28 pm

Re: Robust Design with time varying individual covariates

Postby jlaake » Wed Mar 20, 2019 1:14 pm

You are missing the point here. As the error states,

The following individual covariates are not allowed because they are factor variables:

Individual covariates MUST be numbers (numeric). Not V9 etc. You need to put your level of marking on a numeric scale.
jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Robust Design with time varying individual covariates

Postby Mmelot » Wed Mar 20, 2019 8:43 pm

Hello,

Sorry this were unused factors level. I delete them to be sure to have just integer.

Code: Select all
'data.frame':   169 obs. of  310 variables:
 $ ch        : chr  "0000010000001101010000011000011000011110000000000000000000000000000000000000000000000000000000000000000" "0000010000001101010000011001011000111110100100000010111010011001000110000110000010101011011100111101100" "0000010000001101010000011000010000011110000101000000101010110001000110000110011010101011001101001000000" "1000010000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" ...
 $ Mk1       : Factor w/ 4 levels "0","1","2","3": 3 1 4 4 3 4 3 1 4 3 ...
 $ Mk2       : Factor w/ 4 levels "0","1","2","3": 3 1 4 4 3 4 3 1 4 3 ...
 $ Mk3       : Factor w/ 4 levels "0","1","2","3": 3 1 4 4 3 4 3 1 4 3 ...
 $ Mk4       : Factor w/ 4 levels "0","1","2","3": 3 1 4 4 3 4 3 1 4 3 ...
 $ Mk5       : Factor w/ 4 levels "0","1","2","3": 3 1 4 4 3 4 3 1 4 3 ...
 $ Mk6       : Factor w/ 4 levels "0","1","2","3": 3 3 4 1 3 4 3 3 4 3 ...
 $ Mk7       : Factor w/ 4 levels "0","1","2","3": 3 3 4 1 3 4 3 3 4 3 ...
 $ Mk8       : Factor w/ 4 levels "0","1","2","3": 3 3 4 1 3 4 3 3 4 3 ...


typeof(FD$Mk1)
[1] "integer"


It doesn't change my error message which still only concerning this very specific values of Mk corresponding to my session factors

Code: Select all
M.proc<-process.data(FD,model="RDHuggins", time.intervals=time.intervals)
M.ddl=make.design.data(M.proc)
p.effort1<-list(formula=~time:session, share=TRUE)
c.1<-list(formula=~Mk,share=TRUE)

model.1=mark(M.proc,M.ddl, model = "RDHuggins",
+            time.intervals=time.intervals,
+            model.parameters=list(S=list(formula=~1),
+            GammaDoublePrime=list(formula=~1),
+            p=p.effort1, c=c.1),threads=2)
Error in make.mark.model(data.proc, title = title, parameters = model.parameters,  :
  The following individual covariates are not allowed because they are factor variables:  Mk1,Mk4,Mk9,Mk14,Mk22,Mk27,Mk28,Mk29,Mk32,Mk36,Mk37,Mk38,Mk39,Mk41,Mk43,Mk45
Error in mark(M.proc, M.ddl, model = "RDHuggins", time.intervals = time.intervals,  :
  Misspecification of model or internal error in code



Code: Select all
$ c               :'data.frame':   87 obs. of  9 variables:
  ..$ par.index  : int [1:87] 1 2 3 4 5 6 7 8 9 10 ...
  ..$ model.index: num [1:87] 449 450 451 452 453 454 455 456 457 458 ...
  ..$ group      : Factor w/ 1 level "1": 1 1 1 1 1 1 1 1 1 1 ...
  ..$ time       : Factor w/ 10 levels "2","3","4","5",..: 1 1 2 1 2 3 1 2 1 2 ...
  ..$ session    : Factor w/ 16 levels "1","4","9","14",..: 1 2 2 3 3 3 4 4 5 5 ...
  ..$ Time       : num [1:87] 0 0 1 0 1 2 0 1 0 1 ...
  ..$ c          : num [1:87] 1 1 1 1 1 1 1 1 1 1 ...
  ..$ effort1    : int [1:87] 223 23 23 2086 2086 2086 697 697 4508 4508 ...
  ..$ effort2    : int [1:87] 41 34 34 41 41 41 71 71 61 61 ...
Mmelot
 
Posts: 4
Joined: Thu Mar 14, 2019 6:28 pm

Re: Robust Design with time varying individual covariates

Postby jlaake » Wed Mar 20, 2019 10:58 pm

You have to change it to a numeric variable in R. See how it is still showing as a factor variable? Not sure how you are reading in your data. You need to get some help in R.
jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Robust Design with time varying individual covariates

Postby Mmelot » Thu Mar 21, 2019 2:22 am

My bad, thank you for you patience I just finally change it in the way you ware saying and it is, obviously, working.
Mmelot
 
Posts: 4
Joined: Thu Mar 14, 2019 6:28 pm


Return to RMark

Who is online

Users browsing this forum: No registered users and 9 guests