Pandora-IsoMemo / DSSM

Pandora & IsoMemo spatiotemporal modeling (DSSM)
https://pandora-isomemo.github.io/DSSM/
GNU General Public License v3.0
4 stars 1 forks source link

URGENT: Error in TimeR when a Mask is used #207

Closed CarloCocozza closed 3 months ago

CarloCocozza commented 3 months ago

Filtered North American Humans - 18 Apr 2024 CC.xlsx 2024-04-25_22-48-52_model_TimeR.zip

For the attached dataset and model, I receive the following error when I select year -2200 once a mask is applied. Error Mask

@arunge please give priority to this since we have many projects going on using TimeR with quite strict deadlines! We don't know if this issue, whenever this is a bug, may impact other estimates.

arunge commented 3 months ago

@CarloCocozza Did you really used the settings that you provided me with the zip file?

When just testing this online on beta, the plot was build without errors. However, I saved the model output (you only provided input data in your zip). I will test different settings next week and look if I can reproduce errors.

image

Locally, the model is still calculating since an hour. My laptop is slower than the server...

CarloCocozza commented 3 months ago

Hi Antonia,

Thank you for your quick reply. I think I have saved the right options, but I will also copypaste them below. The issue only appears with the year -2200, it seems. I was also using the local version and it took around one hour and half to run. I have tried this in different occasions and I was also trying with the online version. However, the online version actually crashes during or soon after modelling in my case. Perhaps this is more server related.

Did you also receive the "Simple warning..." Error when the model was built? Issue #199

Dependent variable: delta.13C.coll Dependent variable type: numeric Uncertainty (optional of dep. var.: delta.13C.coll.unc Date type: Interval Mean or lower time point: Curated Min. Age 95 Standard deviation or upper time point:: Curated Max. Age 95 Longitude variable: Longitude Latitude variable: Latitude Site/ID (optional): Site.name Smooth type: planar Number of basic functions: 300 Extrapolation behavior: Constant Bayesian model Distribution of date uncertainty: Uniform (full width) Number of MCMC iterations: 10000 Number of burnin iterations: 1500 Number of MCMC chains: 1 MCMC thinning (keep every x-th sample): 10 Amount of smoothing: 1

Map Centering: 0th meridian Estimation type: Mean Selected “Show model estimates” Range of colour scale Max range: -5 Min range: -24 Range restriction: No restriction Terrestrial Unselected “Show locations on map” Unselected “Show map grid” Selected “Show map scale” Selected “Show north arrow” Selected “Show plot title” Selected “Show colour scale” title Selected “Set axis labels” Main title- Y-axis- Latitude X-axis- Longitude Colour scale title- δ¹³C (‰ - VPDB) Selected “Set north arrow and scale size and position” Size of north arrow: 0.2 Size scale: 0.1 Scale x orientation: 0 Scale y orientation: 0.1 North arrow x orientation: 0.14 North arrow y orientation: 0.2 Location mark size: 1 Selected “Apply convex hull” Selected “Mask/Show output within range of points”

Display up to max standard error: 22 Colour palette: Pink-Yellow-Green Unselected “Reverse colors” Approximate number of colour levels: 20 Unselected “Smooth color transition” Plot resolution (px): 300 Coordinates for map placement: 55, -132, zoom 70

arunge commented 3 months ago

with the year -2200, it seems.

Ok, thanks! This is an important information. I will check that point in time. However, today I am quite busy. So, I will continue on Monday with this issue.

Thanks for your patience!

arunge commented 3 months ago

I got the warning, also:

image

Chatgpt explains the warning as follows. Maybe this helps to understand the problem. We could think of adding some new user inputs for controlling the model. I could check the code for possible new parameters if this is required.

The warning message "simpleWarning in smooth.construct.ds.smooth.spec(object, dk$data, dk$knots): s value modified to give continuous function" you're seeing in R typically comes from using smoothing functions, such as those found in the gam package for Generalized Additive Models (GAMs), or other similar statistical modeling functions that involve smoothing splines. This warning is related to the smoothing parameter s used in these models.

Understanding the Warning:

  1. Background: In smoothing techniques like splines used in GAMs and other regression models, the s parameter controls the smoothness of the spline fit. It essentially governs the trade-off between the smoothness of the fit and fidelity to the data points—higher values lead to smoother curves that may underfit the data, while lower values can lead to a wiggly curve that overfits the data.

  2. Cause of the Warning: The warning message indicates that the smoothing parameter s you specified (or was automatically chosen by the model) was adjusted internally by the algorithm to ensure the resulting spline is a continuous function. This adjustment is typically made to avoid numerical problems or impractical fits, such as attempting to fit a spline that is too wiggly (overfitting) or too smooth (underfitting) beyond the adaptive capacity of the model framework.

  3. Implication: The model's fitting process has modified the smoothing parameter to avoid an overfitting or underfitting problem, ensuring that the resulting model is stable and meaningful.

Dealing with the Warning:

Here are some approaches to handle or respond to this warning:

  • Understanding Model Output: First, check if the model's output is reasonable despite the warning. If the model performance and diagnostics (like residuals, fitted values) look good, the warning may not be critical.

  • Adjust Smoothing Parameter: If you have direct control over the smoothing parameter s (like in gam() or loess()), try adjusting its value. If you set it too high or too low, consider finding a more balanced value based on model diagnostics or using cross-validation techniques.

  • Use Automatic Selection: If available, use methods or options in the function that allow for automatic selection of the smoothing parameter. For example, method = "REML" or method = "GCV.Cp" in the gam() function from the mgcv package, which use restricted maximum likelihood or generalized cross-validation to estimate an optimal s.

  • Increase Flexibility: If the model is overly adjusting s because of limited flexibility (due to few knots in spline models, for example), increase the number of knots or the basis dimension to give the model more flexibility to fit the data without needing to over-correct s.

  • Consult Documentation and Vignettes: Different functions and packages have their own nuances in handling smoothing parameters. It’s often beneficial to look at the specific documentation for guidelines on setting or controlling these parameters effectively.

By exploring these options, you can better understand and control how the smoothing parameter influences your model's fit and adjust accordingly to mitigate warnings and improve model performance.

arunge commented 3 months ago

@CarloCocozza The issue from above is fixed with version 24.04.0 on the beta app. Feel free to test different settings. I am also pushing the fix to the main app, where the new version will be available soon. I am closing here.