Cats example

Data: 144 cats (47 females, 97 males) with a body weight of at least 2 kg

Hwt – Heart Weight, g

Swt – Body Weight, kg

Sex – Sex (F/M)

options(contrasts = c("contr.sum", "contr.poly"))
    cats.fit=lm(Hwt ~ Bwt + Sex + Bwt * Sex)
    coef(cats.fit)
## (Intercept)         Bwt        Sex1    Bwt:Sex1 
##   0.8986122   3.4745464   2.0827002  -0.8381323

Females: Hwt = (0.8986+2.0827)+(3.4745-0.8381) Bwt = 2.9813+2.6364 Bwt

Males: Hwt = (0.8986-2.0827)+(3.4745+0.8381) Bwt = -4.1841+4.3126 Bwt

options(contrasts = c("contr.treatment", "contr.poly"))
    cats.fit=lm(Hwt ~ Bwt + Sex + Bwt * Sex)
    coef(cats.fit)
## (Intercept)         Bwt        SexM    Bwt:SexM 
##    2.981312    2.636414   -4.165400    1.676265

Females: Hwt = 2.9813+2.6364 Bwt

Males: Hwt = (2.9813-4.1654)+(2.6364+1.6763) Bwt = -4.1841+4.3126 Bwt

Model for both sexes

## 
## Call:
## lm(formula = Hwt ~ Bwt + Sex + Bwt * Sex)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.7728 -1.0118 -0.1196  0.9272  4.8646 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   2.9813     1.8428   1.618 0.107960    
## Bwt           2.6364     0.7759   3.398 0.000885 ***
## SexM         -4.1654     2.0618  -2.020 0.045258 *  
## Bwt:SexM      1.6763     0.8373   2.002 0.047225 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.442 on 140 degrees of freedom
## Multiple R-squared:  0.6566, Adjusted R-squared:  0.6493 
## F-statistic: 89.24 on 3 and 140 DF,  p-value: < 2.2e-16

## Analysis of Variance Table
## 
## Model 1: Hwt ~ Bwt + Sex
## Model 2: Hwt ~ Bwt + Sex + Bwt * Sex
##   Res.Df    RSS Df Sum of Sq      F  Pr(>F)  
## 1    141 299.38                              
## 2    140 291.05  1    8.3317 4.0077 0.04722 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

\(t\)-test and \(F\)-test are equivalent in this case

Analysis of residuals

Influential observations

Obs. Sex Bwt Hwt
47 F 3.0 13.0
140 M 3.7 11.0
144 M 3.9 20.5

Separate models for females and males

## 
## Call:
## lm(formula = Hwt ~ Bwt, subset = Sex == "F")
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -3.00871 -0.68599 -0.04506  0.79583  2.21858 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   2.9813     1.4855   2.007 0.050785 .  
## Bwt           2.6364     0.6254   4.215 0.000119 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.162 on 45 degrees of freedom
## Multiple R-squared:  0.2831, Adjusted R-squared:  0.2671 
## F-statistic: 17.77 on 1 and 45 DF,  p-value: 0.0001186
## 
## Call:
## lm(formula = Hwt ~ Bwt, subset = Sex == "M")
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.7728 -1.0478 -0.2976  0.9835  4.8646 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -1.1841     0.9983  -1.186    0.239    
## Bwt           4.3127     0.3399  12.688   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.557 on 95 degrees of freedom
## Multiple R-squared:  0.6289, Adjusted R-squared:  0.625 
## F-statistic:   161 on 1 and 95 DF,  p-value: < 2.2e-16

Estimates \(\hat{\beta}\)’s are the same as for the model with both sexes but SEs are different!

## F-test for equality of variances
##     Female       Male          F         Pr 
## 1.35083915 2.42377822 0.55732787 0.01552139

\(log(Hwt)=\beta_0+\beta_1 Bwt\)

\(Hwt=e^{\beta_0}~ (e^{\beta_1})^{Bwt}=\beta_0^*~ (\beta_1^*)^{Bwt}\)

but if \(\log Hwt \sim N(\beta^t x,\sigma^2)\), then \(Hwt \sim log-Normal~\)!

\[ E(Hwt)=e^{\beta^t x+.5 \sigma^2},\;\;Var(Hwt)=(e^{\sigma^2}-1)e^{2\beta^t x+\sigma^2} \] though \[ Med(Hwt)=e^{\beta^t x} \]

\(log(Hwt)=\beta_0+\beta_1 log(Bwt)\)

\(Hwt=e^{\beta_0}~ Bwt^{\beta_1}=\beta_0^*~ Bwt^{\beta_1}\)

\(lHwt=log(Hwt)\)

\(lBwt=log(Bwt)\)

Separate log-log models for females and males

## 
## Call:
## lm(formula = lHwt ~ lBwt, subset = Sex == "F")
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.38427 -0.06572  0.00217  0.08732  0.23392 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   1.6126     0.1472  10.956 2.75e-14 ***
## lBwt          0.6993     0.1713   4.083  0.00018 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1297 on 45 degrees of freedom
## Multiple R-squared:  0.2703, Adjusted R-squared:  0.2541 
## F-statistic: 16.67 on 1 and 45 DF,  p-value: 0.00018

\(\hat{\beta}_{lBwt} \approx 1\).

Test \(H_0: \beta_{lBwt}=1\). The \(t\)-statistic \(t=|0.6993-1|/0.1713=1.75\;\;(p-value=0.087)\).

## 
## Call:
## lm(formula = lHwt ~ lBwt, subset = Sex == "M")
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.28629 -0.08980 -0.01500  0.09553  0.28834 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.24609    0.09020   13.81   <2e-16 ***
## lBwt         1.09918    0.08477   12.97   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1356 on 95 degrees of freedom
## Multiple R-squared:  0.639,  Adjusted R-squared:  0.6352 
## F-statistic: 168.1 on 1 and 95 DF,  p-value: < 2.2e-16

\(\hat{\beta}_{lBwt} \approx 1\).

Test \(H_0: \beta_{lBwt}=1\). The \(t\)-statistic \(t=|1.09918-1|/0.08477=1.17\;\;(p-value=0.245)\).

Define \(lratio=lHwt-lBwt=log(Hwt/Bwt)\)

## 
## 
## 
## F-test for equality of variances
##     Female       Male          F         Pr 
## 0.01681377 0.01839041 0.91426858 0.37582648

Model for \(lratio\) for both sexes

## 
## Call:
## lm(formula = lratio ~ lBwt + Sex + lBwt:Sex, model = T)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.38427 -0.08590 -0.00165  0.09604  0.28834 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   1.6126     0.1518  10.624   <2e-16 ***
## lBwt         -0.3007     0.1766  -1.702   0.0909 .  
## SexM         -0.3665     0.1759  -2.083   0.0391 *  
## lBwt:SexM     0.3999     0.1954   2.046   0.0426 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1337 on 140 degrees of freedom
## Multiple R-squared:  0.03026,    Adjusted R-squared:  0.009478 
## F-statistic: 1.456 on 3 and 140 DF,  p-value: 0.2292

  • \(R^2\) is very low
  • slope for females is \(-0.3007\;\;(p-value=0.0909)\)
  • slope for males is \(-0.3007+0.3999=0.0992\;\;(p-value=0.6125)\)
  • \(lratio\) is constant ? \[ H_0:\beta_{lBwt}=\beta_{Sex}=\beta_{lBwt:Sex}=0 \]
## 
## Call:
## lm(formula = lratio ~ 1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.38725 -0.09530 -0.00033  0.09459  0.30711 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   1.3523     0.0112   120.8   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1344 on 143 degrees of freedom
## Analysis of Variance Table
## 
## Model 1: lratio ~ lBwt + Sex + lBwt:Sex
## Model 2: lratio ~ 1
##   Res.Df    RSS Df Sum of Sq      F Pr(>F)
## 1    140 2.5037                           
## 2    143 2.5818 -3 -0.078122 1.4561 0.2292