Hi,
How about:

xwfB[f=="A"] <-0
xwfB[f=="B"] <- scale(x[f=="B"], center = TRUE, scale=FALSE)

lmer(y ~ f + xwfB + (1 | g))
Linear mixed-effects model fit by REML
Formula: y ~ f + xwfB + (1 | g)
  AIC  BIC logLik MLdeviance REMLdeviance
 1481 1494 -736.4       1477         1473
Random effects:
 Groups   Name        Variance   Std.Dev.
 g        (Intercept) 3.2279e-06 0.0017966
 Residual             9.5567e+01 9.7758279
Number of obs: 200, groups: g, 20

Fixed effects:
             Estimate Std. Error t value
(Intercept)  606.5497     0.9776   620.5
fB          -183.9712     1.3825  -133.1
xwfB         -51.3651     0.4447  -115.5

Correlation of Fixed Effects:
     (Intr) fB
fB   -0.707
xwfB  0.000  0.000

Best
Reinhold

On Jan 1, 2008 6:27 AM, Gregor GORJANC <gregor.gorjanc@bfro.uni-lj.si>
wrote:

> Hi!
>
> First of all happy new year and all the best in 2008!
>
> Does anyone have any idea how to trick lmer() in the same way as
> lm() to constrain one regression slope to zero in nested regression.
> The following code shows what I want to do:
>
> ## Generate data
>
> x1 <- runif(n=100, min=-4, max=1)
> y1 <- rep(606, length(x1)) + rnorm(n=100, sd=10)
> x1 <- x1 + 1995
>
> x2 <- runif(n=100, min=0, max=8)
> y2 <- (606 + 0.14) - 51.8 * x2 + rnorm(n=100, sd=10)
> x2 <- x2 + 1997
>
> y <- c(y1, y2)
> x <- c(x1, x2)
> f <- factor(rep(c("A", "B"), each=100))
> g <- factor(rep(letters[1:20], times=10))
>
> ## Plot
>
> plot(y ~ x, type="p", xlim=c(1991, 2005), ylim=c(0, 700))
>
> ## Fit model - (nested) regression for each "period"
>
> lm(y ~ f * x)
> ## OK
>
> lmer(y ~ f * x + (1 | g))
> ## OK
>
> ## Fit model - (nested) regression for each "period", but constrain
> ## slope to zero in first "period"
>
> x2 <- x
> x2[1:100] <- 0
>
> lm(y ~ f * x2)
> ## OK
>
> lmer(y ~ f * x2 + (1 | g))
> Error in lmer(y ~ f * x2 + (1 | g)) :
>  Leading minor of order 4 in downdated X'X is not positive definite
>
> Thanks!
>
> --
> Lep pozdrav / With regards,
>    Gregor Gorjanc
>
>
> ----------------------------------------------------------------------------------------------------
> University of Ljubljana          PhD student
> Biotechnical Faculty
> Zootechnical Department     URI: http://www.bfro.uni-lj.si/MR/ggorjan
> Groblje 3                            mail: gregor.gorjanc <at>
> bfro.uni-lj.si
> SI-1230 Domzale                tel: +386 (0)1 72 17 861
> Slovenia, Europe                 fax: +386 (0)1 72 17 888
>
> ----------------------------------------------------------------------------------------------------
> "One must learn by doing the thing; for though you think you know it,
>  you have no certainty until you try." Sophocles ~ 450 B.C.
>
> ----------------------------------------------------------------------------------------------------
>
>
>
> --
> Lep pozdrav / With regards,
>    Gregor Gorjanc
>
>
> ----------------------------------------------------------------------------------------------------
> University of Ljubljana          PhD student
> Biotechnical Faculty
> Zootechnical Department     URI: http://www.bfro.uni-lj.si/MR/ggorjan
> Groblje 3                            mail: gregor.gorjanc <at>
> bfro.uni-lj.si
> SI-1230 Domzale                tel: +386 (0)1 72 17 861
> Slovenia, Europe                 fax: +386 (0)1 72 17 888
>
> ----------------------------------------------------------------------------------------------------
> "One must learn by doing the thing; for though you think you know it,
>  you have no certainty until you try." Sophocles ~ 450 B.C.
>
> _______________________________________________
> R-sig-mixed-models@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>

	[[alternative HTML version deleted]]


