<?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 Why does SLS (REML) give a different intercept than Python statsmodels for the same mixed model? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Why-does-SLS-REML-give-a-different-intercept-than-Python/m-p/946201#M109690</link>
    <description>&lt;P&gt;I fitted:&lt;/P&gt;
&lt;DIV class="code" data-code="id#13845"&gt;
&lt;DIV class="interactive-result-code-block no-vulns" data-keybinding-context="108"&gt;
&lt;DIV class="interactive-result-editor" data-mode-id="plaintext" data-keybinding-context="109"&gt;
&lt;DIV class="monaco-editor no-user-select  showUnused showDeprecated vs-dark" role="code" data-uri="vscode-chat-code-block://dnnjb2rllwnoyxqtc2vzc2lvbjovl2xvy2fsl01ewmhzelkzwlrrde5qqm1zetawtvrnnexxstnnr1l0tm1rnu9xtmlovgcwwlroba/response_e163a2f0-e7f3-49b7-8004-94c37d692fca/0#%7B%22references%22%3A%5B%5D%7D"&gt;
&lt;DIV class="overflow-guard" data-mprt="3"&gt;
&lt;DIV class="native-edit-context" tabindex="0" role="textbox" spellcheck="false" aria-label="The editor is not accessible at this time. To enable screen reader optimized mode, use Shift+Alt+F1" aria-roledescription="editor" aria-autocomplete="none" aria-multiline="true" aria-required="false"&gt;&lt;STRONG&gt;Y ~ A(Sum) + B(Sum) + C(Sum) + D(Sum) + Subject(&amp;amp;Random)&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV class="native-edit-context" tabindex="0" role="textbox" spellcheck="false" aria-label="The editor is not accessible at this time. To enable screen reader optimized mode, use Shift+Alt+F1" aria-roledescription="editor" aria-autocomplete="none" aria-multiline="true" aria-required="false"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;SPAN&gt;in both JMP SLS (REML) and Python statsmodels MixedLM (REML) on the same data (~14k obs, ~200 levels of A, sparse A×C cross-tabulation, ~120 random subjects).&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;STRONG&gt;What I observe:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;All ~200 LS Means for factor A are shifted by a constant ~0.22 (JMP higher)&lt;/LI&gt;
&lt;LI&gt;Relative effects and rankings are identical (diff std &amp;lt; 0.001)&lt;/LI&gt;
&lt;LI&gt;LS Means for different factors in JMP have&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;different grand means&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(A → 78.5, B/D → 73.0), which shouldn't happen with Sum coding&lt;/LI&gt;
&lt;LI&gt;A different Y on the same X gives essentially no offset (0.006)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;What I need help with:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Is there a known reason why JMP's SLS personality (REML) would produce a different intercept than standard GLS β̂ = (X'V⁻¹X)⁻¹X'V⁻¹y? Is SLS using a different algorithm than the Mixed Model personality for computing fixed effects or LS Means?&lt;/P&gt;
&lt;P&gt;JMP Pro 17, Windows.&lt;/P&gt;</description>
    <pubDate>Wed, 06 May 2026 12:48:18 GMT</pubDate>
    <dc:creator>xmq</dc:creator>
    <dc:date>2026-05-06T12:48:18Z</dc:date>
    <item>
      <title>Why does SLS (REML) give a different intercept than Python statsmodels for the same mixed model?</title>
      <link>https://community.jmp.com/t5/Discussions/Why-does-SLS-REML-give-a-different-intercept-than-Python/m-p/946201#M109690</link>
      <description>&lt;P&gt;I fitted:&lt;/P&gt;
&lt;DIV class="code" data-code="id#13845"&gt;
&lt;DIV class="interactive-result-code-block no-vulns" data-keybinding-context="108"&gt;
&lt;DIV class="interactive-result-editor" data-mode-id="plaintext" data-keybinding-context="109"&gt;
&lt;DIV class="monaco-editor no-user-select  showUnused showDeprecated vs-dark" role="code" data-uri="vscode-chat-code-block://dnnjb2rllwnoyxqtc2vzc2lvbjovl2xvy2fsl01ewmhzelkzwlrrde5qqm1zetawtvrnnexxstnnr1l0tm1rnu9xtmlovgcwwlroba/response_e163a2f0-e7f3-49b7-8004-94c37d692fca/0#%7B%22references%22%3A%5B%5D%7D"&gt;
&lt;DIV class="overflow-guard" data-mprt="3"&gt;
&lt;DIV class="native-edit-context" tabindex="0" role="textbox" spellcheck="false" aria-label="The editor is not accessible at this time. To enable screen reader optimized mode, use Shift+Alt+F1" aria-roledescription="editor" aria-autocomplete="none" aria-multiline="true" aria-required="false"&gt;&lt;STRONG&gt;Y ~ A(Sum) + B(Sum) + C(Sum) + D(Sum) + Subject(&amp;amp;Random)&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV class="native-edit-context" tabindex="0" role="textbox" spellcheck="false" aria-label="The editor is not accessible at this time. To enable screen reader optimized mode, use Shift+Alt+F1" aria-roledescription="editor" aria-autocomplete="none" aria-multiline="true" aria-required="false"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;SPAN&gt;in both JMP SLS (REML) and Python statsmodels MixedLM (REML) on the same data (~14k obs, ~200 levels of A, sparse A×C cross-tabulation, ~120 random subjects).&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;STRONG&gt;What I observe:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;All ~200 LS Means for factor A are shifted by a constant ~0.22 (JMP higher)&lt;/LI&gt;
&lt;LI&gt;Relative effects and rankings are identical (diff std &amp;lt; 0.001)&lt;/LI&gt;
&lt;LI&gt;LS Means for different factors in JMP have&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;different grand means&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(A → 78.5, B/D → 73.0), which shouldn't happen with Sum coding&lt;/LI&gt;
&lt;LI&gt;A different Y on the same X gives essentially no offset (0.006)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;What I need help with:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Is there a known reason why JMP's SLS personality (REML) would produce a different intercept than standard GLS β̂ = (X'V⁻¹X)⁻¹X'V⁻¹y? Is SLS using a different algorithm than the Mixed Model personality for computing fixed effects or LS Means?&lt;/P&gt;
&lt;P&gt;JMP Pro 17, Windows.&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2026 12:48:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Why-does-SLS-REML-give-a-different-intercept-than-Python/m-p/946201#M109690</guid>
      <dc:creator>xmq</dc:creator>
      <dc:date>2026-05-06T12:48:18Z</dc:date>
    </item>
    <item>
      <title>Re: Why does SLS (REML) give a different intercept than Python statsmodels for the same mixed model?</title>
      <link>https://community.jmp.com/t5/Discussions/Why-does-SLS-REML-give-a-different-intercept-than-Python/m-p/946240#M109691</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/98859"&gt;@xmq&lt;/a&gt;&amp;nbsp;, and welcome! Can you show the pertinent output from each please? It will help folks here diagnose what might be going on; I have a few thoughts but I don't want us to get ahead of ourselves.&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2026 15:21:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Why-does-SLS-REML-give-a-different-intercept-than-Python/m-p/946240#M109691</guid>
      <dc:creator>MRB3855</dc:creator>
      <dc:date>2026-05-06T15:21:45Z</dc:date>
    </item>
    <item>
      <title>Re: Why does SLS (REML) give a different intercept than Python statsmodels for the same mixed model?</title>
      <link>https://community.jmp.com/t5/Discussions/Why-does-SLS-REML-give-a-different-intercept-than-Python/m-p/946248#M109692</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/7073"&gt;@MRB3855&lt;/a&gt;&amp;nbsp;, thanks for your reply!&lt;BR /&gt;&lt;BR /&gt;Here shares my dataset and JMP/Python scripts and outputs for checking,&lt;/P&gt;
&lt;P&gt;For JMP&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Fit Model(
	Y( :Y1 ),
	Effects( :A, :B, :C, :D ),
	Random Effects( :Subject ),
	NoBounds( 1 ),
	Personality( "Standard Least Squares" ),
	Method( "REML" ),
	Emphasis( "Effect Leverage" ),
	Run(
		:Y1 &amp;lt;&amp;lt; {Summary of Fit( 1 ), Analysis of Variance( 0 ),
		Parameter Estimates( 1 ), Scaled Estimates( 0 ),
		Plot Actual by Predicted( 0 ), Plot Regression( 0 ),
		Plot Residual by Predicted( 0 ), Plot Studentized Residuals( 0 ),
		Plot Effect Leverage( 0 ), Plot Residual by Normal Quantiles( 0 ),
		{:A &amp;lt;&amp;lt; {LSMeans Student's t( 0.05 )}}}
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;For Python&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;def fit_model(df, y_col):
    """Fit Y ~ A(Sum) + B(Sum) + C(Sum) + D(Sum) + (1|Subject) via REML."""
    # Note: column "C" conflicts with patsy's C() function,
    # so we temporarily rename it for formula construction.
    df_tmp = df.rename(columns={'C': '_C_'})
    formula = '1 + C(A, Sum) + C(B, Sum) + C(_C_, Sum) + C(D, Sum)'
    X_mat = dmatrix(formula, df_tmp)
    design_info = X_mat.design_info
    X = pd.DataFrame(np.asarray(X_mat), columns=design_info.column_names)
    y = df[y_col].values
    groups = df['Subject']

    model = MixedLM(y, X, groups=groups)
    result = model.fit(reml=True, method='powell')
    return result, X, design_info, df_tmp


def compute_lsmeans_A(result, X, df_tmp, design_info):
    """Compute LS Means for factor A (Sum coding → intercept + effect)."""
    fe = result.fe_params.values
    n_fe = len(fe)
    col_names = list(X.columns)

    target_prefix = 'C(A, Sum)'
    target_col_idx = [i for i, c in enumerate(col_names) if target_prefix in c]

    base_contrast = np.zeros(n_fe)
    base_contrast[0] = 1.0  # intercept

    levels = sorted(df_tmp['A'].unique())
    lsmeans = {}

    for level in levels:
        sr = df_tmp.iloc[0:1].copy()
        sr['A'] = level
        X_single = np.asarray(build_design_matrices([design_info], sr)[0])
        c = base_contrast.copy()
        for idx in target_col_idx:
            c[idx] = X_single[0, idx]
        lsmeans[level] = float(c @ fe)

    return lsmeans&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;I'd appreciate any comments/suggestions you might have.&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2026 16:31:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Why-does-SLS-REML-give-a-different-intercept-than-Python/m-p/946248#M109692</guid>
      <dc:creator>xmq</dc:creator>
      <dc:date>2026-05-06T16:31:52Z</dc:date>
    </item>
  </channel>
</rss>

