Skip to content
Prev 255815 / 398506 Next

ANCOVA for linear regressions without intercept

Hi Yusuke,

Does the following get what you are after?

### Make some test data.
+                   head_length = c(1.2 * c(170:179 + rnorm(10)), 0.8 * c(150:159 + rnorm(10)), c(160:169 + rnorm(10)))/10,
+                   body_length = c(c(170:179 + rnorm(10)), c(150:159 + rnorm(10)), c(160:169 + rnorm(10)))
+                   )
### The full model - do keep an eye on those intercepts and try to ensure they are not far from 0.
Call:
lm(formula = body_length ~ head_length * sex, data = edf)

Residuals:
     Min       1Q   Median       3Q      Max 
-2.73783 -0.68133  0.02147  0.50858  2.38931 

Coefficients:
                       Estimate Std. Error t value Pr(>|t|)    
(Intercept)              -3.578     25.425  -0.141   0.8893    
head_length              12.772      2.054   6.218    2e-06 ***
sexMale                  15.122     37.464   0.404   0.6901    
sexUnknown               40.308     33.137   1.216   0.2357    
head_length:sexMale      -4.977      2.438  -2.042   0.0523 .  
head_length:sexUnknown   -4.971      2.428  -2.047   0.0517 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 1.384 on 24 degrees of freedom
Multiple R-squared: 0.9802,	Adjusted R-squared: 0.9761 
F-statistic: 237.7 on 5 and 24 DF,  p-value: < 2.2e-16 

### Now suppress intercepts.  head_length:sex should give interactions (slopes) only.
Call:
lm(formula = body_length ~ -1 + head_length:sex, data = edf)

Residuals:
     Min       1Q   Median       3Q      Max 
-3.02782 -0.61861 -0.01079  0.68785  2.57544 

Coefficients:
                       Estimate Std. Error t value Pr(>|t|)    
head_length:sexFemale  12.48253    0.03549   351.8   <2e-16 ***
head_length:sexMale     8.34500    0.02097   398.0   <2e-16 ***
head_length:sexUnknown 10.03844    0.02677   375.0   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 1.389 on 27 degrees of freedom
Multiple R-squared: 0.9999,	Adjusted R-squared: 0.9999 
F-statistic: 1.409e+05 on 3 and 27 DF,  p-value: < 2.2e-16 

### Check the numeric coding of the factor
sex        1  2  3
  Female  10  0  0
  Male     0 10  0
  Unknown  0  0 10
### If no diff between males and females, then males and females can be combined into one group.
sex
MvF       Female Male Unknown
  MorF        10   10       0
  Unknown      0    0      10
Call:
lm(formula = body_length ~ -1 + head_length:MvF, data = edf)

Residuals:
    Min      1Q  Median      3Q     Max 
-23.976 -21.656   0.077  35.899  39.839 

Coefficients:
                       Estimate Std. Error t value Pr(>|t|)    
head_length:MvFMorF      9.4156     0.3429   27.46   <2e-16 ***
head_length:MvFUnknown  10.0384     0.5085   19.74   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 26.39 on 28 degrees of freedom
Multiple R-squared: 0.9761,	Adjusted R-squared: 0.9744 
F-statistic: 571.9 on 2 and 28 DF,  p-value: < 2.2e-16 

### Test the hypothesis that male and female heights are equivalent
Analysis of Variance Table

Model 1: body_length ~ -1 + head_length:MvF
Model 2: body_length ~ -1 + head_length:sex
  Res.Df     RSS Df Sum of Sq     F    Pr(>F)    
1     28 19496.1                                 
2     27    52.1  1     19444 10077 < 2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

### Plot the reduced model regression lines
The other two tests can be set up and run similarly.  Don't
forget to adjust for multiple comparisons...

HTH

Steve


Steven McKinney, Ph.D.

Statistician
Molecular Oncology and Breast Cancer Program
British Columbia Cancer Research Centre
Message-ID: <DCE81E14EB74504B971DAD4D2DB0356B08645686B7@crcmail4.BCCRC.CA>
In-Reply-To: <26212_1301966525_1301966525_B38A1433CF2D7E48BF60B9D93FCD5A260D45C5DE5F@emdch-es2.prod.main.ntgov>