Trouble with export.MARK with nest data

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

Trouble with export.MARK with nest data

Postby zugunruhe1 » Mon Mar 07, 2016 12:30 pm

Hello, I am running my nest survival data in RMark and am having some trouble when it comes to the "export.MARK" function. I am following the example in the mallard dataset, but get this error message when I try to export the data:
Error in export.MARK(modo.results$Age$data, "modoDSR", modo.results, replace = TRUE, :
$ is not a processed dataframemodo.results$Age is not a processed dataframedata is not a processed dataframe

I also tried exporting my models one at a time rather than after running them all within a function and got this message:
Error in export.MARK(modo.proc, "mo", list = c(Dot, vornest), replace = TRUE) :
unused argument (list = c(Dot, vornest))

The problem with the latter code may just be that I really don't get how to create a marklist for multiple models, even after reading the documentation a few times over (not new to R but new to RMark). I'm just going to go ahead and paste all my code since in some of the other postings I've found there's a recurring issue with not having enough info to address the problem.

Last but not least, I've been looking for examples of how to use the logistic-exposure link with nest survival data and can only find that it's possible, but not how to do it. Any help would be much appreciated and I apologize if this is a redundant question- I searched the forum but didn't find any directly relevant examples.

Code:
#Read in data
modor <- read.table(file=paste("C:/D", "modor", ".txt", sep=""), sep="\t", header=TRUE, na.strings=c("NA"))

# Make year a factor variable

modor$year <- factor(modor$year, labels=c("1","2"))

#Create function following example in RMark documentation
run.modor=function()
{

#Constant survival model
Dot=mark(modor, nocc=119, model="Nest",
model.parameters=list(S=list(formula=~1)))

#DSR as function of VOR at nest
vornest=mark(modor, nocc=119, model="Nest",
model.parameters=list(S=list(formula=~vornest)))

#DSR varies with nest age
age=mark(modor, nocc=119, model="Nest",
model.parameters=list(S=list(formula=~Age)))

#DSR varies with distance to two-track
ttdist=mark(modor, nocc=119, model="Nest",
model.parameters=list(S=list(formula=~ttdist)))

#DSR varies with distance to solar facility
sfdist=mark(modor, nocc=119, model="Nest",
model.parameters=list(S=list(formula=~sfdist)))

#DSR varies with VOR at nest & grass cover
vorgrass=mark(modor, nocc=119, model="Nest",
model.parameters=list(S=list(formula=~vornest+grass)))

#DSR varies with distance to solar facility and age
sfdistage=mark(modor, nocc=119, model="Nest",
model.parameters=list(S=list(formula=~sfdist+Age)))

#DSR varies with distance to major road and age
mrdistage=mark(modor, nocc=119, model="Nest",
model.parameters=list(S=list(formula=~mrdist+Age)))

#DSR varies with distance to two-track & forb cover
ttdistforb=mark(modor, nocc=119, model="Nest",
model.parameters=list(S=list(formula=~ttdist+forb)))

#DSR varies with distance to two track, VOR at nest, & distance to major road
ttdistvornestmrdist=mark(modor, nocc=119, model="Nest",
model.parameters=list(S=list(formula=~mrdist+ttdist+vornest)))

#DSR varies with nest age and year
ageyear=mark(modor,nocc=119, model="Nest", model.parameters=list(S=list(formula=~Age+year)), groups=c("year"))
#Only gives parameter estimates for 2nd year.

#DSR varies with nest age and distance to solar facility
sfdistyear=mark(modor,nocc=119, model="Nest", model.parameters=list(S=list(formula=~sfdist+year)), groups=c("year"))

#DSR varies with distance to solar facility, nest age, and year
sfdistageyear=mark(modor,nocc=119, model="Nest", model.parameters=list(S=list(formula=~sfdist+Age+year)), groups=c("year"))

#DSR varies with distance to solar facility, nest age, VOR at nest, and year
sfdistageyearvor=mark(modor,nocc=119, model="Nest", model.parameters=list(S=list(formula=~sfdist+Age+year+vornest)), groups=c("year"))

#DSR varies with the interaction between nest age and forb cover
ageforb=mark(modor, nocc=119, model="Nest",
model.parameters=list(S=list(formula=~forb+Age+forb*Age)))

return(collect.models() )
}
modo.results=run.modor()

#Try exporting model results based on example in “mallard”
export.MARK(modo.results$Age$data,"modoDSR",modo.results,replace=TRUE,ind.covariates="all")

#Error message:
#Error in export.MARK(modo.results$Age$data, "modoDSR", modo.results, replace = TRUE, :
# $ is not a processed dataframemodo.results$Age is not a processed dataframedata is not a #processed dataframe

#Try to export data following example in export.MARK page
Dot=mark(modor, nocc=119, model="Nest", model.parameters=list(S=list(formula=~1))) modo.proc=process.data(modor,nocc=119,model="Nest")
vornest=mark(modor, nocc=119, model="Nest",
model.parameters=list(S=list(formula=~vornest)))

export.MARK(modo.proc,"mo",list=c(Dot,vornest), replace=TRUE)

#Error message:
#Error in export.MARK(modo.proc, "mo", list = c(Dot, vornest), replace = TRUE) :
# unused argument (list = c(Dot, vornest))
zugunruhe1
 
Posts: 25
Joined: Wed Sep 30, 2015 8:04 pm

Re: Trouble with export.MARK with nest data

Postby jlaake » Mon Mar 07, 2016 1:52 pm

As explained in the help, collect.models returns a marklist which is a list with a specific structure with each model object and then a model.table object. Use ?str to see the structure of the result. str(modo.results) or names(modo.results)

Remember that R is case specific. I think you want $age rather than $Age. The function mark.wrapper can also be used to create a marklist.

Someone that is familiar with nest survival data will have to respond your query about the logistic-exposure link.
jlaake
 
Posts: 1479
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Trouble with export.MARK with nest data

Postby zugunruhe1 » Wed Mar 09, 2016 10:40 pm

Thank you so much! I was thinking the element after $ referenced the variable within my data frame, not the model name, which I see now doesn't make sense. Changing that worked.

I have one more question- I am now trying to get model-averaged estimates of daily survival rates for each encounter occasion for each year. I have 119 encounter occasions for each year, and when I do the model averaging following the RMark documentation, I get a nice table of survival estimates for every nest age in the time period I was studying- however, these estimates only seem to cover one year (for group 1). Any ideas how I would get estimates for each year?

This is my code for the model averaging (with modo.results.3 the object produced by run.modo(r) in my first post):
mavg=model.average(modo.results.3,"S",vcv=TRUE)
zugunruhe1
 
Posts: 25
Joined: Wed Sep 30, 2015 8:04 pm

Re: Trouble with export.MARK with nest data

Postby jlaake » Thu Mar 10, 2016 11:04 am

You have used different grouping structures in your models which you don't want to do if you are going to model average. In most of the models you haven't defined groups but you have in a few. If you have used the MARK interface then you know that when you use groups the set of PIMs changes and the PIMs should remain the same if you are going to model average and get meaningful results. You need to spend more time with the documentation and the way the mallard example was written is unfortunate. The best way to use RMark is to use process.data, then make.design.data and then call mark or mark.wrapper with the processed data and the design data list. Had you done that you wouldn't have had the last problem because you would have had the processed data list in an object for use with export.MARK. You can call mark with the data frame and then each time it calls process.data and make.design.data so it is inefficient and really this was only done to allow for simple examples. I'll have to add a check to model.average to make sure all of the models have the same PIM structure. Below is an example of what you code could look like with the more efficient approach. I don't have the data so I couldn't test it, so potentially the code below contains typos.

Code: Select all
modor.dp=process.data(modor,nocc=119, model="Nest",groups=c("year"))
modor.ddl=make.design.data(modor.dp)
run.modor=function()
{

#Constant survival model
S.1=list(formula=~1)
#DSR as function of VOR at nest
S.2=list(formula=~vornest)
#DSR varies with nest age
S.3=list(formula=~Age)
#DSR varies with distance to two-track
S.4=list(formula=~ttdist)
#DSR varies with distance to solar facility
S.5=list(formula=~sfdist)
#DSR varies with VOR at nest & grass cover
S.6=list(formula=~vornest+grass)
#DSR varies with distance to solar facility and age
S.7=list(formula=~sfdist+Age)
#DSR varies with distance to major road and age
S.8=list(formula=~mrdist+Age)
#DSR varies with distance to two-track & forb cover
S.9=list(formula=~ttdist+forb)
#DSR varies with distance to two track, VOR at nest, & distance to major road
S.10=list(formula=~mrdist+ttdist+vornest)
#DSR varies with nest age and year
S.11=list(formula=~Age+year)
#DSR varies with nest age and distance to solar facility
S.12=list(formula=~sfdist+year)

#DSR varies with distance to solar facility, nest age, and year
S.13=list(formula=~sfdist+Age+year)
#DSR varies with distance to solar facility, nest age, VOR at nest, and year
S.14=list(formula=~sfdist+Age+year+vornest)
#DSR varies with the interaction between nest age and forb cover
S.15=list(formula=~forb+Age+forb*Age)
cml=create.model.list("Nest")
return(mark.wrapper(cml,data=modor.dp,ddl=modor.ddl) )
}
modo.results=run.modor()
export.MARK(modo.dp,"mo",modo.results, replace=TRUE)
mavg=model.average(modo.results,"S",vcv=TRUE)
jlaake
 
Posts: 1479
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 1 guest