Closed YSanchezAraujo closed 8 months ago
There is no exact equivalent of R2 for robust models, but different definitions of pseudo-coefficients of determination. See https://juliastats.org/StatsBase.jl/stable/statmodels/#StatsAPI.r2 , where there is the deviance formula you mentioned.
You can get it like that also:
R2 = StatsBase.r2(model, :devianceratio)
I would use this one as it is stricly equivalent to R2 in the OLS case, but I don't know if it's guaranteed to be non-negative. If it is negative, it means the fit with a slope is worse than no fit, in this case, you can consider that R2=0.
But I am not sure this is what you want. If what you want is a signed correlation, it would be better to z-score y
and X
before doing the regression so the coefficients b0
and b1
are scaled. For OLS, z-scoring before the regression leads to a0 = 0
and a1 = Σxi yi
which is the same as computing the Pearson correlation of the z-scored x
and y
.
You can use StatsBase.ZScoreTransform
to z-score:
https://juliastats.org/StatsBase.jl/stable/transformations/#Standardization-a.k.a-Z-score-Normalization
thanks for the response and additional info! closing this
Is there a function (I've searched the API and can't find it but maybe have missed it) to compute variance explained? I'm using robust models from this package to compute p-values for correlations in the case of a single independent variable:
ideally I'd also want to compute the correaltion coefficient, which in the model above in the ols case is just
sign(b1) * sqrt(R^2)
, but in this case I can't simply predict the responses and compute R^2 as per usual because of the potential for negative values.I see in the API one possibility is (i think)
but I'm wondering if there's potentially the same issue here?