dsouthwell / SPOTR

2 stars 1 forks source link

Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double' #1

Open vanmieva opened 1 year ago

vanmieva commented 1 year ago

Hello!

I am working through the SPOTR demo script "SPATIAL POWER ANALYSIS FOR DETECTION OCCUPANCY TRENDS IN R (SPOTR)" and have run into as issue on line 282:

xy.sites <- select.sites(sites, n.sites, R, all.loaded.sites, load.sites, new.site.selection, plot.sites) #Define monitoring sites Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double'

I've checked all input arguments objects in the function using isS4() but all outputs are FALSE. I've also tired uninstalling and reinstalling the package with no avail. There doesn't seem to be any useful forums on this type of error either.

Any help you can provide would be greatly appreciated!

vanmieva commented 1 year ago

Update: I was able to get line 282 to run by editing the select.sites() function and simply replacing plot() with raster::plot(). It appears to have worked as I received this output plot: image

However, now I've run into an issue running lines 317-358.

pwr <- foreach(i = 1:n.cores,.combine='+',.packages=c("SPOTR"))%do%{ #Run the power analysis. Set %dopar% to run in parallel, %do% otherwise. sapply(effect.size, run.power, nsims=nsims, alpha=alpha, Tmax=Tmax, s.years=s.years, trend=trend, sites=sites, model.disturbance=model.disturbance, disturbance.type=disturbance.type, species.list=species.list, dist.occ.time=dist.occ.time, dist.occ.freq=dist.occ.freq, park.level=park.level, xy.sites=xy.sites, R=R, two.tailed=two.tailed, plot.sites=plot.sites, n.sites=n.sites, n.species=n.species, n.park=n.park, all.loaded.sites=all.loaded.sites, load.sites=load.sites, new.site.selection=new.site.selection, occ.time=occ.time, det.method1.time=det.method1.time, det.method2.time=det.method2.time, det.method3.time=det.method3.time, det.method4.time=det.method4.time, n.method=n.method, occ=occ, det.method1=det.method1, det.method2=det.method2, det.method3=det.method3, det.method4=det.method4, stratify=stratify, remote=remote, parks=parks, Pr.dist=Pr.dist, disturbance=disturbance) }

This throws the following error:

Error in { : task 1 failed - "Lapack routine dgesv: system is exactly singular: U[1,1] = 0" In addition: There were 31 warnings (use warnings() to see them)

I'm not sure if this is continuing issue from my modification of select.sites() or an unrelated error?

Again, any help is great appreciated! :)

francisvolh commented 1 month ago

Hi @vanmieva , did you ever figure out how to get the package to work? I see there has been no changes for 6 years, and the package still uses raster (which now has been superseded by terra). So, I wonder if the package is still functional! thanks for any comments about it!

vanmieva commented 1 month ago

Hi @francisvolh, unfortunately I did not get the package to work. I ended up changing tactics. Sorry I couldn't be of more help!

francisvolh commented 1 month ago

Thanks for the quick response @vanmieva, I see. I will try to contact the developer and find out more about the package and do some runs myself. Just out of curiosity, which tactic did you end up using, another package or method? any references! If its not restricted I will be happy to learn about it! Cheers!

vanmieva commented 1 month ago

No worries, @francisvolh. I hope that the developers get back to you with helpful info. I ended up going the GLMM model route and conducting a Bayesian sensitivity analysis following the suggestions by Kruschke & Liddell 2017 " The Bayesian New Statistics: Hypothesis testing, estimation, meta-analysis, and power analysis from a Bayesian perspective". I didn't use a specific package, instead I simply simulated 100s of datasets, fit models to them, and determined sensitivity for various sampling scenarios from summarized outputs. Hope this helps!

francisvolh commented 1 month ago

Hello @vanmieva! I sent you an email to your ualberta address, not sure if you still check it, and also on linkedin (sorry for the spam!).

I found your code for the sensitivity analysis on your github but I had some questions about the overall method and would be happy to discuss my ideas with you on spatially explicit power analysis! and I am also at McGill! woohoo! You could email me to francis.vanoordtlahoz@mail.mcgill.ca if you would like to chat a bit about this, but I understand you may be very busy! Thanks!