Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One thing is how to convert your data. Another is why. From <code>?glm</code>: "[f]or binomial [...] famil[y] the response can [...] be specified as a factor (when the first level denotes failure and all others success) or as a two-column matrix with the columns giving the numbers of successes and failures.". The first way corresponds to your "R's glm wants a dataframe of 2046 rows each reporting a TRUE or FALSE conversion". The second way basically corresponds to the your original data set where the "successes" easily can be calculated from Rate and N. A third way would be to use the proportion of successes per treatment combination as response variable, in which case the number of trials must be supplied as the <code>weights</code> argument.</p> <pre><code>set.seed(1) # one row per observation df1 &lt;- data.frame(x = sample(c("yes", "no"), 40, replace = TRUE), y = sample(c("yes", "no"), 40, replace = TRUE), z = rbinom(n = 40, size = 1, prob = 0.5)) df1 library(plyr) # aggregated data with one row per treatment combination df2 &lt;- ddply(.data = df1, .variables = .(x, y), summarize, n = length(z), rate = sum(z)/n, success = n*rate, failure = n - success) df2 # three different ways to specify the models, # which all give the same parameter estimates for x, y and x*y mod1 &lt;- glm(z ~ x * y, data = df1, family = binomial) mod2 &lt;- glm(cbind(success, failure) ~ x * y, data = df2, family = binomial) mod3 &lt;- glm(rate ~ x * y, data = df2, weights = n, family = binomial) summary(mod1) summary(mod2) summary(mod3) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload