# R implementation of coefficient of partial determination

Does anyone have suggestions or packages that will calculate the coefficient of partial determination?

The coefficient of partial determination can be defined as the percent of variation that cannot be explained in a reduced model, but can be explained by the predictors specified in a full(er) model. This coefficient is used to provide insight into whether or not one or more additional predictors may be useful in a more fully specified regression model.

The calculation for the partial r^2 is relatively straight forward after estimating your two models and generating the ANOVA tables for them. The calculation for the partial r^2 is:

(SSEreduced - SSEfull) / SSEreduced

I've written this relatively simple function that will calculate this for a multiple linear regression model. I'm unfamiliar with other model structures in R where this function may not perform as well:

partialR2 <- function(model.full, model.reduced){
anova.full <- anova(model.full)
anova.reduced <- anova(model.reduced)

sse.full <- tail(anova.full$"Sum Sq", 1) sse.reduced <- tail(anova.reduced$"Sum Sq", 1)

pR2 <- (sse.reduced - sse.full) / sse.reduced
return(pR2)

}


Any suggestions or tips on more robust functions to accomplish this task and/or more efficient implementations of the above code would be much appreciated.

-
I suggest trying the other models and see whether the code works or not. R is usually nice, so anova should return similar things for different models. The problem is with your initial formula. Does it hold for other models? If it does not, then there is no point in getting code to work, furthermore the code should issue a warning that it is used for models where formula does not hold. – mpiktas Mar 2 '11 at 15:05
I don't really see the question. You want a function that calculates partial R2, but you already have one. Do you know package sensitivity (there are no partial R2 but pcc which is a particular case is implemented)? – robin girard Mar 7 '11 at 12:39
@robin - I apologize if my question wasn't clear. I am interested in finding a package that contains this calculation (as it probably contains many other helpful functions that would be useful) and/or suggestions on how to improve the function I wrote above. It is obviously lacking any error checking, and may not be applicable for all model types. – Chase Mar 7 '11 at 16:07
I suggest this question be migrated to SE. At the heart of the question seems to be an implementation problem, not a statistical one. – caracal May 18 '11 at 21:45
@caracal - whatever you see fit. I know there's been a fair amount of discussion regarding where the line in the sand should be drawn between SO and CV regarding R related questions. I don't have a strong preference either way. My work has taken me away from this specific problem for the last bit, but will be revisiting it again in the coming weeks so I may come up with a better solution myself. I'm also fine letting the question fade off into the ether... – Chase May 19 '11 at 0:26

Well, r^2 is really just covariance squared over the product of the variances, so you could probably do something like cov(Yfull, Ytrue)/var(Ytrue)var(Yfull) - cov(YReduced, Ytrue)/var(Ytrue)var(YRed) regardless of model type; check to verify that gives you the same answer in the lm case though.

http://www.stator-afm.com/image-files/r-squared.gif

-