borealbirds / QPAD

Calibrating indices of avian density from non-standardized survey data
2 stars 2 forks source link

Problem with edr matrix.... #3

Open A-Drake opened 4 years ago

A-Drake commented 4 years ago

I'm experiencing an issue with the localBAMcorrections function in QPAD version 3. It seems to be related to incorporating LCC values into the detection probability (q). The error references "Xr" and occurs only when the edr model specified is >1. It does not occur for model.edr=2 in QPAD version 2.

Update: It seems to be a leveling issue within the LCC variable - either unrecognized categories or missing levels, I was still getting errors in version 2 for my own data until I added empty factor levels so that levels 1-5 were present; I'm still having issues in version 3...

For example, using the ovenbird data (with LCC and pforest derived as in the supplement of Solymos et al. 2013):

bm <- bestmodelBAMspecies("OVEN", type = "BIC") bc <- with(oven, localBAMcorrections("OVEN", t = dur, r = dist, jday = JDAY, tssr = TSSR, tree = pforest, lcc = LCC, model.sra = bm$sra, model.edr = bm$edr))

Error in Xr %*% coefBAMspecies(species, model.sra, model.edr)$edr : requires

numeric/complex matrix/vector arguments

psolymos commented 4 years ago

@A-Drake : the issue might be that some of the functions haven't been updated to v3 of the estimates where the land cover layer has changed from the Canadian to North American, along with the factor levels.

You can find and updated script that I am now working on here: https://github.com/ABbiodiversity/recurring/blob/master/offset/index.R

I will check the functions so that these at least give a reasonable error message.

northernbio commented 3 years ago

Hi Peter. I am having a similar issue as A-Drake. If I use the bestmodel (bm$edr), which for the oven dataset is EDR 3, I get the xR error, however if I explicitly set the EDR model to 0 or 1, the function works. Do I need to make changes to the oven data set to make it compatible to with the North American landcover? If so, is there a URL pointing to example data.

Error in Xr %*% coefBAMspecies(species, model.sra, model.edr)$edr : requires

numeric/complex matrix/vector arguments

#code snippets based on QPAD_SupportingInfo.pdf
QPAD::load_BAM_QPAD(version = 3)
bm <- bestmodelBAMspecies("OVEN", type = "BIC")
#With QPAD Version 3, only edr models 0 or 1 work.  
bc <- with(oven, localBAMcorrections("OVEN", r = dist, t = dur,
                jday = JDAY, tssr = TSSR, tree = pforest, lcc = LCC, model.sra = bm$sra,
                model.edr = 1))
psolymos commented 3 years ago

Can you please use do the following and report back here what R prints out?

northernbio commented 3 years ago

Hi Peter

I ran this code.

oven$LCC <- factor(5, levels = 1:5) # 5=OH open habitat

oven$LCC[pf > 0.25 & pc > pd] <- "3" # 3=SC dense conifer

oven$LCC[pf > 0.25 & pc <= pd] <- "4" # 4=SD sparse deciduous

oven$LCC[pf > 0.6 & pc > pd] <- "1" # 1=DC dense conifer

oven$LCC[pf > 0.6 & pc <= pd] <- "2" # 2=DC dense deciduous

table(oven$LCC)

1 2 3 4 5

66 225 25 175 400

traceback()

No traceback available

class(LCC); table(LCC)

Error: object 'LCC' not found

class(oven$LCC) [1] "factor"

Rob

From: Peter Solymos notifications@github.com Sent: Monday, December 21, 2020 3:57 PM To: psolymos/QPAD QPAD@noreply.github.com Cc: northernbio northernbio@gmail.com; Comment comment@noreply.github.com Subject: Re: [psolymos/QPAD] Problem with edr matrix.... (#3)

Can you please use do the following and report back here what R prints out?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/psolymos/QPAD/issues/3#issuecomment-749192308 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ASHJE3FT5ZQY4C6MJTK3QBDSV6ZDFANCNFSM4LD37CGQ . https://github.com/notifications/beacon/ASHJE3A57CCGRWEEPF3KV5TSV6ZDFA5CNFSM4LD37CG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFST4I5A.gif

psolymos commented 3 years ago

@A-Drake @northernbio : I looked at the example, and the problem is with the QPAD functions not quite supporting v3 of the estimates. I found the package's functionality quite restrictive in the sense that user needed to ensure that the correct spatial layers are used etc. This was troublesome, so I wrote some scripts that circumvent that.

See https://github.com/ABbiodiversity/recurring/blob/master/offset/README.md for worked example.

Hope this helps.

northernbio commented 3 years ago

This is very helpful!

From: Peter Solymos notifications@github.com Sent: Monday, January 4, 2021 12:54 PM To: psolymos/QPAD QPAD@noreply.github.com Cc: northernbio northernbio@gmail.com; Mention mention@noreply.github.com Subject: Re: [psolymos/QPAD] Problem with edr matrix.... (#3)

@A-Drake https://github.com/A-Drake @northernbio https://github.com/northernbio : I looked at the example, and the problem is with the QPAD functions not quite supporting v3 of the estimates. I found the package's functionality quite restrictive in the sense that user needed to ensure that the correct spatial layers are used etc. This was troublesome, so I wrote some scripts that circumvent that.

See https://github.com/ABbiodiversity/recurring/blob/master/offset/README.md for worked example.

Hope this helps.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/psolymos/QPAD/issues/3#issuecomment-754120963 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ASHJE3GWJQDI4O5SCXLJOM3SYH6DPANCNFSM4LD37CGQ . https://github.com/notifications/beacon/ASHJE3GUEP35GU2ORDUBAJDSYH6DPA5CNFSM4LD37CG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFTZPSAY.gif

northernbio commented 3 years ago

The example code worked for me, so I appreciate the scripts! A couple of questions: Are the example tif files (e.g. LCC.tif) in a Lambert projection, or are they Geographic (Lat/Long)? In QGIS it says undefined CRS, but the coordinate values seem to be Lambert.

Is it possible to mix raster resolutions? The 1 km^2 resolution for the LCC.tif seems a bit coarse, so I was wondering if a finer resolution landcover map (say 30 m) could be used instead. My study area is relatively small.

psolymos commented 3 years ago

@northernbio the lat/long is tranformed into Lambert conical (as the raster crs indicates).

You can use a different resolution but same projection and replace the raster, it should work. You can get the projection as PROJ4 string by proj4string(raster_name).

northernbio commented 3 years ago

Thanks Peter. When I use the new Canada’s Landcover, with 30 m cell size, I get no GDAL errors.

Canada's Land Cover | Natural Resources Canada (atlas.gc.ca) https://atlas.gc.ca/lcct/en/index.html

LCC <- raster ("./data/CAN_LC_2015_CAL.tif")

crs <- proj4string(LCC)

crs

"+proj=lcc +lat_0=49 +lon_0=-95 +lat_1=49 +lat_2=77 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs"

From: Peter Solymos notifications@github.com Sent: Tuesday, January 5, 2021 12:05 AM To: psolymos/QPAD QPAD@noreply.github.com Cc: northernbio northernbio@gmail.com; Mention mention@noreply.github.com Subject: Re: [psolymos/QPAD] Problem with edr matrix.... (#3)

@northernbio https://github.com/northernbio the lat/long is tranformed into Lamer conical (as the raster crs indicates).

You can use a different resolution but same projection and replace the raster, it should work. You can get the projection as PROJ4 string by proj4string(raster_name).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/psolymos/QPAD/issues/3#issuecomment-754398894 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ASHJE3CPF5WHKPRFOU6PFZLSYKMZPANCNFSM4LD37CGQ . https://github.com/notifications/beacon/ASHJE3CSKQE2YZBJHOKK523SYKMZPA5CNFSM4LD37CG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFT3TNLQ.gif