Dear All, I was wondering if it might be possible in my below model to set "D1:Treat" and "D2:Treat" to be equal? lme(value ~ 0 + D1 + D2 + D1:Treat + D2:Treat, random = ~0 + D1 + D2 | Student, data = data) Thank you, Simon
Set two coefficients to be equal in lme()
4 messages · Simon Harmel, Uanhoro, James
Dear Simon, Create a variable that is the sum of D1 * Treat and D2 * Treat and place it in the model: data$new_var <- (data$D1 + data$D2) * data$Treat lme(value ~ 0 + D1 + D2 + new_var, random = ~0 + D1 + D2 | Student, data = data) The coefficient of new_var in the model above is the coefficient for both variables if their coefficients were constrained equal. James.
On Fri, 2021-01-15 at 23:42 -0600, Simon Harmel wrote:
Dear All, I was wondering if it might be possible in my below model to set "D1:Treat" and "D2:Treat" to be equal? lme(value ~ 0 + D1 + D2 + D1:Treat + D2:Treat, random = ~0 + D1 + D2 | Student, data = data) Thank you, Simon _______________________________________________ R-sig-mixed-models at r-project.org<mailto:R-sig-mixed-models at r-project.org> mailing list https://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models__;!!KGKeukY!hQ3ckIWlyqLy5tBnCl95bnMNKolFrWnQRu6QTS9PccmzQxnbqcOShxhVL7FHXci3_siUHiNNAdM$
If D1 and D2 are coded {-.5, .5} as you suggested in a separate email, then D1+D2 = 0 if all cases either belong to group D1 or D2 and never both. Then read Treat * new_var = 0, a constant not a variable.
In that case, simply use Treat in the model by itself - again, this is the same as constraining both groups to have the same Treat coefficient.
lme(value ~ 0 + D1 + D2 + Treat, random = ~0 + D1 + D2 | Student, data = data)
Also, basic idea behind all this is: b * x1 + b * x2 = b * (x1 + x2).
James.
From: R-sig-mixed-models <r-sig-mixed-models-bounces at r-project.org> on behalf of Uanhoro, James <uanhoro.1 at buckeyemail.osu.edu>
Sent: Saturday, January 16, 2021, 01:10
To: r-sig-mixed-models at r-project.org
Subject: Re: [R-sig-ME] Set two coefficients to be equal in lme()
Sent: Saturday, January 16, 2021, 01:10
To: r-sig-mixed-models at r-project.org
Subject: Re: [R-sig-ME] Set two coefficients to be equal in lme()
Dear Simon,
Create a variable that is the sum of D1 * Treat and D2 * Treat and place it in the model:
data$new_var <- (data$D1 + data$D2) * data$Treat
lme(value ~ 0 + D1 + D2 + new_var, random = ~0 + D1 + D2 | Student, data = data)
The coefficient of new_var in the model above is the coefficient for both variables if their coefficients were constrained equal.
James.
On Fri, 2021-01-15 at 23:42 -0600, Simon Harmel wrote:
Dear All,
I was wondering if it might be possible in my below model to set
"D1:Treat" and "D2:Treat" to be equal?
lme(value ~ 0 + D1 + D2 + D1:Treat + D2:Treat, random = ~0 + D1 + D2 |
Student, data = data)
Thank you,
Simon
[[alternative HTML version deleted]]
_______________________________________________
R-sig-mixed-models at r-project.org<mailto:R-sig-mixed-models at r-project.org> mailing list
https://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models__;!!KGKeukY!hQ3ckIWlyqLy5tBnCl95bnMNKolFrWnQRu6QTS9PccmzQxnbqcOShxhVL7FHXci3_siUHiNNAdM$
[[alternative HTML version deleted]]
_______________________________________________
R-sig-mixed-models at r-project.org mailing list
https://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models__;!!KGKeukY!nTI9flHdl-yk8eCV0yW6MKuX9CpUt1ou2zObcnZPtbJwnD2foUvMOxLrBWzjyQRnZaJ8y6i-FWw$
Dear James,
Thank you for your answer. I have a follow-up question. In my `dat` dataset
below, "Treat" is coded {-.5, .5}. D1 & D2 are simply dummy coded {0, 1} .
My question is: why when I recode "Treat" as a factor {-.5="C", .5="T"},
then the model fails? Below is a reproducible example:
library(nlme)
(dat <- read.csv("https://raw.githubusercontent.com/hkil/m/master/mv.l.csv
"))
model_works <- lme(value ~ 0 + D1 + D2+D1:Treat+D2:Treat, random = ~0 + D1
+ D2 | Student, data = dat)
(dat2 <- transform(dat, Treat = ifelse(Treat==.5,"T", "C"))) # recode
Treat as a factor
model_fails <- lme(value ~ 0 + D1 + D2+D1:Treat+D2:Treat, random = ~0 + D1
+ D2 | Student, data = dat2)
On Sat, Jan 16, 2021 at 12:10 AM Uanhoro, James <
uanhoro.1 at buckeyemail.osu.edu> wrote:
Dear Simon,
Create a variable that is the sum of D1 * Treat and D2 * Treat and place
it in the model:
data$new_var <- (data$D1 + data$D2) * data$Treat
lme(value ~ 0 + D1 + D2 + new_var, random = ~0 + D1 + D2 | Student, data =
data)
The coefficient of new_var in the model above is the coefficient for both
variables if their coefficients were constrained equal.
James.
On Fri, 2021-01-15 at 23:42 -0600, Simon Harmel wrote:
Dear All,
I was wondering if it might be possible in my below model to set
"D1:Treat" and "D2:Treat" to be equal?
lme(value ~ 0 + D1 + D2 + D1:Treat + D2:Treat, random = ~0 + D1 + D2 |
Student, data = data)
Thank you,
Simon
[[alternative HTML version deleted]]
_______________________________________________ R-sig-mixed-models at r-project.org<mailto:R-sig-mixed-models at r-project.org> mailing list https://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models__;!!KGKeukY!hQ3ckIWlyqLy5tBnCl95bnMNKolFrWnQRu6QTS9PccmzQxnbqcOShxhVL7FHXci3_siUHiNNAdM$ [[alternative HTML version deleted]] _______________________________________________ R-sig-mixed-models at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models