Occupancy model in RMark, Error in FUN(X[[1L]], ...)

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

Occupancy model in RMark, Error in FUN(X[[1L]], ...)

Postby pgriffin » Fri May 24, 2013 1:58 pm

I am a long-time MARK user, some-time R user, and am trying to learn RMark.
I am consistently getting an error ("Error in FUN(X[[1L]], ...) : invalid 'type' (character) of argument") when I try to run Occupancy model with RMark, but I have not seen any postings about this yet.
I recently updated my verisons of R (v. 3.0.0) and MARK (v. 7.0).

Here is example script that I have used leading up to the error. Can anyone, please, advise about what might be the source of this problem?
Thanks, very much! Paul Griffin


Code: Select all
# Script attempting to run simple Occupancy models for 2-occasions, single-season, single-place.
> library(RMark)
> PAO2009 <- import.chdata("PAO2009_Rmark_Trial_Data.txt", header = TRUE, use.comments = FALSE)
# Confirm that the ch looks good:
> PAO2009 [1:3,]
  ch freq Blowdown Light Effort
1 11    1       50     1      4
2 01    1       50     1      4
3 10    1        2     1      4
> PAO.2009.process=process.data(PAO2009, model="Occupancy")
> PAO.2009.ddl=make.design.data(PAO.2009.process)
# Designate simple model structure
> p.dot=list(formula=~1)
> Psi.dot=list(formula=~1)
# create a model
> model.p.dot.Psi.dot <- mark(PAO.2009.process, PAO.2009.ddl,model.parameters=list(p=p.dot, Psi=Psi.dot))
Error in FUN(X[[1L]], ...) : invalid 'type' (character) of argument
# What's the problem? I'm pretty sure that the capture histories are the right type:
> typeof(PAO2009$ch)
[1] "character"
# And all three covariates are integers, for example...
> typeof(PAO2009$Blowdown)
[1] "integer"
pgriffin
 
Posts: 3
Joined: Thu May 23, 2013 5:36 pm

Re: Occupancy model in RMark, Error in FUN(X[[1L]], ...)

Postby jlaake » Fri May 24, 2013 2:19 pm

Obviously I need to put in some data checks to avoid this one. It is better to use str(PAO2009). If you did that you would see

Code: Select all
> str(PAO2009)
'data.frame':   3 obs. of  5 variables:
 $ ch      : chr  "11" "01" "10"
 $ freq    : Factor w/ 1 level "1": 1 1 1
 $ Blowdown: Factor w/ 2 levels "2","50": 2 2 1
 $ Light   : Factor w/ 1 level "1": 1 1 1
 $ Effort  : Factor w/ 1 level "4": 1 1 1

Note that factor variables are integers

Code: Select all
> typeof(PAO2009$Blowdown)
[1] "integer"


What you want to do is as follows. You only specify the types of fields after ch.
Code: Select all
 
> PAO2009 <- import.chdata("ch.inp",field.type=rep("n",4))
>  str(PAO2009)
'data.frame':   3 obs. of  5 variables:
 $ ch      : chr  "11" "01" "10"
 $ freq    : num  1 1 1
 $ Blowdown: num  50 50 2
 $ Light   : num  1 1 1
 $ Effort  : num  4 4 4
> PAO.2009.process=process.data(PAO2009, model="Occupancy")
> PAO.2009.ddl=make.design.data(PAO.2009.process)
> p.dot=list(formula=~1)
> Psi.dot=list(formula=~1)
> model.p.dot.Psi.dot <- mark(PAO.2009.process, PAO.2009.ddl,model.parameters=list(p=p.dot, Psi=Psi.dot))
STOP NORMAL EXIT

Note: only  1  parameters counted of  2  specified parameters
AICc and parameter count have been adjusted upward

Output summary for Occupancy model
Name : p(~1)Psi(~1)

Npar :  2  (unadjusted=1)
-2lnL:  7.63817
AICc :  Inf  (unadjusted=13.63817)

Beta
                  estimate        se       lcl       ucl
p:(Intercept)    0.6931472 0.8660254 -1.004263  2.390557
Psi:(Intercept) 40.0489330 0.0000000 40.048933 40.048933


Real Parameter p
         1         2
 0.6666667 0.6666667


Real Parameter Psi
 1
 1



I can replicate the error by not specifying the fields as numeric:

Code: Select all
> PAO2009 <- import.chdata("ch.inp")
Warning message:
In readLines(inp.filename) : incomplete final line found on 'ch.inp'
> PAO.2009.process=process.data(PAO2009, model="Occupancy")
> PAO.2009.ddl=make.design.data(PAO.2009.process)
> model.p.dot.Psi.dot <- mark(PAO.2009.process, PAO.2009.ddl,model.parameters=list(p=p.dot, Psi=Psi.dot))
Error in FUN(X[[1L]], ...) : invalid 'type' (character) of argument

Enter a frame number, or 0 to exit   

1: mark(PAO.2009.process, PAO.2009.ddl, model.parameters = list(p = p.dot, Psi = Psi.dot))
2: mark.R#333: make.mark.model(data.proc, title = title, parameters = model.parameters, ddl = ddl, initial = initial, call = match.call(), default.fixed = default.fixed, model.name = model.name,
3: make.mark.model.R#1155: sapply(split(data$freq, pasted.data), sum)
4: lapply(X = X, FUN = FUN, ...)
jlaake
 
Posts: 1480
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Occupancy model in RMark, Error in FUN(X[[1L]], ...)

Postby pgriffin » Fri May 24, 2013 2:58 pm

Fantastic! Thank you so much for the help. It is ironic that an object that is an integer might not be numeric, but I should have remembered that from my early R readings. That model is running, and yielding the same results as I obtained in MARK. Yay!
pgriffin
 
Posts: 3
Joined: Thu May 23, 2013 5:36 pm


Return to RMark

Who is online

Users browsing this forum: No registered users and 0 guests