Skip to content

vegan RsquareAdj() for lm models

5 messages · Paolo Piras, Jari Oksanen

#
Dear list,
I would like to easily compute the adjusted R-square in a lm model without intercept (excluding the intercept is essential for my analysis)

I found that RsquareAdj() in vegan returns NA if the argument is  a multiple-multivariate lm model thus including multivariate responses and multiple predictors, while it works for univariate response and multiple predictors. 

For example:
library(vegan)

yy<-matrix(rnorm(200,0,1),ncol=4)
xx<-matrix(rnorm(200,0,1),ncol=4)
RsquareAdj(lm(yy~xx-1))
RsquareAdj(lm(yy[,1]~xx-1))



There some specific reason for this behavior?
Thanks in advance for any advice
best regards
Poalo
#
Specific reason is that nobody has implemented this. These things don't come by automatic writing, but somebody must do them.

What would you expect to get? Is this what was on your mind:
Response Y1 Response Y2 Response Y3 Response Y4
r.squared      0.06845032  0.04788037  0.01702738  0.11253059
adj.r.squared -0.01255400 -0.03491264 -0.06844849  0.03535934


This could be implemented, but (1) is this what you or anybody else would like to have?, (2) how many things would it break by returning several values instead of one?

If you want to have this, you really do not need to use vegan. vegan:::RsquareAdj.lm() takes its results from summary(<lm_object>). You can use that stats:::summary.lm directly.

Cheers, Jari Oksanen
#
Thankyou very much Jari!
I think that it is nearly ok
what I would like to have is the same as in
RsquareAdj(vegan::rda(yy,xx))

that is a GLOBAL measure of the association
BUT...I want it for a multiple-multivariate lm model that does not include the intercept;
an alternative could be to build a rda design for the exclusion of intercept but I really cannot figure out how to do it. 

I think I just need to compute the average of single adjusted r squared from the output of your line of code, 
But the results are not identical 
EXAMPLE  WITH INTERCEPT IN ORDER TO COMPARE WITH RDA

RsquareAdj(vegan::rda(yy,xx))
mean(sapply(summary(lm(yy~xx)), function(x) c("r.squared" = x$r.squared, "adj.r.squared" = x$adj.r.squared))[2,])

Or.... I just miss something in this computation

Thanks again for any further suggestion
#
Paolo,

See ?RsquareAdj for the call interface. The default method can be called as RsquareAdj(x, n, m), and in the default method x is the unadjusted correlation, n is the number of observations and m is the number of parameters (degrees of freedom) in the fitted model. Specific methods for univariate lm or for rda (and some others) find these variables in the result object, but then they just call the default method with the found x, n and m. You can build your model on that. It is possible to build a specific function for mlm objects, but nobody has done so in vegan.

You cannot build an rda design without an intercept. It was a conscious design decision to make this impossible without hacking the rda.default code (I even say this in decision-vegan vignette). I am not going to make easy to have non-centred RDA: I care too much about people and i don't want to do evil. If you really *know* that you need non-centred RDA. then you know how to change those lines of code in rda.default. 

Cheers, Jari Oksanen
#
Thanks Jari, I understand
Before going trough the code of rda I would prefer to see if I can do this using RsquareAdj

When you say "The default method can be called as RsquareAdj(x, n, m), and in the default method x is the unadjusted correlation...etc.."
my problem is to extract the global unadjusted correlation that is a single global R-square; 
As I said, just averaging the single adjusted R-squared does not return the same values of RsquareAdj

best
paolo