<?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 Can SAS LSMEANS algorithm be translated for a design matrix in Reference coding? in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Can-SAS-LSMEANS-algorithm-be-translated-for-a-design-matrix-in/m-p/625473#M30108</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is whether it’s possible to compute lsmeans defined in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/statug/63962/HTML/default/viewer.htm#statug_glm_a0000000871.htm" target="_blank" rel="nofollow noopener noreferrer"&gt;this SAS algorithm&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if the design matrix is not in GLM form. In particular, in R, if one feeds that design to model.matrix(), then Reference coding is used, so A will occupy 2 columns, B will occupy 1 column, A*B will occupy 2 columns, and C will take 1 column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The meaning of columns in GLM and Ref coding is quite different. For instance, if we have just one factor with two levels, A1 and A2, then in GLM format the intercept corresponds to the response averaged over A1 and A2, but in Ref the intercept corresponds to response at A1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apparently, the column space of GLM and Ref is the same, so I wonder if there is a way to represent each GLM column as a linear combination of Ref columns. In that case, one could take the LSM vector defined in GLM terms and apply it to a model fitted in Ref coding. Likewise, a contrast vector can be set as a difference of two LSM vectors and then estimated in Ref coding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know there are some R packages, like "contrast" that can take a fitted model in Ref coding and a contrast or lsmeans specification in string format, like "LSM(A1, B1)" or "A1 vs A2". However, here I am interested in a more specific solution that assumes we have already implemented the SAS algorithm for LSM vector. I am looking for a GLM-&amp;gt;Ref "adapter" of sorts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;James&lt;/P&gt;</description>
    <pubDate>Tue, 18 Feb 2020 16:23:47 GMT</pubDate>
    <dc:creator>JamesLin</dc:creator>
    <dc:date>2020-02-18T16:23:47Z</dc:date>
    <item>
      <title>Can SAS LSMEANS algorithm be translated for a design matrix in Reference coding?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Can-SAS-LSMEANS-algorithm-be-translated-for-a-design-matrix-in/m-p/625473#M30108</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is whether it’s possible to compute lsmeans defined in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/statug/63962/HTML/default/viewer.htm#statug_glm_a0000000871.htm" target="_blank" rel="nofollow noopener noreferrer"&gt;this SAS algorithm&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if the design matrix is not in GLM form. In particular, in R, if one feeds that design to model.matrix(), then Reference coding is used, so A will occupy 2 columns, B will occupy 1 column, A*B will occupy 2 columns, and C will take 1 column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The meaning of columns in GLM and Ref coding is quite different. For instance, if we have just one factor with two levels, A1 and A2, then in GLM format the intercept corresponds to the response averaged over A1 and A2, but in Ref the intercept corresponds to response at A1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apparently, the column space of GLM and Ref is the same, so I wonder if there is a way to represent each GLM column as a linear combination of Ref columns. In that case, one could take the LSM vector defined in GLM terms and apply it to a model fitted in Ref coding. Likewise, a contrast vector can be set as a difference of two LSM vectors and then estimated in Ref coding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know there are some R packages, like "contrast" that can take a fitted model in Ref coding and a contrast or lsmeans specification in string format, like "LSM(A1, B1)" or "A1 vs A2". However, here I am interested in a more specific solution that assumes we have already implemented the SAS algorithm for LSM vector. I am looking for a GLM-&amp;gt;Ref "adapter" of sorts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;James&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 16:23:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Can-SAS-LSMEANS-algorithm-be-translated-for-a-design-matrix-in/m-p/625473#M30108</guid>
      <dc:creator>JamesLin</dc:creator>
      <dc:date>2020-02-18T16:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: Can SAS LSMEANS algorithm be translated for a design matrix in Reference coding?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Can-SAS-LSMEANS-algorithm-be-translated-for-a-design-matrix-in/m-p/625605#M30111</link>
      <description>&lt;P&gt;Reference parameterization (PARAM=REF option) is just a nonsingular (full-rank) version of GLM parameterization (PARAM=GLM option). The unrestricted parameters (those not constrained to zero) using GLM parameterization are the same as the parameters using reference parameterization and have the same interpretation. In your example, the intercept estimate from both parameterizations is the same and is interpreted as the effect at A2 (by default). And the interpretation of the A1 parameter is the difference in effect of the A1 and A2 levels under both parameterizations. See &lt;A href="https://go.documentation.sas.com/?docsetId=statug&amp;amp;docsetTarget=statug_introcom_sect012.htm&amp;amp;docsetVersion=15.1&amp;amp;locale=en" target="_self"&gt;this section&lt;/A&gt; on the available parameterizations for more.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 14:28:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Can-SAS-LSMEANS-algorithm-be-translated-for-a-design-matrix-in/m-p/625605#M30111</guid>
      <dc:creator>StatDave</dc:creator>
      <dc:date>2020-02-18T14:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: Can SAS LSMEANS algorithm be translated for a design matrix in Reference coding?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Can-SAS-LSMEANS-algorithm-be-translated-for-a-design-matrix-in/m-p/625631#M30112</link>
      <description>A nice point is that in R, model.matrix() will not use the same reference level as REF option in SAS. For a factor with levels A1 and A2, R will use A1 as reference and SAS will use A2. &lt;BR /&gt;&lt;BR /&gt;So, the question is how to represent each column of GLM matrix as a linear combination of columns from Ref matrix. I suspect one should solve a certain linear system for that (apparently, the answer will depend on what level is used for reference).</description>
      <pubDate>Tue, 18 Feb 2020 16:29:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Can-SAS-LSMEANS-algorithm-be-translated-for-a-design-matrix-in/m-p/625631#M30112</guid>
      <dc:creator>JamesLin</dc:creator>
      <dc:date>2020-02-18T16:29:12Z</dc:date>
    </item>
  </channel>
</rss>

