courtiol / IsoriX

This is the GitHub repository dedicated to the development of the R package IsoriX
12 stars 6 forks source link

check that datasets have more than one row #77

Closed courtiol closed 2 years ago

courtiol commented 6 years ago

Some users try to fit e.g. calibration based on a single observation. spaMM returns a silly message, so let's test these mistake straight in IsoriX before calling spaMM. Maybe we can also display some minimal information that are displayed at each function call explaining briefly what the function does...

courtiol commented 2 years ago

No longer seems to be a problem:

``` r
library(IsoriX)
#> Registered S3 methods overwritten by 'registry':
#>   method               from 
#>   print.registry_field proxy
#>   print.registry_entry proxy
#> 
#>  IsoriX version 0.8.2.9999 is now loaded!
#> 
#>  Type:
#> 
#>     * ?IsoriX
#>       for a very short description
#> 
#>     * help(package = 'IsoriX', help_type = 'html')
#>       for a list of the package objects and their help files
#> 
#>     * browseURL('https://bookdown.org/content/782/')
#>       for online tutorials & documentation
#> 
#>     * citation('IsoriX')
#>       for information on how to cite IsoriX (i.e. the papers you should read)
#> 
#>     * news(package = 'IsoriX')
#>       for info on what has changed between the different versions of IsoriX
#> 
#>  Please also consider joinging the mailing list / google group: 'https://groups.google.com/g/IsoriX' for help, news and discussions about IsoriX!
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

CalibDataAlien |>
  group_by(site_ID) |>
  slice(1) -> CalibDataAlienX

GNIPDataDEagg <- prepsources(data = GNIPDataDE)

GermanFit <- isofit(data = GNIPDataDEagg,
                    mean_model_fix = list(elev = TRUE, lat_abs = TRUE))
#> Warning: Expected Hessian matrix is used by default for GLM families with non-canonical link.
#>  Use spaMM.options(obsInfo=TRUE) to use observed Hessian globally in Laplace approximation or method=c("ML","obs") to use it on a specific fit. The default may well be reversed
#>  in a future version, so use method=c("ML","exp") to prevent any future change in results.

CalibAlienX <- calibfit(data = CalibDataAlienX, isofit = GermanFit)
#> Warning in .calc_logdisp_cov(object, dvdloglamMat = dvdloglamMat, dvdlogphiMat =
#> dvdlogphiMat, : phi dispVar component not yet available for phi model != ~1.
#> Note: extrapolation issues
#> Out of your 50 calibration samples,
#>  * 21 correspond to locations outside the area covered by the measurements you used to build your isoscape.
#>  * 2 are associated to predicted values more extreme than the ones present in the isoscape.
#> --> These cases correspond to extrapolation during the calibration step, which could imped the reliability of your assignments.
#> If the proportion of problematic samples is large, you should perhaps rethink the design of your isoscape and/or collect more callibration data within the expected range to avoid any problem.
CalibAlienX
#> 
#> Fixed effect estimates of the calibration fit 
#> sample_value = intercept + slope * mean_source_value + corrMatrix(1|site_ID) + slope^2 * (1|site_ID) + Error 
#> 
#>            intercept (+/- SE) = 1.92 +/- 2.59 
#>            slope     (+/- SE) = 0.48 +/- 0.04 
#> 
#> [for more information, use summary()]

Created on 2022-08-26 with reprex v2.0.2