<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p><tt>Compartilho uma das soluções dada por:</tt></p>
    <pre wrap="">Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: <a class="moz-txt-link-abbreviated" href="mailto:pd.mes@cbs.dk">pd.mes@cbs.dk</a>  Priv: <a class="moz-txt-link-abbreviated" href="mailto:PDalgd@gmail.com">PDalgd@gmail.com</a>
</pre>
    <p><tt>Através da lista <a class="moz-txt-link-abbreviated" href="mailto:r-help@r-project.org">r-help@r-project.org</a>:</tt></p>
    <p><tt># CMR<br>
      </tt></p>
    <p><tt>pair <- c(1,1,2,2,3,3,4,4,5,5,6,6,7,7)  # identification</tt><tt><br>
      </tt><tt>treat <-  c(1,0,1,0,1,0,1,0,1,0,1,0,1,0) # treatament
        1 (A) or 0 (B)</tt><tt><br>
      </tt><tt>impr <-  c(1,0,1,0,1,0,0,1,0,1,0,0,1,1) # improvement
        1 (yes) 0 (no)</tt><tt><br>
      </tt><tt>treatfac <- factor(treat)</tt><tt><br>
      </tt><tt>levels(treatfac)<-list("A"=1,"B"=0 )</tt><tt><br>
      </tt><tt>imprfac <- factor(impr)</tt><tt><br>
      </tt><tt>levels(imprfac)<-list("+"=1,"-"=0)</tt><tt><br>
      </tt><tt><br>
      </tt><tt>dd<-data.frame(pair,treatfac,imprfac)</tt><tt><br>
      </tt><tt>dd</tt></p>
    <p><tt><br>
      </tt><tt>   pair treatfac imprfac</tt><tt><br>
      </tt><tt>1     1        A       +</tt><tt><br>
      </tt><tt>2     1        B       -</tt><tt><br>
      </tt><tt>3     2        A       +</tt><tt><br>
      </tt><tt>4     2        B       -</tt><tt><br>
      </tt><tt>5     3        A       +</tt><tt><br>
      </tt><tt>6     3        B       -</tt><tt><br>
      </tt><tt>7     4        A       -</tt><tt><br>
      </tt><tt>8     4        B       +</tt><tt><br>
      </tt><tt>9     5        A       -</tt><tt><br>
      </tt><tt>10    5        B       +</tt><tt><br>
      </tt><tt>11    6        A       -</tt><tt><br>
      </tt><tt>12    6        B       -</tt><tt><br>
      </tt><tt>13    7        A       +</tt><tt><br>
      </tt><tt>14    7        B       +</tt><tt><br>
      </tt></p>
    <p><tt># A solução<br>
      </tt></p>
    <p><tt># O segredo é rearrumar os dados primeiro:<br>
      </tt></p>
    <p><tt>ddw <- reshape(dd, direction="wide", idvar="pair",
        timevar="treatfac")</tt><tt><br>
      </tt><tt>ddw</tt><tt><br>
      </tt></p>
    <p><tt>   pair imprfac.A imprfac.B</tt><tt><br>
      </tt><tt>1     1         +         -</tt><tt><br>
      </tt><tt>3     2         +         -</tt><tt><br>
      </tt><tt>5     3         +         -</tt><tt><br>
      </tt><tt>7     4         -         +</tt><tt><br>
      </tt><tt>9     5         -         +</tt><tt><br>
      </tt><tt>11    6         -         -</tt><tt><br>
      </tt><tt>13    7         +         +</tt></p>
    <p><tt># Para em seguida, através da função xtabs (como mencionado
        anteriormente por Fernando)</tt><tt><br>
      </tt></p>
    <tt>xtabs(~ imprfac.A + imprfac.B, ddw)</tt><tt><br>
    </tt><tt><br>
      # Se obter o resultado desejado:<br>
      <br>
    </tt><tt>         imprfac.B</tt><tt><br>
    </tt><tt>imprfac.A + -</tt><tt><br>
    </tt><tt>        + 1 3</tt><tt><br>
    </tt><tt>        - 2 1</tt><tt><br>
    </tt><tt><br>
    </tt><tt>Maurício Cardeal<br>
      UFBA<br>
      <br>
    </tt>
    <div class="moz-cite-prefix"><tt>Em 07/04/2017 15:17, FHRB Toledo
        escreveu:</tt><tt><br>
      </tt></div>
    <blockquote
cite="mid:CAN55XP4NmaBdBrB=kYXJ1HPAUZQP5HR_gxBsPk7uBBg52Q4qvA@mail.gmail.com"
      type="cite">
      <div dir="ltr"><tt>help(xtabs)</tt><tt><br>
        </tt></div>
      <div class="gmail_extra"><tt><br>
        </tt>
        <div class="gmail_quote"><tt>2017-04-07 12:59 GMT-05:00 Mauricio
            Cardeal via R-br </tt><tt><span dir="ltr"><<a
                moz-do-not-send="true"
                href="mailto:r-br@listas.c3sl.ufpr.br" target="_blank">r-br@listas.c3sl.ufpr.br</a>></span></tt><tt>:</tt><tt><br>
          </tt>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex"><tt>Boa
              tarde!</tt><tt><br>
            </tt>
            <tt><br>
            </tt><tt>
              Por favor, como faço para construir uma tabela como a do
              modelo do final do script,</tt><tt><br>
            </tt>
            <tt><br>
            </tt><tt>
              onde o conteúdo das 4 caselas são contagens do número de
              pares que combinam</tt><tt><br>
            </tt>
            <tt><br>
            </tt><tt>
              melhora e não melhora de 2 tratamentos aplicados
              simultaneamente no mesmo</tt><tt><br>
            </tt>
            <tt><br>
            </tt><tt>
              individuo (perna direita e perna esquerda), por exemplo ?</tt><tt><br>
            </tt>
            <tt><br>
            </tt><tt>
              # CMR:</tt><tt><br>
            </tt>
            <tt><br>
            </tt><tt>
              par <- c(1,1,2,2,3,3,4,4,5,5,6,6,7,7)</tt><wbr><tt>  #
              refere-se ao número do individuo</tt><tt><br>
            </tt><tt>
              trata <-  c(1,0,1,0,1,0,1,0,1,0,1,0,1,0) # tratamento 1
              (A) ou 0 (B)</tt><tt><br>
            </tt><tt>
              melhora <-  c(1,0,1,0,1,0,0,1,0,1,0,0,1,1) # resultado
              do tratamento 1 (melhora) 0 (não melhora)</tt><tt><br>
            </tt><tt>
              tratac <- factor(trata)</tt><tt><br>
            </tt><tt>
              levels(tratac)<-list("A"=1,"B"</tt><wbr><tt>=0 )</tt><tt><br>
            </tt><tt>
              melhorac <- factor(melhora)</tt><tt><br>
            </tt><tt>
              levels(melhorac)<-list("+"=1,"</tt><wbr><tt>-"=0)</tt><tt><br>
            </tt>
            <tt><br>
            </tt><tt>
              data.frame(par,tratac,melhorac</tt><wbr><tt>)</tt><tt><br>
            </tt>
            <tt><br>
            </tt><tt>
                 par tratac melhorac</tt><tt><br>
            </tt><tt>
              1    1      A        +</tt><tt><br>
            </tt><tt>
              2    1      B        -</tt><tt><br>
            </tt><tt>
              3    2      A        +</tt><tt><br>
            </tt><tt>
              4    2      B        -</tt><tt><br>
            </tt><tt>
              5    3      A        +</tt><tt><br>
            </tt><tt>
              6    3      B        -</tt><tt><br>
            </tt><tt>
              7    4      A        -</tt><tt><br>
            </tt><tt>
              8    4      B        +</tt><tt><br>
            </tt><tt>
              9    5      A        -</tt><tt><br>
            </tt><tt>
              10   5      B        +</tt><tt><br>
            </tt><tt>
              11   6      A        -</tt><tt><br>
            </tt><tt>
              12   6      B        -</tt><tt><br>
            </tt><tt>
              13   7      A        +</tt><tt><br>
            </tt><tt>
              14   7      B        +</tt><tt><br>
            </tt>
            <tt><br>
            </tt><tt>
              # COMO FAÇO PARA GERAR ESSA TABELA A PARTIR DOS DADOS
              ACIMA?</tt><tt><br>
            </tt>
            <tt><br>
            </tt><tt>
              #                      tratamento B</tt><tt><br>
            </tt><tt>
              #                      melhora melhora</tt><tt><br>
            </tt><tt>
              #                         +       -</tt><tt><br>
            </tt><tt>
              #tratamento A melhora +   1       3</tt><tt><br>
            </tt><tt>
              #             melhora -   2       1</tt><tt><br>
            </tt>
            <tt><br>
            </tt><tt>
              Obrigado,</tt><tt><br>
            </tt>
            <tt><br>
            </tt><tt>
              Maurício Cardeal</tt><tt><br>
            </tt>
            <tt><br>
            </tt><tt>
              UFBA</tt><tt><br>
            </tt>
            <tt><br>
            </tt>
            <tt><br>
            </tt><tt>
              ______________________________</tt><wbr><tt>_________________</tt><tt><br>
            </tt><tt>
              R-br mailing list</tt><tt><br>
            </tt>
            <tt><a moz-do-not-send="true"
                href="mailto:R-br@listas.c3sl.ufpr.br" target="_blank">R-br@listas.c3sl.ufpr.br</a></tt><tt><br>
            </tt>
            <tt><a moz-do-not-send="true"
                href="https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br"
                rel="noreferrer" target="_blank">https://listas.inf.ufpr.br/cgi<wbr>-bin/mailman/listinfo/r-br</a></tt><tt><br>
            </tt><tt>
              Leia o guia de postagem (</tt><tt><a
                moz-do-not-send="true"
                href="http://www.leg.ufpr.br/r-br-guia" rel="noreferrer"
                target="_blank">http://www.leg.ufpr.br/r-br-g<wbr>uia</a></tt><tt>)
              e fornea cdigo mnimo reproduzvel.</tt></blockquote>
        </div>
        <tt><br>
        </tt></div>
    </blockquote>
    <tt><br>
    </tt>
  </body>
</html>