0

I have a linear model where my response Y is say the percentage (proportion) of fat in milk. I have two explanatory variables one (x1) is a continuous variable, the other (z) is a three level factor.

I now do the regression in R as:

contrasts(z) <- "contr.sum"
model<-lm(logit(Y) ~ log(x1)*z)

the model summary gives me the R2 of this model . However, I want to find out the importance of x1 in my model. I can look at the p-value if the slope is statistically different from 0, but this does not tell me if x1 is actually a good predictor.

Is there a way to get the partial R2 for this model and the overall effect of x1? As this model includes an interaction I am not sure how to calculate this and if there is one unique solution or if I get a partial R2 for the main effect of x1 and a partial R2 for main effect of x1 plus its interaction.

Or would it be better to avoid partial R2 and explain the magnitude of the slope of the main effect and interaction. But given my logit transformation I am not sure if this has any practical meaning for say how log(x1) changes the log odds ratio of % fat in milk.

Thanks.

-I tried to fit the model without the interaction and without the factor to get a usual R2 , but this would not be my preferred solution and I would like to get the partial R2 when specifying a full model.

Update: As requested in a comment, here the output from the summary(model). As written above z is sum contrast coded.

Call:
lm(formula = y ~ log(x1) * z, data = mydata)

Residuals:
     Min       1Q   Median       3Q      Max 
-1.21240 -0.09487  0.03282  0.13588  0.85941 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) -2.330678   0.034043 -68.462  < 2e-16 ***
log(x1)     -0.012948   0.005744  -2.254  0.02454 *  
z1           0.140710   0.048096   2.926  0.00357 ** 
z2          -0.348526   0.055156  -6.319 5.17e-10 ***
log(x1):z1   0.017051   0.008095   2.106  0.03558 *  
log(x1):z2  -0.028201   0.009563  -2.949  0.00331 ** 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.2288 on 594 degrees of freedom
Multiple R-squared:  0.1388,    Adjusted R-squared:  0.1315 
F-statistic: 19.15 on 5 and 594 DF,  p-value: < 2.2e-16

Update: As requested in a comment, here the output from

print(aov(model))

Call:
   aov(formula = model)

Terms:
                  log(x1)         z log(x1):z Residuals
Sum of Squares   0.725230  3.831223  0.456677 31.105088
Deg. of Freedom         1         2         2       594

Residual standard error: 0.228835
Estimated effects may be unbalanced.
As written above, z is sum contrast coded.
Dave2e
  • 22,192
  • 18
  • 42
  • 50
Jmmer
  • 11
  • 3
  • If you use the print the summary of the `aov()` using your model. The table will provide a column for the sum of square for each term. R2 = 1 - (residual sum of sq)/(total of sum of squares). One could use this to calculate the fractional contribution of term in R2. Of course in your model with a factor variable it complicates the calculation. It might be easier to separate your data into 3 groups based on the factor variable and perform the calculation independently for each factor. – Dave2e Nov 02 '22 at 02:39
  • thanks, updated the question. Yes.. not sure how to include the interaction, this is exactly the problem I have, as I want to avoid fitting multiple models or excluding the factor. – Jmmer Nov 02 '22 at 02:54
  • -not sure if my only option is to look at the R2 of model<-lm(logit(Y) ~ log(x1)*z) and the R2 from model2<-lm(logit(Y) ~ z) and just check how much my R2 increases from model2 to model1. But not really a partial R2 of log(x1)? – Jmmer Nov 02 '22 at 03:00
  • You want to use `summary(aov(model))`, I do suggest performing the regressions individually and trying to understand the process. Once that is complete then run the analysis on the full model. – Dave2e Nov 02 '22 at 03:05
  • - I think I understand but given I have the interaction can I do (SSE (model2) - SSE (model)) / SSE (model2) to obtain a partial R2 for log(x1). with SSE the residual sums of squares. I am quite struggling to understand how to disentangle the contribution of the interaction in this. – Jmmer Nov 02 '22 at 03:36

0 Answers0