Nest survival error for factor variables- sort.list

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

Nest survival error for factor variables- sort.list

Postby gcbain » Mon Oct 29, 2018 8:35 pm

Hi All,

I'm new to RMark but have read the manual and have followed the Nest Survival example in Appendix C using the mallard data (which runs fine for me). I am testing for the effects of multiple habitat variables on DSR. Problem is when I include factors as covariates I have this error...

Code: Select all
Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?


The models run without error when I only use continuous variables. I've tried using dummy variables as in the mallard example as well as having a single column with the various levels of the factor but get the same error either way. My factors are the nesting "PlantType" with 5 levels and "Year" with 2 levels. My code and data structure (not using dummy variables) are below.

Apologies if the answer is obvious but any help would be much appreciated!

Code: Select all
run.markdata=function()
{
# 1. A model of constant daily survival rate (DSR) - Null Model
Dot=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~1)))
# 2. DSR varies by year
Year=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~Year)),groups=c("Year"))
# 3. DSR varies by nest height
Hght=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~Height)))
# 4. DSR varies by canopy closure
CanC=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~CanClosure)))
# 5. DSR varies by nest concealment
AVis=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~AvVis)))
# 6. DSR varies by density of cloud points below 1.5m
Dens=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~AvDen1.5)))
# 7. DSR varies by number of cloud points at nest height
PntH=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~PointNest)))
# 8. DSR varies by skew of cloud points
Skew=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~Skew)))
# 9. DSR varies by type of nesting plant
PTyp=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~PlantType)),groups=c("PlantType"))
return(collect.models() )
}
markdataresults=run.markdata()


Data Structure

Code: Select all
$ ID         : chr  "/*1*/" "/*11*/" "/*12*/" "/*15*/" ...
 $ FirstFound : num  24 26 26 34 56 60 64 85 85 85 ...
 $ LastPresent: num  50 46 47 60 58 65 89 102 97 92 ...
 $ LastChecked: num  50 46 47 60 58 65 89 102 97 92 ...
 $ Fate       : num  0 0 0 0 0 0 0 0 0 0 ...
 $ Freq       : num  1 1 1 1 1 1 1 1 1 1 ...
 $ Year       : Factor w/ 2 levels "0","1": 2 2 2 2 2 2 2 2 2 2 ...
 $ Height     : num  24 68 74 75 40 159 62 155 33 147 ...
 $ CanClosure : num  56.74 3.16 27.16 45.05 18.76 ...
 $ AvVis      : num  11.38 3.79 18.87 17.29 67.14 ...
 $ AvDen1.5   : num  14.7 12.8 12.5 13.1 12.7 ...
 $ PointNest  : num  215572 98003 503070 615239 293852 ...
 $ Skew       : num  2.26 1.38 1.63 2.02 1.77 ...
 $ PlantType  : Factor w/ 5 levels "Bra","Gor","Gra",..: 4 5 5 2 2 2 1 5 4 5 ...
Last edited by gcbain on Mon Oct 29, 2018 9:19 pm, edited 1 time in total.
gcbain
 
Posts: 3
Joined: Mon Oct 29, 2018 2:54 am

Re: Nest survival error for factor variables- sort.list

Postby jlaake » Mon Oct 29, 2018 9:08 pm

Model 9 as shown on phidot should work. Oddly that is not what shows in the version I got in the mail version which shows each factor level listed. The easiest way to handle factor variables is to use them in groups and then you can use same variable in the formula eg PlantType.
jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Nest survival error for factor variables- sort.list

Postby gcbain » Mon Oct 29, 2018 9:31 pm

Hi, yes I had initially uploaded the wrong code (back when things were dummy variables) so it had the factors levels listed separately. I've edited the post to correct that, sorry for the confusion.

I just tried to run it again, ignoring Year for now. The output shows estimates etc. for all models except for model 9. and I still get the same error at the end.

Code: Select all
run.markdata=function()
{
# 1. A model of constant daily survival rate (DSR) - Null Model
Dot=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~1)))
# 2. DSR varies by year
#Year=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~Year)),groups=c("Year"))
# 3. DSR varies by nest height
Hght=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~Height)))
# 4. DSR varies by canopy closure
CanC=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~CanClosure)))
# 5. DSR varies by nest concealment
AVis=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~AvVis)))
# 6. DSR varies by density of cloud points below 1.5m
Dens=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~AvDen1.5)))
# 7. DSR varies by number of cloud points at nest height
PntH=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~PointNest)))
# 8. DSR varies by skew of cloud points
Skew=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~Skew)))
# 9. DSR varies by type of nesting plant
PTyp=mark(markdata,nocc=156,model="Nest",model.parameters=list(S=list(formula=~PlantType)),groups=c("PlantType"))
return(collect.models() )
}
markdataresults=run.markdata()

STOP NORMAL EXIT

Output summary for Nest model
Name : S(~1)

Npar :  1
-2lnL:  278.7156
AICc :  280.7205

Beta
              estimate        se      lcl     ucl
S:(Intercept) 3.088232 0.1704989 2.754054 3.42241

# followed by output for other models then this...

Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?
gcbain
 
Posts: 3
Joined: Mon Oct 29, 2018 2:54 am

Re: Nest survival error for factor variables- sort.list

Postby jlaake » Tue Oct 30, 2018 8:36 am

Please run model 9 by itself and see what happens. I think the error is occurring in collect.models. Send further emails to me directly jefflaake@gmail.com. Once we work this out we can post the answer.
jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Nest survival error for factor variables- sort.list

Postby gcbain » Sat Nov 03, 2018 8:24 pm

UPDATE: This error appears to have been the result of how I imported my data file into R. I had initially used RStudio and then converted the relevant covariates to factors. After importing the same data using read.table, converting factors, and using the exact same code, all of the models ran without error. Not entirely sure why this was the case. I'm sure someone else will know though :D
gcbain
 
Posts: 3
Joined: Mon Oct 29, 2018 2:54 am


Return to RMark

Who is online

Users browsing this forum: Google [Bot] and 15 guests