[R] Subset function of lm() does not seem to work

Ajay Shah ajayshah at mayin.org
Sat Feb 7 06:17:27 CET 2004


I have an elementary question about  the lm() function, where I'm
trying to exploit the "subset" feature, to make it use only a subset
of the observations. My code is:

  A <- read.table(file="datafile.2",
  # The file datafile.2 has 100 observations.
  # I want to do a regression using the first 25 only

  # Subset vector : the 1st 25 are on, the remaining 75 are off.
  window = c(rep(1,25), rep(0,75))

  model <- lm(dlinrchf ~ dlusdchf + dljpychf + dldemchf, A, window)

This doesn't work: I get --

  Coefficients: (3 not defined because of singularities)
                Estimate Std. Error    t value Pr(>|t|)    
  (Intercept) -3.088e-03  1.384e-19 -2.232e+16   <2e-16 ***
  dlusdchf            NA         NA         NA       NA    
  dljpychf            NA         NA         NA       NA    
  dldemchf            NA         NA         NA       NA    

I have tested using alternative software (stata) and the 1st 25
observations are quite fine for doing a regression. I find that even
if I set window to rep(1,100) (i.e. a vector of 100 ones) the lm()
does not work.

I guess I'm making some mistake in using the "subset" capability of
lm(). Any help will be most appreciated...

More information about the R-help mailing list