[Rd] under certain conditions, model.matrix appears to lack one column (PR#646)

rnassar@duke.edu rnassar@duke.edu
Sun, 27 Aug 2000 22:24:00 +0200 (MET DST)


Dear R Team,

# Summary of the problem: setting contrasts as 
   > contrasts(g) <- contr.treatment 
or > contrasts(g) <- matrix(c(1,-1,0),ncol=1)
(i.e. without quotes around `contr.treatment' or `contr.sum', etc.)
and fitting an lm model without an intercept results in a model matrix
that lacks one column.

(I do ask for forgiveness if this is not a bug but is due to my
ignorance.)

Many thanks for the extraordinary R.

Rashid Nassar


# Details:

# the data:
x <- gl(3,3)
y <- c(2,4,3,4,5,7,6,5,8)

## 1.  Using the default (treatment) contrasts unchanged gives correct 
       results.

## 2.  Setting contrasts using either of the following two forms also
       gives correct results:

> contrasts(x) <- "contr.treatment"
> contrasts(C(x,contr.treatment))

## 3. However I believe that the following (contr.treatment without quotation
marks) results in a problem (also contrasts(x) <- matrix(c(1,-1,0),ncol=1))
when an intercept is not included in the model:

> contrasts(x) <- contr.treatment 
> f4 <- lm(y ~ x - 1)
> summary(f4)

Coefficients:
   Estimate Std. Error t value Pr(>|t|)
x2    5.333      1.351   3.947  0.00555
x3    6.333      1.351   4.688  0.00224

> anova(f4)
Analysis of Variance Table

Response: y
          Df  Sum Sq Mean Sq F value   Pr(>F)
x          2 205.667 102.833  18.778 0.001537
Residuals  7  38.333   5.476                 

> model.matrix(f4)
  x2 x3
1  0  0
2  0  0
3  0  0
4  1  0
5  1  0
6  1  0
7  0  1
8  0  1
9  0  1

--please do not edit the information below--

Version:
 platform = i586-pc-linux-gnu
 arch = i586
 os = linux-gnu
 system = i586, linux-gnu
 status = 
 major = 1
 minor = 1.1
 year = 2000
 month = August
 day = 15
 language = R

Search Path:
 .GlobalEnv, package:MASS, Autoloads, package:base


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._