[R] car::linearHypothesis fails to constrain factor to zero
John Fox
jfox at mcmaster.ca
Wed Aug 15 15:33:55 CEST 2012
Dear Iuri,
"fake" is not a coefficient in the model:
> linearHypothesis(my_lm, matchCoefs(my_lm, "fake"))
Linear hypothesis test
Hypothesis:
fakeB = 0
Model 1: restricted model
Model 2: Infant.Mortality ~ Fertility + fake
Res.Df RSS Df Sum of Sq F Pr(>F)
1 45 322.54
2 44 311.97 1 10.567 1.4903 0.2287
Best,
John
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Iuri Gavronski
> Sent: August-15-12 4:47 AM
> To: r-help
> Subject: [R] car::linearHypothesis fails to constrain factor to zero
>
> Hi,
>
> I am trying to test whether a factor (coded as a set of dummy
> variables) is equal to zero, using linearHypothesis. I get an error.
> See a reproducible example:
>
> data(swiss)
> my_swiss = swiss
> my_swiss$fake = factor(sample(c("A","B"),47,rep=T))
> my_lm <- lm(Infant.Mortality ~ Fertility + fake, data=my_swiss)
>
> > linearHypothesis(my_lm, "fake")
> Error in constants(lhs, cnames_symb) :
> The hypothesis "fake" is not well formed: contains bad
coefficient/variable
> names.
> In addition: Warning message:
> In constants(lhs, cnames_symb) : NAs introduced by coercion
> >
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list