[R] how to suppress the intercept in an lm()-like formula method?
Michael Friendly
friendly at yorku.ca
Tue Jan 29 17:31:09 CET 2013
On 1/29/2013 10:11 AM, John Fox wrote:
> Hi Michael,
>
> OK -- I see -- you need to do more than fix up the model matrix.
>
> How about this?
>
> formula <- update(formula, . ~ . - 1)
> cl <- match.call()
> cl$formula <- formula
> mf <- match.call(expand.dots = FALSE)
> mf$formula <- formula
>
> Best,
> John
That's the cleverest solution I've seen. It fixes it early, and avoids
later complications / kludges.
Thanks very much for this. I'm cc'ing R-help for posterity.
best,
-Michael
>
>> -----Original Message-----
>> From: Michael Friendly [mailto:friendly at yorku.ca]
>> Sent: Tuesday, January 29, 2013 9:36 AM
>> To: John Fox
>> Subject: Re: [R] how to suppress the intercept in an lm()-like formula
>> method?
>>
>> On 1/29/2013 9:23 AM, John Fox wrote:
>>> Hi Michael,
>>>
>>> How about,
>>>
>>> x <- x[, colnames(x) != "(Intercept)"]
>>>
>> Thanks, John
>> See my followup post. I'm now using
>>
>> remove.intercept <- function(x) {
>> if (colnames(x)[1] == "(Intercept)") {
>> x <- x[,-1]
>> attr(x, "assign") <- attr(x, "assign")[-1]
>> }
>> x
>> }
>> which works, but other objects in the function (mt & mf) are silently
>> wrong, still including the intercept.
>>
>> --
>> Michael Friendly Email: friendly AT yorku DOT ca
>> Professor, Psychology Dept. & Chair, Quantitative Methods
>> York University Voice: 416 736-2100 x66249 Fax: 416 736-5814
>> 4700 Keele Street Web: http://www.datavis.ca
>> Toronto, ONT M3J 1P3 CANADA
>
--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept. & Chair, Quantitative Methods
York University Voice: 416 736-2100 x66249 Fax: 416 736-5814
4700 Keele Street Web: http://www.datavis.ca
Toronto, ONT M3J 1P3 CANADA
More information about the R-help
mailing list