s-jSDM icon indicating copy to clipboard operation
s-jSDM copied to clipboard

How to handle negative values ​​in internalStructure() results

Open KaiFeng-HUN opened this issue 8 months ago • 4 comments

Dear sjSDM developers,

I appreciate your work on sjSDM, and I have two questions regarding the internalStructure() function and ternary plot rendering:

  1. Dealing with Negative R² in internalStructure() In the User Guide, it is mentioned:

"Note the comments in ?internalStructure, especially about how to deal with negative values."

However, I could not find any recommendations in ?internalStructure. I would like to understand:

What causes negative R² values in internalStructure() results?

How should we handle them? Should sites or species with negative values be removed?

I noticed that in Pichler et al., 2025 and Cai et al., 2025, the R²-distinctiveness figures seem to lack negative R² values. Similarly, no negative values appear in the ternary plot of Cai et al., 2025. Were sites/species with negative R² values filtered out in these studies?

  1. Ternary Plot Rendering Issue When using plot.sjSDMinternalStructure(), I found that points located on the edges of the ternary plot are partially cut off. However, in Cai et al., 2025, edge points are fully displayed. I understand that ggtern is used for plotting, but could you provide specific guidance on how to ensure all edge points are fully visible?

Any insights would be greatly appreciated!

Best regards, Kai

Cai et al., 2025 https://doi.org/10.1111/ecog.07461 Pichler et al., 2025 https://doi.org/10.1111/mec.17733

KaiFeng-HUN avatar Apr 03 '25 13:04 KaiFeng-HUN

In general, the core issues regarding negative R² values can be summarized as follows: 1.What are the underlying reasons for negative R² values in internalStructure() results? 2.How did Pichler et al. (2025) and Cai et al. (2025) handle negative R² values? Were they manually removed, or was there another adjustment? 3.What is the recommended approach to deal with these negative values? Should they be removed, or is there a better way to interpret them?

KaiFeng-HUN avatar Apr 03 '25 13:04 KaiFeng-HUN

I understand that the total R² (fourth column) is not simply the sum of env, spa, and codist, and that these two types of R² are conceptually different. However, I have two specific questions regarding the handling of negative R² values:

1.Handling negative env, spa, and codist values: In the R²-distinctiveness plot from Pichler et al., 2025 and the ternary plot from Cai et al., 2025, there do not seem to be any negative R² values for these three components. Did they use the negatives = "floor" option in plot.sjSDMinternalStructure() or plotAssemblyEffects() to set negative values to zero? Or was another approach taken?

2.Handling negative total R² (fourth column): I noticed that in Cai et al., 2025, the ternary plot does not display any negative total R² values (i.e., no red-colored points). Does this mean that negative total R² values were filtered out before visualization, or was there another adjustment applied?

I would greatly appreciate any insights on best practices for handling these negative values!

KaiFeng-HUN avatar Apr 03 '25 14:04 KaiFeng-HUN

Hi @KaiFeng-HUN,

1. Negative R2 An individual R2 can occur when certain predictions are worse than predictions from an intercept-only model (which is most likely the result of an observation being an outlier or a strong misfit for a particular observation (which again can have different reasons)). Here's a simple demonstration using an lm:

set.seed(42)
X = runif(100, -1, 1)
Y = X[1:99] + rnorm(99, sd = 0.3)
X[100] = -0.5 # Outlier
Y = c(Y, 1.0)

m = lm(Y~X)
lls = dnorm( Y , cbind(1, X) %*% coef(m), sd =  sd(m$residuals), log = TRUE )
nulls = dnorm( Y , mean(Y), sd =  sd(Y - mean(Y)), log = TRUE )

SSE = (Y - cbind(1, X) %*% coef(m))**2
SS0 = (Y - mean(Y))**2

hist ( 1/100-  (( (SSE)/sum(SS0))))

Shared R2 fractions can be also negative, however, because of different reasons (some people call it suppression), you can read it here https://esajournals.onlinelibrary.wiley.com/doi/full/10.1890/0012-9658%282006%2987%5B2614%3AVPOSDM%5D2.0.CO%3B2

2. How to handle R2 The problem is that we can't visualise negative R2 in the tenary plots (values need to be in [0, inf[ for the tenary plots to work, we've tried a few things but haven't been able to solve this problem yet. In the two papers you mentioned, we used the previous version of sjSDM where the "floor" option was still the default (for all plots, ternary and plotAssembly), but we decided that in the future the "raw" option should be the default, at least for the plotAssemblyEffects(). So for the ternary it is floor (raw is technically not possible) and for the plotAssembly plot it should be raw.

MaximilianPi avatar Apr 03 '25 14:04 MaximilianPi

Dear Maximilian Pichler @MaximilianPi,

Thank you very much for your detailed response. I now have a better understanding of the issue regarding negative R² values for env, spa, and codist, and the way they are handled in the both kind of plots. I greatly appreciate your clarification on that.

I do have one more question regarding the negative values for total R² (the value in the fourth column). In the ternary plot in Cai et al., 2025, I noticed that there are no negative total R² values (as indicated by the color of the points), and no points are marked in red. I was wondering whether this could be because the absolute values of R² were used to represent point size, or if there were no occurrences of negative total R² values in the data itself.

However, in both the sjSDM package example data and my own data, negative total R² values do appear. Given this, what do you recommend as the most appropriate way to handle such cases? Specifically, in the ternary plot, should we display the negative values and provide an explanation of their potential meaning, as you mentioned in your previous response? Or should we just represent the values using their absolute values to show point size

Thank you again for your insights, and I look forward to your advice on this matter.

Best regards, Kai

KaiFeng-HUN avatar Apr 03 '25 15:04 KaiFeng-HUN