carlopacioni / vortexR

an R package for post Vortex simulation analysis
8 stars 3 forks source link

Errors: arguments imply differing number of rows in pairwise #40

Open lachlanfrancis opened 5 years ago

lachlanfrancis commented 5 years ago

Hi. I am using your package for some PVA analyses from Vortex (version 10.2.17.0). I have completed tests on the Vortex sensitivity testing output analyses as per vignette which works perfectly. Now I'm testing between two management scenarios, using two different Vortex simulations. Data collates without issue, plots without issue, but when running pairwise function it comes up with an error:

> pairw.sp.pva <- pairwise(data=sp.pva, project="Species.PVA", scenario="PVA 'base-case'", params=c("Nall"), yrs=c(10,25,50), ST=FALSE, group.mean = TRUE, save2disk=FALSE)
Error in data.frame(..., check.names = FALSE) : 
  arguments imply differing number of rows: 2, 0

Do you have any ideas if I'm doing anything wrong (I'm new to Vortex and R)? I've attached the Output .dat files from Vortex, and copied in my R code and session information below. (.dat files renamed to .txt to allow attachment)

Species PVA_PVA 'management'.dat.txt Species PVA_PVA 'base-case'.dat.txt

/////PVA SCENARIO ANALYSIS/////
/////two separate simulations to investigate predator management actions, one without management, one with.
///////////////////////////////
sp.pva <- collate_dat("Species.PVA", 1000, scenario=NULL, dir_in = "C:/directory/VOutput", save2disk=TRUE, verbose=TRUE)
sp.pva[1:5, 1:5]

/// DATA VISUALISATION
// dot plot at selected years - Nall and Std Devs
plot.dot.sp.pva <- dot_plot(data=sp.pva, project="Species.PVA", scenario=NULL, yrs=c(10, 25, 50), params="Nall", save2disk=FALSE)
// line plot for mean population sizes over simulation
plot.lineplot.sp.pva <- line_plot_year(data=sp.pva, project="Species.PVA", scenario=NULL, params="Nall", save2disk=FALSE)

///// DATA ANALYSIS
pairw.sp.pva <- pairwise(data=sp.pva, project="Species.PVA", scenario="PVA 'base-case'", params=c("Nall"), yrs=c(10,25,50), ST=FALSE, group.mean = TRUE, save2disk=FALSE)

Here's my session information too.

R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252   
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] vortexR_1.1.5

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18       pillar_1.3.0       compiler_3.5.1     RColorBrewer_1.1-2
 [5] plyr_1.8.4         tools_3.5.1        digest_0.6.15      tibble_1.4.2      
 [9] gtable_0.2.0       lattice_0.20-35    rlang_0.2.1        glmulti_1.0.7     
[13] GGally_1.4.0       rJava_0.9-10       vortexRdata_1.0.3  irr_0.84          
[17] stringr_1.3.1      gtools_3.8.1       stats4_3.5.1       lmtest_0.9-36     
[21] grid_3.5.1         nnet_7.3-12        reshape_0.8.7      data.table_1.11.4 
[25] flexmix_2.3-14     Formula_1.2-3      ggplot2_3.0.0      reshape2_1.4.3    
[29] magrittr_1.5       scales_0.5.0       modeltools_0.2-22  lpSolve_5.6.13    
[33] colorspace_1.3-2   betareg_3.1-0      labeling_0.3       sandwich_2.4-0    
[37] stringi_1.1.7      lazyeval_0.2.1     munsell_0.5.0      crayon_1.3.4      
[41] zoo_1.8-3 
lachlanfrancis commented 5 years ago

I have revisited my code for the pairwise function today, and found that the quotation marks I enter in VORTEX simulation name are no longer in the scenario names after collation. That settles the above error, but brings a new error.

pairw.PVA.sp <- pairwise(data=PVA.sp, project="Species.PVA", scenario="PVA base-case", params="Nall", yrs=c(10,25,50), ST=FALSE, type = NA, group.mean = FALSE, SVs = NA, save2disk=FALSE)
Error in ratings.rank[, i] : incorrect number of dimensions

I have also checked over the help file and reviewed the arguments and believe they are all OK now. Is there anything you could suggest which may resolve this?

lachlanfrancis commented 5 years ago

Hi Carlo, I have managed to get the scenarios to run by duplicating my management scenario, so in total there are three scenarios (so pairwise has two and the base scenario). I figure the problem was not enough scenarios for pairwise. I'm not sure how many times there will only be two simulations being investigated, but I assume a new function would be required to just compare between two simulations (one and a base scenario)? Cheers.

carlopacioni commented 5 years ago

Hi Lachlanfrancis, thanks for the detailed report and for providing the test files. The reason why the pairwise function doesn't work in your case is because the function carries out a statistical test (Kendall test) for ranking consistency across raters. As you have correctly worked out, because you only have on scenario (in addition to the base scenario) there is nothing to rank and the statistical test fails. I agree that a more informative error message would helpful here, or even better, an internal check as to whether there is only one scenario, in which case the function skips that statistical test, could be desirable (for those users that are interested in obtaining CVs). I'll mark this as an enhancement for the successive versions.

Note that if you are only interested in SSMD, the function SSMD_matrix would work in your case:

SSDM.PVA.sp <- SSMD_matrix(data=sp.pva, project="Species.PVA", scenario="PVA base-case", 
                         params="Nall", yrs=c(10,25,50), ST=FALSE,  save2disk=FALSE)

Cheers, carlo