<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How can I control for convergence in Proc Glimmix procedure for linear mixed models? in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/How-can-I-control-for-convergence-in-Proc-Glimmix-procedure-for/m-p/944356#M47163</link>
    <description>&lt;P&gt;I am working on a linear mixed model to compare results in SAS proc glimmix (or equivalently proc mixed) and CRAN R lme4 package. My challenge is: How do I manipulate the SAS code to get similar (approximately equal) F-ratios for the analysis of variance in SAS and R?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to control for convergence in SAS (see code), but I need help to finetune that SAS code to get the degrees of freedom and/or F-ratio that match those i get in R.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data extract (1st 5 observations):&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lyson_0-1726644044959.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100468iB53AB509F86937C5/image-size/large?v=v2&amp;amp;px=999" role="button" title="Lyson_0-1726644044959.png" alt="Lyson_0-1726644044959.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Here is my SAS code:&lt;/P&gt;
&lt;PRE&gt;proc glimmix data=BarleyGroups outdesign=XZ  ;&lt;BR /&gt;class factorA factorB  groupA groupB switchA switchB  ;&lt;BR /&gt;model yield=  groupA|groupB / ddfm=kr;&lt;BR /&gt;random groupA*factorA*switchA; &lt;BR /&gt;random groupA*groupB*factorB*switchB; &lt;BR /&gt;random groupB*factorB*switchB;&lt;BR /&gt;random groupB*groupA*factorA*switchA;&lt;BR /&gt;random groupA*factorA*switchA*groupB*factorB*switchB;&lt;BR /&gt;parms (0.0000) (0.0000) (0.0000) (0.0000) (0.07074)  (0.41458);&lt;BR /&gt;nloptions maxiter=1000 maxfunc=10000  xconv=1e-5 gconv=1e-5 technique=nmsimp;&lt;BR /&gt;lsmeans  groupA|groupB / lines ;&lt;BR /&gt;Title "Linear Mixed Model with Convergence";&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;Here is my SAS output from the code above:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lyson_1-1726644198940.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100469iFA0C570E23B6A85A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Lyson_1-1726644198940.png" alt="Lyson_1-1726644198940.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lyson_2-1726644282675.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100470i00DFD0B44B3B089D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Lyson_2-1726644282675.png" alt="Lyson_2-1726644282675.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;**********************************************************************************************************************&lt;/P&gt;
&lt;P&gt;Here is my R code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;# Load necessary libraries&lt;BR /&gt;library(lme4)&lt;BR /&gt;library(emmeans)&lt;BR /&gt;library(lmerTest) # Provides Type III tests for fixed effects&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;control_settings &amp;lt;- lmerControl(&lt;BR /&gt;optimizer = "Nelder_Mead", # Use Nelder-Mead optimizer&lt;BR /&gt;optCtrl = list(maxfun = 10000), # Set maximum number of function evaluations&lt;BR /&gt;check.conv.grad = .makeCC(action = "warning", tol = 1e-5), # Gradient convergence check&lt;BR /&gt;check.conv.singular = .makeCC(action = "warning", tol = 1e-5) # Singular fit check&lt;BR /&gt;)&lt;BR /&gt;Full.mod&amp;lt;-lmer(Yield~groupA+ groupB+groupA:groupB+ &lt;BR /&gt;(1 | groupA:factorA:switchA) + &lt;BR /&gt;(1 | groupB:factorB:switchB) +&lt;BR /&gt;(1 | groupA:groupB:factorB:switchB) + &lt;BR /&gt;(1 | groupB:groupA:factorA:switchA)+&lt;BR /&gt;(1|groupA:factorA:switchA:groupB:factorB:switchB), &lt;BR /&gt;data = BarleyGroups, &lt;BR /&gt;control = control_settings)&lt;BR /&gt;summary(Full.mod)&lt;BR /&gt;anova(Full.mod, type=3, ddf = "Kenward-Roger")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the R output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lyson_3-1726644718013.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100471i35A01C118F0C0C96/image-size/large?v=v2&amp;amp;px=999" role="button" title="Lyson_3-1726644718013.png" alt="Lyson_3-1726644718013.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE id="rstudio_console_output" class="GNVWDDMDL3B" tabindex="0" role="document" aria-label="Console Output"&gt;&lt;SPAN class="GNVWDDMDM3B"&gt;&lt;SPAN class="GNVWDDMDC4B ace_keyword"&gt;&amp;gt; &lt;/SPAN&gt;&lt;SPAN class="GNVWDDMDB3B ace_keyword"&gt;anova(Full.mod, type=3, ddf = "Kenward-Roger")
&lt;/SPAN&gt;&lt;SPAN class="GNVWDDMDL3B"&gt;Type III Analysis of Variance Table with Kenward-Roger's method
               Sum Sq Mean Sq NumDF  DenDF F value Pr(&amp;gt;F)
groupA        0.08694 0.04347     2 4.5808  0.1040 0.9033
groupB        1.51768 0.50589     3 5.5396  1.2056 0.3905
groupA:groupB 1.38705 0.23118     6 7.9107  0.5506 0.7585&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;**************************************************************************************************************************************&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Sep 2024 08:05:45 GMT</pubDate>
    <dc:creator>Lyson</dc:creator>
    <dc:date>2024-09-18T08:05:45Z</dc:date>
    <item>
      <title>How can I control for convergence in Proc Glimmix procedure for linear mixed models?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-can-I-control-for-convergence-in-Proc-Glimmix-procedure-for/m-p/944356#M47163</link>
      <description>&lt;P&gt;I am working on a linear mixed model to compare results in SAS proc glimmix (or equivalently proc mixed) and CRAN R lme4 package. My challenge is: How do I manipulate the SAS code to get similar (approximately equal) F-ratios for the analysis of variance in SAS and R?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to control for convergence in SAS (see code), but I need help to finetune that SAS code to get the degrees of freedom and/or F-ratio that match those i get in R.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data extract (1st 5 observations):&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lyson_0-1726644044959.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100468iB53AB509F86937C5/image-size/large?v=v2&amp;amp;px=999" role="button" title="Lyson_0-1726644044959.png" alt="Lyson_0-1726644044959.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Here is my SAS code:&lt;/P&gt;
&lt;PRE&gt;proc glimmix data=BarleyGroups outdesign=XZ  ;&lt;BR /&gt;class factorA factorB  groupA groupB switchA switchB  ;&lt;BR /&gt;model yield=  groupA|groupB / ddfm=kr;&lt;BR /&gt;random groupA*factorA*switchA; &lt;BR /&gt;random groupA*groupB*factorB*switchB; &lt;BR /&gt;random groupB*factorB*switchB;&lt;BR /&gt;random groupB*groupA*factorA*switchA;&lt;BR /&gt;random groupA*factorA*switchA*groupB*factorB*switchB;&lt;BR /&gt;parms (0.0000) (0.0000) (0.0000) (0.0000) (0.07074)  (0.41458);&lt;BR /&gt;nloptions maxiter=1000 maxfunc=10000  xconv=1e-5 gconv=1e-5 technique=nmsimp;&lt;BR /&gt;lsmeans  groupA|groupB / lines ;&lt;BR /&gt;Title "Linear Mixed Model with Convergence";&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;Here is my SAS output from the code above:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lyson_1-1726644198940.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100469iFA0C570E23B6A85A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Lyson_1-1726644198940.png" alt="Lyson_1-1726644198940.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lyson_2-1726644282675.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100470i00DFD0B44B3B089D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Lyson_2-1726644282675.png" alt="Lyson_2-1726644282675.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;**********************************************************************************************************************&lt;/P&gt;
&lt;P&gt;Here is my R code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;# Load necessary libraries&lt;BR /&gt;library(lme4)&lt;BR /&gt;library(emmeans)&lt;BR /&gt;library(lmerTest) # Provides Type III tests for fixed effects&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;control_settings &amp;lt;- lmerControl(&lt;BR /&gt;optimizer = "Nelder_Mead", # Use Nelder-Mead optimizer&lt;BR /&gt;optCtrl = list(maxfun = 10000), # Set maximum number of function evaluations&lt;BR /&gt;check.conv.grad = .makeCC(action = "warning", tol = 1e-5), # Gradient convergence check&lt;BR /&gt;check.conv.singular = .makeCC(action = "warning", tol = 1e-5) # Singular fit check&lt;BR /&gt;)&lt;BR /&gt;Full.mod&amp;lt;-lmer(Yield~groupA+ groupB+groupA:groupB+ &lt;BR /&gt;(1 | groupA:factorA:switchA) + &lt;BR /&gt;(1 | groupB:factorB:switchB) +&lt;BR /&gt;(1 | groupA:groupB:factorB:switchB) + &lt;BR /&gt;(1 | groupB:groupA:factorA:switchA)+&lt;BR /&gt;(1|groupA:factorA:switchA:groupB:factorB:switchB), &lt;BR /&gt;data = BarleyGroups, &lt;BR /&gt;control = control_settings)&lt;BR /&gt;summary(Full.mod)&lt;BR /&gt;anova(Full.mod, type=3, ddf = "Kenward-Roger")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the R output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lyson_3-1726644718013.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100471i35A01C118F0C0C96/image-size/large?v=v2&amp;amp;px=999" role="button" title="Lyson_3-1726644718013.png" alt="Lyson_3-1726644718013.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE id="rstudio_console_output" class="GNVWDDMDL3B" tabindex="0" role="document" aria-label="Console Output"&gt;&lt;SPAN class="GNVWDDMDM3B"&gt;&lt;SPAN class="GNVWDDMDC4B ace_keyword"&gt;&amp;gt; &lt;/SPAN&gt;&lt;SPAN class="GNVWDDMDB3B ace_keyword"&gt;anova(Full.mod, type=3, ddf = "Kenward-Roger")
&lt;/SPAN&gt;&lt;SPAN class="GNVWDDMDL3B"&gt;Type III Analysis of Variance Table with Kenward-Roger's method
               Sum Sq Mean Sq NumDF  DenDF F value Pr(&amp;gt;F)
groupA        0.08694 0.04347     2 4.5808  0.1040 0.9033
groupB        1.51768 0.50589     3 5.5396  1.2056 0.3905
groupA:groupB 1.38705 0.23118     6 7.9107  0.5506 0.7585&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;**************************************************************************************************************************************&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 08:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-can-I-control-for-convergence-in-Proc-Glimmix-procedure-for/m-p/944356#M47163</guid>
      <dc:creator>Lyson</dc:creator>
      <dc:date>2024-09-18T08:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: How can I control for convergence in Proc Glimmix procedure for linear mixed models?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-can-I-control-for-convergence-in-Proc-Glimmix-procedure-for/m-p/944461#M47178</link>
      <description>&lt;P&gt;The fact that the standard errors for the covariance parameters are missing indicates that there are convergence issues with your program. I would take care of that first before trying to compare the results with anything else.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might start with simplifying your model first. For example, start with simpler random effects. Also try different values for the PARMS statement if necessary. Your NLOPTIONS statement seems to be relaxing the convergence criteria too much. I would try not to have that statement to begin with.&lt;/P&gt;
&lt;P&gt;Good luck,&lt;/P&gt;
&lt;P&gt;Jill&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 15:46:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-can-I-control-for-convergence-in-Proc-Glimmix-procedure-for/m-p/944461#M47178</guid>
      <dc:creator>jiltao</dc:creator>
      <dc:date>2024-09-18T15:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: How can I control for convergence in Proc Glimmix procedure for linear mixed models?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-can-I-control-for-convergence-in-Proc-Glimmix-procedure-for/m-p/945138#M47226</link>
      <description>Hi Jiltao&lt;BR /&gt;&lt;BR /&gt;Thanks for the response and advice, I am busy trying that one. Convergence&lt;BR /&gt;is what I really want to achieve, with reasonable standard errors&lt;BR /&gt;reflecting on the output. My model is trying to combine all random effects&lt;BR /&gt;into one model, that is the main objective. So I am not quite sure if there&lt;BR /&gt;is another approach of forcing this model to behave well without&lt;BR /&gt;necessarily simplifying it (excluding other random effects).&lt;BR /&gt;</description>
      <pubDate>Wed, 25 Sep 2024 05:37:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-can-I-control-for-convergence-in-Proc-Glimmix-procedure-for/m-p/945138#M47226</guid>
      <dc:creator>Lyson</dc:creator>
      <dc:date>2024-09-25T05:37:38Z</dc:date>
    </item>
  </channel>
</rss>

