Do I need to specify nested random effects when nesting is implicit in the data?lme4 upgrade produces error message even after grouping variables within the data frameAfter trying various optimzers, model simplification running more iterations, when fitting GLMMs, R still produces warning messagesglmer with user-defined link function giving error: (maxstephalfit) PIRLS step-halvings failed to reduce deviancelme4 fails to calculate random intercepts with no warningsMixed effects model with random and nested effects in lmerSpecify within-subjects and between-subjects ANOVA model using lme or lmer, as fixed-effectsPercentage and glmerglmer random effect nested within fixed effectLMMs with random effects associated with levels of crossed/nested grouping factorsHow can I use a glmer output for rma.glmm input in mixed model logistic regression meta-analysis?
Swapping "Good" and "Bad"
How were Martello towers supposed to work?
Why didn't the Archangel Michael save Jesus when he was crucified?
Integer Lists of Noah
Convert BAM to properly paired FASTQ files
What is the right approach to quit a job during probation period for a competing offer?
Does Multiverse exist in MCU?
Why return a static pointer instead of an out parameter?
Why weren't bootable game disks ever common on the IBM PC?
Salt, pepper, herbs and spices
Shortest hex dumping program
Elf (adjective) vs. Elvish vs. Elven
For a hashing function like MD5, how similar can two plaintext strings be and still generate the same hash?
Can I completely remove lens distortion from any image?
What's the point of having a RAID 1 configuration over incremental backups to a secondary drive?
Which star / galaxy is moving away from us the fastest?
Short story about Nobel Prize winning scientists that drop out when they realise they were incorrect
Are there any sports for which the world's best player is female?
Why are Democratic presidential candidates promising free health care for Illegal Immigrants?
Is "I do not want you to go nowhere" a case of "DOUBLE-NEGATIVES" as claimed by Grammarly?
Confirming the Identity of a (Friendly) Reviewer After the Reviews
How can characters/players identify that a polymorphed dragon is a dragon?
How to tell someone I'd like to become friends without letting them think I'm romantically interested in them?
If your plane is out-of-control, why does military training instruct releasing the joystick to neutralize controls?
Do I need to specify nested random effects when nesting is implicit in the data?
lme4 upgrade produces error message even after grouping variables within the data frameAfter trying various optimzers, model simplification running more iterations, when fitting GLMMs, R still produces warning messagesglmer with user-defined link function giving error: (maxstephalfit) PIRLS step-halvings failed to reduce deviancelme4 fails to calculate random intercepts with no warningsMixed effects model with random and nested effects in lmerSpecify within-subjects and between-subjects ANOVA model using lme or lmer, as fixed-effectsPercentage and glmerglmer random effect nested within fixed effectLMMs with random effects associated with levels of crossed/nested grouping factorsHow can I use a glmer output for rma.glmm input in mixed model logistic regression meta-analysis?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am working with a data set containing nested groups and am wondering how to properly specify the model(s).
The data are binary indicators of whether or not a "Code" is agreed upon by a Group. There are 3 Groups within the Control condition and 3 Groups within the Treatment condition.
I am trying to model the probabilities of the various Codes being present in the Treatment Condition.
Some toy data:
library(lme4)
Data <- rbind(data.frame(Code = rep(LETTERS[1:5],6),
Condition = rep("Control", 30),
Trial = rep(c(1:3), each = 5),
Group = rep(letters[1:3],10),
Present = sample(0:1, 30, replace = T)),data.frame(Code = rep(LETTERS[1:5],6),
Condition = rep("Treatment", 30),
Trial = rep(c(1:3), each = 5),
Group = rep(letters[4:6],10),
Present = sample(0:1, 30, replace = T)))
Give the inherent nesting in the data, can I specify the model as:
Mod1 <- glmer(Present ~ Condition * Code + (1|Group), family=binomial(link = "logit"), data = Data)
Or do I need to specify the nesting with something like:
Mod2<- glmer(Present ~ Condition * Code + (1|Condition/Group), family=binomial(link = "logit"), data = Data)
I'm not sure which model captures the design and I have seen conflicting posts about the use of / vs :, so I'm not clear if I have specified the nesting correctly (in addition to whether it's necessary).
The example data are small, so the second model gives a singular fit warning. My data generation/simulation skills are non-existent, so any advice on creating a better example set would also be welcome!
r statistics lme4
add a comment |
I am working with a data set containing nested groups and am wondering how to properly specify the model(s).
The data are binary indicators of whether or not a "Code" is agreed upon by a Group. There are 3 Groups within the Control condition and 3 Groups within the Treatment condition.
I am trying to model the probabilities of the various Codes being present in the Treatment Condition.
Some toy data:
library(lme4)
Data <- rbind(data.frame(Code = rep(LETTERS[1:5],6),
Condition = rep("Control", 30),
Trial = rep(c(1:3), each = 5),
Group = rep(letters[1:3],10),
Present = sample(0:1, 30, replace = T)),data.frame(Code = rep(LETTERS[1:5],6),
Condition = rep("Treatment", 30),
Trial = rep(c(1:3), each = 5),
Group = rep(letters[4:6],10),
Present = sample(0:1, 30, replace = T)))
Give the inherent nesting in the data, can I specify the model as:
Mod1 <- glmer(Present ~ Condition * Code + (1|Group), family=binomial(link = "logit"), data = Data)
Or do I need to specify the nesting with something like:
Mod2<- glmer(Present ~ Condition * Code + (1|Condition/Group), family=binomial(link = "logit"), data = Data)
I'm not sure which model captures the design and I have seen conflicting posts about the use of / vs :, so I'm not clear if I have specified the nesting correctly (in addition to whether it's necessary).
The example data are small, so the second model gives a singular fit warning. My data generation/simulation skills are non-existent, so any advice on creating a better example set would also be welcome!
r statistics lme4
1
Yes.. The whole point is to create the proper mathematical environment for valid inference. I get the same failure to converge warning with either model.
– 42-
Mar 26 at 1:04
add a comment |
I am working with a data set containing nested groups and am wondering how to properly specify the model(s).
The data are binary indicators of whether or not a "Code" is agreed upon by a Group. There are 3 Groups within the Control condition and 3 Groups within the Treatment condition.
I am trying to model the probabilities of the various Codes being present in the Treatment Condition.
Some toy data:
library(lme4)
Data <- rbind(data.frame(Code = rep(LETTERS[1:5],6),
Condition = rep("Control", 30),
Trial = rep(c(1:3), each = 5),
Group = rep(letters[1:3],10),
Present = sample(0:1, 30, replace = T)),data.frame(Code = rep(LETTERS[1:5],6),
Condition = rep("Treatment", 30),
Trial = rep(c(1:3), each = 5),
Group = rep(letters[4:6],10),
Present = sample(0:1, 30, replace = T)))
Give the inherent nesting in the data, can I specify the model as:
Mod1 <- glmer(Present ~ Condition * Code + (1|Group), family=binomial(link = "logit"), data = Data)
Or do I need to specify the nesting with something like:
Mod2<- glmer(Present ~ Condition * Code + (1|Condition/Group), family=binomial(link = "logit"), data = Data)
I'm not sure which model captures the design and I have seen conflicting posts about the use of / vs :, so I'm not clear if I have specified the nesting correctly (in addition to whether it's necessary).
The example data are small, so the second model gives a singular fit warning. My data generation/simulation skills are non-existent, so any advice on creating a better example set would also be welcome!
r statistics lme4
I am working with a data set containing nested groups and am wondering how to properly specify the model(s).
The data are binary indicators of whether or not a "Code" is agreed upon by a Group. There are 3 Groups within the Control condition and 3 Groups within the Treatment condition.
I am trying to model the probabilities of the various Codes being present in the Treatment Condition.
Some toy data:
library(lme4)
Data <- rbind(data.frame(Code = rep(LETTERS[1:5],6),
Condition = rep("Control", 30),
Trial = rep(c(1:3), each = 5),
Group = rep(letters[1:3],10),
Present = sample(0:1, 30, replace = T)),data.frame(Code = rep(LETTERS[1:5],6),
Condition = rep("Treatment", 30),
Trial = rep(c(1:3), each = 5),
Group = rep(letters[4:6],10),
Present = sample(0:1, 30, replace = T)))
Give the inherent nesting in the data, can I specify the model as:
Mod1 <- glmer(Present ~ Condition * Code + (1|Group), family=binomial(link = "logit"), data = Data)
Or do I need to specify the nesting with something like:
Mod2<- glmer(Present ~ Condition * Code + (1|Condition/Group), family=binomial(link = "logit"), data = Data)
I'm not sure which model captures the design and I have seen conflicting posts about the use of / vs :, so I'm not clear if I have specified the nesting correctly (in addition to whether it's necessary).
The example data are small, so the second model gives a singular fit warning. My data generation/simulation skills are non-existent, so any advice on creating a better example set would also be welcome!
r statistics lme4
r statistics lme4
asked Mar 26 at 1:04
JLCJLC
3011 silver badge9 bronze badges
3011 silver badge9 bronze badges
1
Yes.. The whole point is to create the proper mathematical environment for valid inference. I get the same failure to converge warning with either model.
– 42-
Mar 26 at 1:04
add a comment |
1
Yes.. The whole point is to create the proper mathematical environment for valid inference. I get the same failure to converge warning with either model.
– 42-
Mar 26 at 1:04
1
1
Yes.. The whole point is to create the proper mathematical environment for valid inference. I get the same failure to converge warning with either model.
– 42-
Mar 26 at 1:04
Yes.. The whole point is to create the proper mathematical environment for valid inference. I get the same failure to converge warning with either model.
– 42-
Mar 26 at 1:04
add a comment |
1 Answer
1
active
oldest
votes
No, all nesting (in the coding sense) does is create two terms, the first term alone and the interaction of the first and second term. And all an interaction needs to have is a unique identifier for each unique combination.
That is, A/B results in A + A:B, and if you had a third variable C which was, say, paste(A, B), then this would also be equivalent to A + C.
In your case, Condition/Group reduces to Condition + Condition:Group, which is equivalent to Condition + Group. So that's why your two models are not equivalent, the second includes a random effect for Condition and the first does not.
Referring back to my first sentence, it's important to distinguish between nesting in the design and nesting in the coding; in your case, Group is nested within Condition in the design sense, because each level of Condition is different for each Group, but you're enforcing that in the computer by giving each a unique identifier, so you don't need to nest in the code.
Thanks! So with the way these data are structured,Mod1 <- glmer(Present ~ Condition * Code + (1|Group), family=binomial(link = "logit"), data = Data)is sufficient?
– JLC
Mar 26 at 1:46
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348455%2fdo-i-need-to-specify-nested-random-effects-when-nesting-is-implicit-in-the-data%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
No, all nesting (in the coding sense) does is create two terms, the first term alone and the interaction of the first and second term. And all an interaction needs to have is a unique identifier for each unique combination.
That is, A/B results in A + A:B, and if you had a third variable C which was, say, paste(A, B), then this would also be equivalent to A + C.
In your case, Condition/Group reduces to Condition + Condition:Group, which is equivalent to Condition + Group. So that's why your two models are not equivalent, the second includes a random effect for Condition and the first does not.
Referring back to my first sentence, it's important to distinguish between nesting in the design and nesting in the coding; in your case, Group is nested within Condition in the design sense, because each level of Condition is different for each Group, but you're enforcing that in the computer by giving each a unique identifier, so you don't need to nest in the code.
Thanks! So with the way these data are structured,Mod1 <- glmer(Present ~ Condition * Code + (1|Group), family=binomial(link = "logit"), data = Data)is sufficient?
– JLC
Mar 26 at 1:46
add a comment |
No, all nesting (in the coding sense) does is create two terms, the first term alone and the interaction of the first and second term. And all an interaction needs to have is a unique identifier for each unique combination.
That is, A/B results in A + A:B, and if you had a third variable C which was, say, paste(A, B), then this would also be equivalent to A + C.
In your case, Condition/Group reduces to Condition + Condition:Group, which is equivalent to Condition + Group. So that's why your two models are not equivalent, the second includes a random effect for Condition and the first does not.
Referring back to my first sentence, it's important to distinguish between nesting in the design and nesting in the coding; in your case, Group is nested within Condition in the design sense, because each level of Condition is different for each Group, but you're enforcing that in the computer by giving each a unique identifier, so you don't need to nest in the code.
Thanks! So with the way these data are structured,Mod1 <- glmer(Present ~ Condition * Code + (1|Group), family=binomial(link = "logit"), data = Data)is sufficient?
– JLC
Mar 26 at 1:46
add a comment |
No, all nesting (in the coding sense) does is create two terms, the first term alone and the interaction of the first and second term. And all an interaction needs to have is a unique identifier for each unique combination.
That is, A/B results in A + A:B, and if you had a third variable C which was, say, paste(A, B), then this would also be equivalent to A + C.
In your case, Condition/Group reduces to Condition + Condition:Group, which is equivalent to Condition + Group. So that's why your two models are not equivalent, the second includes a random effect for Condition and the first does not.
Referring back to my first sentence, it's important to distinguish between nesting in the design and nesting in the coding; in your case, Group is nested within Condition in the design sense, because each level of Condition is different for each Group, but you're enforcing that in the computer by giving each a unique identifier, so you don't need to nest in the code.
No, all nesting (in the coding sense) does is create two terms, the first term alone and the interaction of the first and second term. And all an interaction needs to have is a unique identifier for each unique combination.
That is, A/B results in A + A:B, and if you had a third variable C which was, say, paste(A, B), then this would also be equivalent to A + C.
In your case, Condition/Group reduces to Condition + Condition:Group, which is equivalent to Condition + Group. So that's why your two models are not equivalent, the second includes a random effect for Condition and the first does not.
Referring back to my first sentence, it's important to distinguish between nesting in the design and nesting in the coding; in your case, Group is nested within Condition in the design sense, because each level of Condition is different for each Group, but you're enforcing that in the computer by giving each a unique identifier, so you don't need to nest in the code.
answered Mar 26 at 1:40
AaronAaron
30.5k4 gold badges59 silver badges116 bronze badges
30.5k4 gold badges59 silver badges116 bronze badges
Thanks! So with the way these data are structured,Mod1 <- glmer(Present ~ Condition * Code + (1|Group), family=binomial(link = "logit"), data = Data)is sufficient?
– JLC
Mar 26 at 1:46
add a comment |
Thanks! So with the way these data are structured,Mod1 <- glmer(Present ~ Condition * Code + (1|Group), family=binomial(link = "logit"), data = Data)is sufficient?
– JLC
Mar 26 at 1:46
Thanks! So with the way these data are structured,
Mod1 <- glmer(Present ~ Condition * Code + (1|Group), family=binomial(link = "logit"), data = Data) is sufficient?– JLC
Mar 26 at 1:46
Thanks! So with the way these data are structured,
Mod1 <- glmer(Present ~ Condition * Code + (1|Group), family=binomial(link = "logit"), data = Data) is sufficient?– JLC
Mar 26 at 1:46
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348455%2fdo-i-need-to-specify-nested-random-effects-when-nesting-is-implicit-in-the-data%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Yes.. The whole point is to create the proper mathematical environment for valid inference. I get the same failure to converge warning with either model.
– 42-
Mar 26 at 1:04