Issues running occupancy analysis in unmarked

Hi Community,
I'm running into some weird results and a warning: "In sqrt(diag(vcov(obj))) : NaNs produced" when I try running code for occupancy analysis in unmarked. I'm just starting to learn to use R & unmarked.

My supervisor thought it could be a 'convergence issue' to try providing 'starting values', what does this mean & how do I do it? She advised looking online for help.

Here is the code I was trying to run (none of the errors shown in the reprex come up when I run the code only the warning message what does this mean?:

#Make this a new object
dets_cats_aw <- dat_cats_aw[,-1]
#> Error in eval(expr, envir, enclos): object 'dat_cats_aw' not found

#Check it
dets_cats_aw
#> Error in eval(expr, envir, enclos): object 'dets_cats_aw' not found

#Put data into 'unmarkedframe object' form UFO
UFO_cats_aw <- unmarkedFrameOccu(y = dets_cats_aw)
#> Error in unmarkedFrameOccu(y = dets_cats_aw): could not find function "unmarkedFrameOccu"

#Print summary
summary(UFO_cats_aw)
#> Error in summary(UFO_cats_aw): object 'UFO_cats_aw' not found

#Build Occupancy Frame with Covariates

CTTable <- read.csv("CTTable_test1.csv")
#> Warning in file(file, "rt"): cannot open file 'CTTable_test1.csv': No such file
#> or directory
#> Error in file(file, "rt"): cannot open the connection

View("CTTable_test.csv")
str(CTTable)
#> Error in str(CTTable): object 'CTTable' not found
head(CTTable)
#> Error in head(CTTable): object 'CTTable' not found

cov_test <- as.data.frame(CTTable$veg_group2)
#> Error in as.data.frame(CTTable$veg_group2): object 'CTTable' not found
names(cov_test) <- "veg_group2"
#> Error in names(cov_test) <- "veg_group2": object 'cov_test' not found
cov_test
#> Error in eval(expr, envir, enclos): object 'cov_test' not found

UFO1 <- unmarkedFrameOccu(y = dets_cats_aw, siteCovs = cov_test)
#> Error in unmarkedFrameOccu(y = dets_cats_aw, siteCovs = cov_test): could not find function "unmarkedFrameOccu"
summary(UFO1)
#> Error in summary(UFO1): object 'UFO1' not found
UFO1        
#> Error in eval(expr, envir, enclos): object 'UFO1' not found

#Run models
#Model 1 simplest model constant det & occ
#doesn't vary with any covariate

m1 <- occu(~1~1, data = UFO1)
#> Error in occu(~1 ~ 1, data = UFO1): could not find function "occu"
m1
#> Error in eval(expr, envir, enclos): object 'm1' not found

Created on 2020-01-29 by the reprex package (v0.3.0)

Apologies for the ugly code I'm having trouble making a reprex as well, everything in R is just so complicated & not user-friendly!

Thankyou
Mary

1 Like

Hi, and welcome!

R is not so much unfriendly as it is foreign. As you learn the language, you'll discover that it can be richly expressive, and make things easier to do than they might be in other languages.

On the reprex errors: a reprex has to contain a complete R script down to where the error in your console shows up. That means library() and something to use for the data. It doesn't have to be all of your data. If there is a built-in data.set available from the package you are using, or better yet, iris, mtcars or one of the other packages shown by data(), that's fine if it exhibits the same behavior

If you do want to share your data, you can cut-and-paste the output of

dput(my_data)

which will look like

dput(mtcars)
#> structure(list(mpg = c(21, 21, 22.8, 21.4, 18.7, 18.1, 14.3, 
#> 24.4, 22.8, 19.2, 17.8, 16.4, 17.3, 15.2, 10.4, 10.4, 14.7, 32.4, 
#> 30.4, 33.9, 21.5, 15.5, 15.2, 13.3, 19.2, 27.3, 26, 30.4, 15.8, 
#> 19.7, 15, 21.4), cyl = c(6, 6, 4, 6, 8, 6, 8, 4, 4, 6, 6, 8, 
#> 8, 8, 8, 8, 8, 4, 4, 4, 4, 8, 8, 8, 8, 4, 4, 4, 8, 6, 8, 4), 
#>     disp = c(160, 160, 108, 258, 360, 225, 360, 146.7, 140.8, 
#>     167.6, 167.6, 275.8, 275.8, 275.8, 472, 460, 440, 78.7, 75.7, 
#>     71.1, 120.1, 318, 304, 350, 400, 79, 120.3, 95.1, 351, 145, 
#>     301, 121), hp = c(110, 110, 93, 110, 175, 105, 245, 62, 95, 
#>     123, 123, 180, 180, 180, 205, 215, 230, 66, 52, 65, 97, 150, 
#>     150, 245, 175, 66, 91, 113, 264, 175, 335, 109), drat = c(3.9, 
#>     3.9, 3.85, 3.08, 3.15, 2.76, 3.21, 3.69, 3.92, 3.92, 3.92, 
#>     3.07, 3.07, 3.07, 2.93, 3, 3.23, 4.08, 4.93, 4.22, 3.7, 2.76, 
#>     3.15, 3.73, 3.08, 4.08, 4.43, 3.77, 4.22, 3.62, 3.54, 4.11
#>     ), wt = c(2.62, 2.875, 2.32, 3.215, 3.44, 3.46, 3.57, 3.19, 
#>     3.15, 3.44, 3.44, 4.07, 3.73, 3.78, 5.25, 5.424, 5.345, 2.2, 
#>     1.615, 1.835, 2.465, 3.52, 3.435, 3.84, 3.845, 1.935, 2.14, 
#>     1.513, 3.17, 2.77, 3.57, 2.78), qsec = c(16.46, 17.02, 18.61, 
#>     19.44, 17.02, 20.22, 15.84, 20, 22.9, 18.3, 18.9, 17.4, 17.6, 
#>     18, 17.98, 17.82, 17.42, 19.47, 18.52, 19.9, 20.01, 16.87, 
#>     17.3, 15.41, 17.05, 18.9, 16.7, 16.9, 14.5, 15.5, 14.6, 18.6
#>     ), vs = c(0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 
#>     0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1), am = c(1, 
#>     1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 
#>     0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1), gear = c(4, 4, 4, 3, 
#>     3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 
#>     3, 3, 4, 5, 5, 5, 5, 5, 4), carb = c(4, 4, 1, 1, 2, 1, 4, 
#>     2, 2, 4, 4, 3, 3, 3, 4, 4, 4, 1, 2, 1, 1, 2, 2, 4, 2, 1, 
#>     2, 2, 4, 6, 8, 2)), row.names = c("Mazda RX4", "Mazda RX4 Wag", 
#> "Datsun 710", "Hornet 4 Drive", "Hornet Sportabout", "Valiant", 
#> "Duster 360", "Merc 240D", "Merc 230", "Merc 280", "Merc 280C", 
#> "Merc 450SE", "Merc 450SL", "Merc 450SLC", "Cadillac Fleetwood", 
#> "Lincoln Continental", "Chrysler Imperial", "Fiat 128", "Honda Civic", 
#> "Toyota Corolla", "Toyota Corona", "Dodge Challenger", "AMC Javelin", 
#> "Camaro Z28", "Pontiac Firebird", "Fiat X1-9", "Porsche 914-2", 
#> "Lotus Europa", "Ford Pantera L", "Ferrari Dino", "Maserati Bora", 
#> "Volvo 142E"), class = "data.frame")

Created on 2020-01-28 by the reprex package (v0.3.0)

Are any of the unmarked datasets, such as bird able to stand in for CCTable if that's where the error comes up? The NaNs error indicates that some calculation that was involved resulted in *Not a Number, so a dput` of your data might be needed.

Just tried dput() on my data and pasted a portion of the result below, it looks very strange instead of "0"s & "1"s they all have 'L' next to them? What does that mean?

dput(dat_cats_aw)
structure(list(X = structure(1:42, .Label = c("EB01", "EB02",
"EB03", "EB04", "EB06", "EB07", "EB08", "EB09", "EB10", "EB11",
"EB12", "EB13", "EB14", "EB15", "EB16", "EB17", "EB18", "EB19",
"EB20", "EB21", "EB22", "EB23", "EB24", "EB25", "EB26", "EB27",
"EB28", "EB29", "EB30", "EB31", "EB32", "EB33", "WB09", "WB10",
"WB11", "WB12", "WB14", "WB15", "WB16", "WB24", "WB27", "WB28"
), class = "factor"), o1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L), o2 = c(0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), o3 = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), o4 = c(0L, 0L, 0L, 0L, 0L,

1 Like

The L just signifies an object of class integer, which probably makes no difference and could be fixed with as.numeric' even if it did.

What strikes me though is the lonely 1L swimming in a sea of 0Ls. If the error derived from a function taking this data as an argument and involved anything other than addition, subtraction and multiplication, it’s not at all surprising to see NaNs.

1 Like

Occupancy models are based on recursive visits to locations and record the presence of a given species (or multiple species).
As 0 means not recorded and 1 mean recorded, t is not rare to have rows full of 0 or with just one 1 in between many 0's

Hi Fernando,

Yes I don't think it's the lack of '1s' causing the problem. I've run the code for 3 different species in my dataset and get the "NaN" warning for 2 of them - the example given above for cats which had a naive occupancy of 50% & foxes which was 90% (so lots of 1's but same NaN warning). When I ran it for rabbits which had a naive occupancy of only 23% (lots more "0s" than the cats) it ran fine with no warnings or errors.

Very strange.

Are you sure all are 0 or 1?
I cannot think of any other issue with the info you have provided...
Have you tried alternatives like RMark or jags trough rjags?
Cheers

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.