harrelfe / rms

Regression Modeling Strategies
https://hbiostat.org/R/rms
Other
172 stars 48 forks source link

Sum of squares type 1, 2, 3? #60

Closed Deleetdk closed 6 years ago

Deleetdk commented 6 years ago

I am trying to calculate omega² as effect size measures (instead of the usual eta² which is biased) for complex models such that one can compare the relative importance of predictors. In base R, this is a little tricky because various R functions use different sum of square types: stats::anova uses type 1, car::Anova can use type 2 and 3. Unfortunately, car::Anova does not work for rms fits:

> ols(Sepal.Width ~ Petal.Width, data = iris) %>% car::Anova()
Error in match.arg(type) : 
  'arg' should be one of “ordinary”, “score”, “dfbeta”, “dfbetas”, “dffit”, “dffits”, “hat”, “hscore”

I can't use stats::lm because I need the rcs() from rms for nonlinearity.

But rms has its own S3 method for the anova generic:

> ols(Sepal.Width ~ Petal.Width, data = iris) %>% anova()
                Analysis of Variance          Response: Sepal.Width 

 Factor      d.f. Partial SS MS   F  P     
 Petal.Width   1   3.8       3.79 23 <.0001
 REGRESSION    1   3.8       3.79 23 <.0001
 ERROR       148  24.5       0.17          

But it is not clear which kind of sum of squares is used. Presumably type 1 since it's a method for the stats::anova. Is there some way to get type 2 and 3 squares that I can use for computing omega²? I didn't see anything in the docs for rms::anova.rms.

harrelfe commented 6 years ago

Type 1 SS is sequential and order-dependent so is seldom appropriate. rms anova uses type 2 SS but has a different philosophy of not making it easy for the user to obtain 'main effect' tests that are adjusted for but do not include interaction effects. The preferred method is instead used: pool lower order terms with higher order terms (main effect + interaction).