<div dir="ltr"><div><div>Se você possui 4 GL para o fator A e  4 GL para o fator B, como podem 
haver somente 1 GL para a interação? Acredito que por isso o R retorna <span id="gmail-m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133224">"there are aliased coefficients in the model". Uma vez que você não possui informações em todas as combinações dos fatores A e B. <br><br>with(dados,table(factorA,factorB))<br><br></span></div><span id="gmail-m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133224">Veja com um banco de dados completo e nos retorne<br><br><br></span></div><span id="gmail-m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133224">Att<br></span></div><div class="gmail_extra"><br><div class="gmail_quote">Em 21 de junho de 2017 11:23, Eduardo Bearzoti via R-br <span dir="ltr"><<a href="mailto:r-br@listas.c3sl.ufpr.br" target="_blank">r-br@listas.c3sl.ufpr.br</a>></span> escreveu:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="color:#000;background-color:#fff;font-family:Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_132816" dir="ltr"><span id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133224">Bom dia, pessoal.<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133123"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133124">Minha dúvida é particularmente sobre o cálculo de somas de quadrados tipo III (mas também do tipo II) no R com conjuntos de dados desbalanceados.<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133125"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133126">Estou ciente da polêmica em torno do uso destas somas de quadrados na comunidade estatística, mas gostaria muito de poder calculá-las no R, e, a não ser que eu esteja enganado, nem sempre o R as calcula corretamente.<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133127"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133128">Pesquisando na rede, descobri que em geral são apontadas duas maneiras de se calcular somas de quadrados tipo III no R: a) Utilizando a função drop1() em modelos ajustados com a especificação de contrastes contr.sum (ou contr.helmert), e b) utilizando a função Anova() (com "A" maiúsculo), do pacote car. <br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133129"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133130">Abaixo, eu apresento um exemplo simulado de um ensaio fatorial altamente desbalanceado, faltando várias combinações entre os níveis dos dois fatores. A interação entre eles, por exemplo, apresenta um único grau de liberdade, tamanho o desbalanceamento.<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133131"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133132">dados <- data.frame(y=c(35.44627,43.<wbr>43353,40.20125,38.1061,39.<wbr>96211,44.21636,19.78237,23.<wbr>58636,31.73537,<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133133">         36.49977,38.71573,41.00456,19.<wbr>6787,16.43436,32.05407,33.<wbr>3784,18.58266,17.74051),<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133134">         factorA=as.factor(c(2,2,4,4,4,<wbr>4,6,6,6,6,6,6,8,8,8,8,10,10)),<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133135">         factorB=as.factor(c(2,2,1.5,1.<wbr>5,2.5,2.5,1,1,2,2,3,3,1.5,1.5,<wbr>2.5,2.5,2,2)))<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133136"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133137">Tenho em mente o modelo contendo os fatores A e B, bem como sua interação. <br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133138"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133139">No SAS, utilizando o proc glm, obtenho as seguintes somas de quadrados tipo I, tipo II e tipo III:<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133140"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133141">Source                      DF       Type I SS<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133142"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133143">factorA                       4     964.4164933<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133144">factorB                       3     500.0771638<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133145">factorA*factorB               1      68.7277880<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133146"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133147">Source                      DF      Type II SS<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133148"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133149">factorA                       3     <a href="tel:(954)%20673-0970" value="+19546730970" target="_blank">954.6730970</a><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133150">factorB                       3     500.0771638<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133151">factorA*factorB               1      68.7277880<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133152"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133153">Source                      DF     Type III SS<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133154"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133155">factorA                       3     <a href="tel:(954)%20673-0970" value="+19546730970" target="_blank">954.6730970</a><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133156">factorB                       3     500.0771638<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133157">factorA*factorB               1      68.7277880<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133158"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133159">Percebam que neste exemplo as somas de quadrados tipo II e III são iguais, pois as "caselas" apresentam o mesmo número de repetições (duas).<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133160"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133161">No R, tentei reproduzir este resultado seguindo os dois procedimentos citados acima:<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133162"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133163">1) Utilizando a função drop1()<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133164"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133165">> mod <- lm(y ~ factorA*factorB, <br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133166">          contrasts=list(factorA=contr.<wbr>sum, factorB=contr.sum),<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133167">          data=dados)<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133168"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133169">> drop1(mod, ~.,test = "F")<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133170">Single term deletions<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133171"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133172">Model:<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133173">y ~ factorA * factorB<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133174">                Df Sum of Sq     RSS    AIC F value  Pr(>F)  <br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133175"><none>                        70.841 42.661                  <br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133176">factorA          0     0.000  70.841 42.661                  <br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133177">factorB          0     0.000  70.841 42.661                  <br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133178">factorA:factorB  1    68.728 139.569 52.867  8.7315 0.01609 *<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133179">---<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133180">Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133181"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133182">(apenas a soma de quadrados da interação foi calculada)<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133183"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133184"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133185">2) Utilizando car::Anova()<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133186"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133187">> mod <- lm(y ~ factorA*factorB, data=dados)<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133188">> library(car)<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133189">> Anova(mod,type = "II")<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133190">Anova Table (Type II tests)<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133191"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133192">Response: y<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133193">                 Sum Sq Df F value    Pr(>F)    <br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133194">factorA         1284.10  4 40.7845 8.995e-06 ***<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133195">factorB          500.08  3 21.1774 0.0002047 ***<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133196">factorA:factorB   68.73  1  8.7315 0.0160919 *  <br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133197">Residuals         70.84  9                      <br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133198">---<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133199">Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133200">> Anova(mod,type = "III")<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133201">Error in Anova.III.lm(mod, error, singular.ok = singular.ok, ...) : <br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133202">  there are aliased coefficients in the model</span></div><div dir="ltr" id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133297"><br><span id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133224"></span></div><div dir="ltr" id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133351"><span id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133224">(soma de quadrados tipo II calculada errada para o fator A, e tipo III não calculadas)<br></span></div><div dir="ltr"><span id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133224"><br></span></div><div dir="ltr" id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133353"><span id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133224">Ou seja, não consegui reproduzir nem as somas de quadrados tipo III nem as do tipo II, por nenhum dos dois procedimentos sugeridos na rede.<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133205"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133206">Estou utilizando:<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133207">> sessionInfo()<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133208">R version 3.4.0 (2017-04-21)<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133209">Platform: x86_64-pc-linux-gnu (64-bit)<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133210">Running under: Ubuntu 14.04.5 LTS<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133211">(...)<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133212">other attached packages:<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133213">[1] car_2.1-4<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133214"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133215"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133216"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133217">Eu estaria fazendo alguma coisa equivocada? Qualquer observação, sugestão, ou indicação de alguma maneira alternativa para cálculo das somas de quadrados tipo III no R será muito bem vinda.<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133218"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133219">Abs,<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133220"><br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133221">Eduardo Bearzoti<br id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_133222">(UFOP)</span></div><div id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_132877"> </div><div class="m_-6328446204165365820signature" id="m_-6328446204165365820yui_3_16_0_ym19_1_1498049847166_132878"><br></div></div></div><br>______________________________<wbr>_________________<br>
R-br mailing list<br>
<a href="mailto:R-br@listas.c3sl.ufpr.br">R-br@listas.c3sl.ufpr.br</a><br>
<a href="https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br" rel="noreferrer" target="_blank">https://listas.inf.ufpr.br/<wbr>cgi-bin/mailman/listinfo/r-br</a><br>
Leia o guia de postagem (<a href="http://www.leg.ufpr.br/r-br-guia" rel="noreferrer" target="_blank">http://www.leg.ufpr.br/r-br-<wbr>guia</a>) e forneça código mínimo reproduzível.<br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><span>=========================================<br>
Fernando Souza<br>
Zootecnista, DSc. Produção e Alimentação Animal<br>
Celular: (31)99796-8781 (Vivo)<br>
<a href="mailto:e-mail%3Anandodesouza@gmail.com" target="_blank">E-mail:nandodesouza@gmail.com</a><br>
Lattes: <a href="http://lattes.cnpq.br/6519538815038307" target="_blank">http://lattes.cnpq.br/6519538815038307</a><br>
Blog: <a href="https://producaoanimalcomr.wordpress.com/" target="_blank">https://producaoanimalcomr.wordpress.com/</a><br>
==========================================</span></div></div></div></div></div></div></div></div></div></div>
</div>