> On 11 Mar 2016, at 23:48 , David Winsemius wrote:
>
>>
>> On Mar 11, 2016, at 2:07 PM, peter dalgaard wrote:
>>
>>
>>> On 11 Mar 2016, at 17:56 , David Winsemius wrote:
>>>
On Mar 11, 2016, at 12:48 AM, peter
> On Mar 11, 2016, at 2:07 PM, peter dalgaard wrote:
>
>
>> On 11 Mar 2016, at 17:56 , David Winsemius wrote:
>>
>>>
>>> On Mar 11, 2016, at 12:48 AM, peter dalgaard wrote:
>>>
>>>
On 11 Mar 2016, at 08:25 , David Winsemius
> On 11 Mar 2016, at 17:56 , David Winsemius wrote:
>
>>
>> On Mar 11, 2016, at 12:48 AM, peter dalgaard wrote:
>>
>>
>>> On 11 Mar 2016, at 08:25 , David Winsemius wrote:
>> ...
> dfrm <- data.frame(y=rnorm(10),
> On Mar 11, 2016, at 12:48 AM, peter dalgaard wrote:
>
>
>> On 11 Mar 2016, at 08:25 , David Winsemius wrote:
>>>
> ...
dfrm <- data.frame(y=rnorm(10), x1=rnorm(10) ,x2=as.factor(TRUE),
x3=rnorm(10))
lm(y~x1+x2+x3, dfrm,
Hi,
In case this is helpful for anyone, I think I've coded a satisfactory
function answering my problem (of handling formulas containing 1-level
factors) by hacking liberally at the model.matrix code to remove any
model terms for which the contrast fails. As it's a problem I've come
across a lot
The one you cite must have been due to fat-fingering (send instead of delete),
but there was a later followup to David, w/copy to r-help.
-pd
On 11 Mar 2016, at 16:03 , Robert McGehee wrote:
>
> PS, Peter, wasn't sure if you also meant to add comments, but they
> didn't
> On 11 Mar 2016, at 02:03 , Robert McGehee wrote:
>
>> df <- data.frame(y=c(0,2,4,6,8), x1=c(1,1,2,2,NA),
> x2=factor(c("A","A","A","A","B")))
>> resid(lm(y~x1+x2, data=df, na.action=na.exclude)
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business
> On 11 Mar 2016, at 08:25 , David Winsemius wrote:
>>
...
>>> dfrm <- data.frame(y=rnorm(10), x1=rnorm(10) ,x2=as.factor(TRUE),
>>> x3=rnorm(10))
>>> lm(y~x1+x2+x3, dfrm, na.action=na.exclude)
>> Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
>>
M
>> To: Robert McGehee
>> Cc: r-help@r-project.org
>> Subject: Re: [R] Regression with factor having1 level
>>
>>
>>> On Mar 10, 2016, at 2:00 PM, Robert McGehee <rmcge...@gmail.com>
>> wrote:
>>>
>>> Hello R-helpers,
>>> I'
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of David
> Winsemius
> Sent: Thursday, March 10, 2016 4:39 PM
> To: Robert McGehee
> Cc: r-help@r-project.org
> Subject: Re: [R] Regression with factor having1 level
>
>
>
Here's an example for clarity:
> df <- data.frame(y=c(0,2,4,6,8), x1=c(1,1,2,2,NA),
x2=factor(c("A","A","A","A","B")))
> resid(lm(y~x1+x2, data=df, na.action=na.exclude)
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more
> On Mar 10, 2016, at 2:00 PM, Robert McGehee wrote:
>
> Hello R-helpers,
> I'd like a function that given an arbitrary formula and a data frame
> returns the residual of the dependent variable,and maintains all NA values.
What does "maintains all NA values" actually mean?
Robert McGehee gmail.com> writes:
>
> Hello R-helpers,
> I'd like a function that given an arbitrary formula and a data frame
> returns the residual of the dependent variable, and maintains all
> NA values.
>
> Here's an example that will give me what I want if my formula is y~x1+x2+x3
> and
Hello R-helpers,
I'd like a function that given an arbitrary formula and a data frame
returns the residual of the dependent variable, and maintains all NA values.
Here's an example that will give me what I want if my formula is y~x1+x2+x3
and my data frame is df:
resid(lm(y~x1+x2+x3, data=df,
14 matches
Mail list logo