[R] truncated regressor

Emmanuel Paradis paradis at isem.univ-montp2.fr
Mon May 15 11:33:59 CEST 2000


At 16:45 14/05/00 +0100, Brian D. Ripley wrote:
>On Sun, 14 May 2000, Troels Ring wrote:
>
>> Dear friends. I have the problem of assessing the importance of bleeding 
>> times censored at 20 minutes for predicting blood loss incurred after a 
>> liver biopsy. How would I use the knowledge that the censored values were 
>> 20 minutes or more ?
>
>This is a (partially) missing-value problem.  Are values > 20 mins 
>always censored?  If so I would group the times and use an ordered factor
>as a regressor.  If you really want a linear effect on, say `bt' you can
>use
>
>... + bt + I(bt==20) + ...
>
>which allows a separate value of bt==20 over and above a linear model.


I am trying to understand this. The help for ?I says:

...
     To avoid this confusion, the function `I()' can be used to bracket
     those portions of a model formula where the operators are used in
     their arithmetic sense.  For example, in the formula `y ~ a +
     I(b+c)', the term `b+c' is to be interpreted as the sum of `b' and
     `c'.
...

which is clear to me: doing lm(y ~ a + I(b+c)) is similar to

	d <- b + c
	lm(y ~ a + d)

But what if the expression in I() is a logical? After playing a moment, I
found out that a formula can include a logical variable, and treats it as a
factor:

> x <- runif(50, 0, 50)
> y <- 2*x + rnorm(50, 0, 5)
> lm(y ~ x < 25)

Call:
lm(formula = y ~ x < 25)

Coefficients:
(Intercept)       x < 25  
      78.24       -53.92  

> lm(y ~ x > 25)

Call:
lm(formula = y ~ x > 25)

Coefficients:
(Intercept)       x > 25  
      24.32        53.92  


Is it worth adding a few lines in this help file on the use of logical
variables in formula? (also characters can be included but must be
converted into factors before)

Emmanuel Paradis
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list