Error in rowSums: 'x' must be numeric

5,534 views
Skip to first unread message

Hugh Robinson

unread,
Nov 21, 2013, 4:20:25 PM11/21/13
to unma...@googlegroups.com
Hi,

I'm trying to run a relatively simple single season occupancy model using occu but get an  "Error in rowSums(y, na.rm = TRUE) : 'x' must be numeric".  My unmarkedFrame seems to be entering properly, summary(x) provides the following.

168 sites
Maximum number of observations per site: 76
Mean number of observations per site: 13.54
Sites with at least one detection: 32

Tabulation of y observations:
    0     1  <NA>
 2195    79 10494

I have a very unbalanced sample design, and I've included several unsurveyed sites in which I would like to predict occupancy based on covariates. 
Could the abundance of NA values in my data be causing the row Sum error?

Thanks,
HR

Jeffrey Royle

unread,
Nov 21, 2013, 4:29:14 PM11/21/13
to unma...@googlegroups.com
hi Hugh,
 To test that out, delete the all-NA observations and see what happens, I'm guessing yes.
 You shouldn't need to carry around those missing records in the fitting stage of the analysis (but predict() will work on whatever input covariate values you provide).
regards
andy
 


--
You received this message because you are subscribed to the Google Groups "unmarked" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hugh Robinson

unread,
Dec 2, 2013, 11:34:40 AM12/2/13
to unma...@googlegroups.com
Thanks Andy,
This also worked.  Ran before creating my unmarkedFrameOccu file, and where detect is the name of my detection history data frame.
detect<-apply(detect, 2, function(x){as.numeric(as.character(x))})

HR

Brian Leo

unread,
Apr 17, 2017, 8:23:46 PM4/17/17
to unmarked
Hi Andy,

I get the same error when trying to run an occupancy model.  I am trying to practice, and have downloaded the data from MacKenzie et al 2002.  I am trying to run the occupancy models for the american toad.  There are many "-" or NA values in the dataset.  When I run the summary of my unmarkedFrameOccu where "data" is the dataframe of occupancy data and habitat is a site covariate vector.

umf <- unmarkedFrameOccu(y = data, siteCovs = data.frame(habitat = habitat))
summary(umf)

28 sites
Maximum number of observations per site: 82 
Mean number of observations per site: 82 
Sites with at least one detection: 10 

Tabulation of y observations:
   -    0    1 <NA> 
2044  221   31    0 

Site-level covariates:
       X1        
 Min.   :0.0000  
 1st Qu.:0.0000  
 Median :0.0000  
 Mean   :0.2857  
 3rd Qu.:1.0000  
 Max.   :1.0000 

When I delete the NAs, as was suggested for Hugh's problem, I get the error when I try to create the unmarkedFrameOccu:

Error in validObject(.Object) : 
  invalid class “unmarkedFrame” object: siteCovData does not have same size number of sites as y.

What is the proper way of handling NAs?

Thanks,

Brian

Ian Jenkins

unread,
Apr 17, 2020, 8:44:36 AM4/17/20
to unmarked
Thank you!! This worked for me. RStudio 'research methods II' 

April 2020
To unsubscribe from this group and stop receiving emails from it, send an email to unma...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages