[R-sig-ME] Reducing two mixed models into one

João Veríssimo j|@ver|@@|mo @end|ng |rom gm@||@com
Tue Jun 13 19:00:55 CEST 2023


Hi Timothy,

The formula I've suggested before is identical to the first 
parametrization in Thierry's answer, i.e., writing "item_num / 
Condition" is the same as writing "item_num + item_num:Condition".
That parametrization gives you estimates for the Condition slopes 
separately for each level of item_num. So the correlation between the 
corresponding by-subject random slopes is (I believe) what you want:

> d <- read.csv("https://raw.githubusercontent.com/fpqq/w/main/d3.csv") > 
model_1 <- lmer(I(-1000/RT) ~ item_num / Condition + (item_num / 
Condition|Subject) + (item_num / Condition|Item), data = d)> re.corrs <- 
attr(VarCorr(model_1)$Subject, "correlation") > 
re.corrs["item_numEven:Conditionunrelated", 
"item_numOdd:Conditionunrelated"] [1] 0.9499885


João

On 13/06/2023 18:36, Timothy MacKenzie wrote:
> Dear Thierry,
>
> Thank you so much for your highly informative answer. If I may, I
> wanted to ask a follow-up question.
>
> Previously, from the two separate models, I used to compute a
> correlation (0.849635) between the random slopes of subjects in
> 'Condition==unrelated' for Odd vs. Even items (shown below).
>
> **Question: Could we obtain the latent equivalent of the above
> correlation (which may not be numerically the same as 0.849635) from
> `attr(VarCorr(First_Parametrization_Model)$Subject, "correlation")`?
>
> Thank you so much again,
> Tim M
>
> ranef_model_2_even = data.frame(ranef(model_2)$Subject)
> ranef_model_2_even$Subject <- row.names(ranef_model_2_even)
> ranef_model_3_odd = data.frame(ranef(model_3)$Subject)
> ranef_model_3_odd$Subject <- row.names(ranef_model_3_odd)
>
> Subject = merge(ranef_model_2_even, ranef_model_3_odd, by = "Subject",
> suffixes = c("_even", "_odd"))
> cor(Subject$Conditionunrelated_even, Subject $Conditionunrelated_odd)
> #  [1] 0.849635
>
>
>
>
>
> On Mon, Jun 12, 2023 at 1:36 AM Thierry Onkelinx
> <thierry.onkelinx using inbo.be>  wrote:
>> Dear Timothy,
>>
>> Add the interaction with item_num to every parameter and you should have the same parameterization for both models in a single model.
>>
>> # gives similar parameters as both models
>> I(-1/RT) ~ item_num + item_num:Condition + (item_num + item_num:Condition|Subject) + (item_num + item_num:Condition|Item)
>> # same model fit, different parametrization
>> I(-1/RT) ~ item_num*Condition + (item_num*Condition|Subject) + (item_num*Condition|Item)
>>
>> Best regards,
>>
>> ir. Thierry Onkelinx
>> Statisticus / Statistician
>>
>> Vlaamse Overheid / Government of Flanders
>> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND FOREST
>> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
>> thierry.onkelinx using inbo.be
>> Havenlaan 88 bus 73, 1000 Brussel
>> www.inbo.be
>>
>> ///////////////////////////////////////////////////////////////////////////////////////////
>> To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
>> The plural of anecdote is not data. ~ Roger Brinner
>> The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey
>> ///////////////////////////////////////////////////////////////////////////////////////////
>>
>>
>>
>>
>> Op za 10 jun 2023 om 19:06 schreef Timothy MacKenzie<fswfswt using gmail.com>:
>>> Hello All,
>>>
>>> I'm hoping to clarify my prior post to elicit an informative response
>>> from the experts on the list.
>>>
>>> Currently, I'm running two models each using a subset of my data (below).
>>>
>>> <Question>: Instead of running two separate models, is it possible to
>>> create one model that captures both these separate models?
>>>
>>> Thank you,
>>> Tim M
>>> ################
>>> d = read.csv("https://raw.githubusercontent.com/fpqq/w/main/d3.csv")
>>> library(optimx)
>>> library(blme)
>>>
>>> # Subset 1:
>>> model_2 = blmer(I(-1/RT) ~ Condition + (Condition|Subject) + (Condition|Item),
>>> data = d, control=lmerControl(optimizer="optimx",optCtrl=list(method="nlminb")),
>>>             subset = item_num == "Even")
>>>
>>> # Subset 2:
>>> model_3 = blmer(I(-1/RT) ~ Condition + (Condition|Subject) + (Condition|Item),
>>> data = d, control=lmerControl(optimizer="optimx",optCtrl=list(method="nlminb")),
>>>               subset = item_num == "Odd")
>>>
>>> _______________________________________________
>>> R-sig-mixed-models using r-project.org  mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> _______________________________________________
> R-sig-mixed-models using r-project.org  mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models

	[[alternative HTML version deleted]]



More information about the R-sig-mixed-models mailing list