I would like to quantitatively describe the relationship between the two variables shown in this plot, but I am not sure what would be the correct way to do so. More specifically, my aim would be to assess whether there is a relationship between both variables and to quantify the strength of such a relationship (e.g. quantifying the amount of V2 variance explained by V1 with the coefficient of determination R2 or any other suitable statistic)

scatter plot

I have tentatively used the GAM model available in the geom_smooth function of ggplot (method="gam",formula = y ~ s(x, bs = "cs") and I have reproduced the same model with the gam package (see code and output below). However, I am not sure if this would be enough to claim that there is a relevant relationship between V1 and V2 and, if so, what would be the crucial statistics that I should report to substantiate such a possible conclusion. On the other hand, I have calculated the Spearman correlation trying to assess the relationship at the ordinal level (rho=0.480, p= 7.221e-08).

Thanks in advance for any help/ advice


v=gam(V1~s(V2),bs="cs", data=ff)

Call: gam(formula = V1 ~ s(V2), data = ff, bs = "cs")
Deviance Residuals:
     Min       1Q   Median       3Q      Max 
-3.36459 -0.31432 -0.14645  0.09815  7.18685 

(Dispersion Parameter for gaussian family taken to be 1.7516)

    Null Deviance: 377.6946 on 115 degrees of freedom
Residual Deviance: 194.4251 on 111.0001 degrees of freedom
AIC: 401.1024 

Number of Local Scoring Iterations: 2 

Anova for Parametric Effects
           Df  Sum Sq Mean Sq F value    Pr(>F)    
s(V2)       1  71.352  71.352  40.736 4.159e-09 ***
Residuals 111 194.425   1.752                      
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Anova for Nonparametric Effects
            Npar Df Npar F     Pr(F)    
s(V2)             3 21.299 5.709e-11 ***
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

############# ############ EDIT:

Following the advices received I have transformed V1 using log (both proposed transformations produced virtually identical results). Then, I have estimated the relationship through linear regression. However, the obtained fit does not seem to be much better... enter image description here

  • $\begingroup$ How do you want to use the quantitative description of the relationship between the two variables? Please edit the question to add that information, as comments are easily overlooked and can even be lost. $\endgroup$
    – EdM
    Jan 5 at 17:45
  • $\begingroup$ HI EdM, thanks for your comment but I am not sure what do you mean. Could you clarify what I should specify in my question? Thanks in advance $\endgroup$
    – cs-
    Jan 6 at 10:04
  • $\begingroup$ What I mean is essentially what @pengzell says in a comment on an answer below. Do you just want to describe the data? Then the revised plot does a good job of that. Do you have some theoretical relationship between V2 and V1 that you want to test? Then you should be fitting a non-linear function of some specific form to the data. Do you want to make predictions about V2 from future values of V1? Then you might consider any of a number of transformations and fitting methods: besides specific forms like what you've tried, more general and flexible methods like loess or restricted cubic splines. $\endgroup$
    – EdM
    Jan 6 at 14:53
  • $\begingroup$ EdM: Thanks for the clarification. I have edited my question, now clarifying that I am not so really interested in predictions of unknown variables, but just want to quantify the strength of the relationship between V1 and V2. $\endgroup$
    – cs-
    Jan 6 at 15:59

The first thing that stands out is that V1 looks highly right skewed. A first pass would be to log-transform V1 and see if a linear regression then provides a reasonable fit.

Given that the data contain zeros, a common alternative to log transformation that preserves zeros is the inverse hyperbolic sine:

ihs = log(V1 + sqrt(V1^2 + 1))

See, e.g.: Burbidge, John B., Lonnie Magee and A. Leslie Robb. 1988 "Alternative Transformations to Handle Extreme Values of the Dependent Variable." Journal of the American Statistical Association, vol. 83, 123-127.

  • $\begingroup$ Agree the log transform looks appropriate. Another way to handle taking the log of data with zeros in it is to add 1 divided by the log base, so that values of 0 get mapped to -1. So instead of log10(V1), which will fail, you'd do log10(V1+0.1). $\endgroup$ Jan 5 at 19:55
  • $\begingroup$ Hi pengzell and Nuclear Hoagie, thank you very much for your suggestions. I implemented them and obtained virtually identical results with each of them. I've posted one of the results as an edit to my former question (not sure if that's the procedure). As you can see, the log transformation does not suffice to remove the extreme skewness of Vº $\endgroup$
    – cs-
    Jan 6 at 10:02
  • 1
    $\begingroup$ What is a "good fit" here depends on your purpose. Although it doesn't remove all the skew, clearly the result is much better now and the graph is more informative as a result. I personally would be happy to use this as a basis for further modeling (e.g., how robust is the relationship to confounding etc), although others may disagree. $\endgroup$
    – pengzell
    Jan 6 at 10:14
  • $\begingroup$ Hi pengzell, you are right when saying that what a "good fit" is, very much depends on the purpose. My comment did not try to diminish the achieved improvement after applying the log transformation you proposed. I just tried to express that I would like to keep digging and find out if there's any other alternative that could provide an even "better fit" $\endgroup$
    – cs-
    Jan 6 at 11:37

If you want "to assess whether there is a relationship between both variables and to quantify the strength of such a relationship," then any general rank-correlation coefficient, for example Spearman's or Kendall's, would be a reasonable choice. That makes no assumptions about the underlying distributions, the functional form of the relationship, or which of your 2 variables is a predictor versus an outcome. You have a highly significant Spearman coefficient, consistent with a strong relationship between them.

The Spearman coefficient helps with "quantifying the amount of V2 variance explained by V1," if you are willing to consider the variance in ranks rather than variances in the actual values: the Spearman coefficient is the correlation coefficient between the 2 sets of ranks.

For "quantifying the amount of V2 variance explained by V1" in their original scales, then regression is an approach. Given the non-linear relationship between them, however, you presumably want to choose some transformation(s).

The best transformation(s) depends on how you intend to use the result. If you don't have a specific functional form in mind based on your understanding of the subject matter, generalized additive models (GAM) as you tried (although you modeled V1 as a function of V2, not the direction you seem to be interested in) and spline-based approaches provide general ways to proceed. Note, however, that you might tend to overestimate "the amount of V2 variance explained by V1" with those approaches: the results might not generalize well to new data samples unless you took precautions like penalization to minimize the effects of vagaries in fitting the particular data sample at hand.

If you don't care about the functional form of the relationship between the 2 variables, then the Spearman correlation is a very good choice. You can think of it as their correlation following one of the simplest of all transformations: each is simply transformed into its empirical cumulative distribution function.

  • $\begingroup$ Hi EdM, thanks a lot for your complete and detailed answer!. I think I will stick to Spearman's correlation as I am not so much interested in the relationship between V1 and V2 original scales but in their ordinal relationship. Thanks a lot for your help $\endgroup$
    – cs-
    Jan 7 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.