[R] Implementing a linear restriction in lm()

Ravi Varadhan rvaradhan at jhmi.edu
Thu Dec 25 17:39:33 CET 2008


Hi,

You could use the "offset" argument in lm().  Here is an example:

set.seed(123)
x <- runif(50)
beta <- 1
y <- 2 + beta*x + rnorm(50)

model1 <- lm (y ~ x)
model2 <- lm (y ~ 1, offset=x)

anova(model2, model1)

Best,
Ravi.
____________________________________________________________________

Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvaradhan at jhmi.edu


----- Original Message -----
From: Serguei Kaniovski <Serguei.Kaniovski at wifo.ac.at>
Date: Wednesday, December 24, 2008 9:39 pm
Subject: [R] Implementing a linear restriction in lm()
To: r-help at stat.math.ethz.ch


>  
>  Dear All!
>  
>  I want to test a coeffcient restriction beta=1 in a univariate model 
> lm
>  (y~x). Entering
>  lm((y-x)~1) does not help since anova test requires the same dependent
>  variable. What is the right way to proceed?
>  
>  Thank you for your help and marry xmas,
>  Serguei Kaniovski
>  ________________________________________
>  Austrian Institute of Economic Research (WIFO)
>  
>  P.O.Box 91                          Tel.: +43-1-7982601-231
>  1103 Vienna, Austria        Fax: +43-1-7989386
>  
>  Mail: Serguei.Kaniovski at wifo.ac.at
>  
>  	[[alternative HTML version deleted]]
>   
> ______________________________________________
>  R-help at r-project.org mailing list
>  
>  PLEASE do read the posting guide 
>  and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list