| expand.bpairs | R Documentation |
Expand binomial-pair data from “short” to “long” form.
The short form specifies the response with two columns giving the numbers of successes and failures. Example short form:
survived died dose sex
3 0 10 male
2 1 10 female
1 2 20 male
1 2 20 female
The long form specifies the response as single column of
TRUEs and FALSEs.
For example, the
long form of the above data (spaces and comments added):
survived dose sex
TRUE 10 male # row 1 of short data: 0 died, 3 survived
TRUE 10 male
TRUE 10 male
FALSE 10 female # row 2 of short data: 1 died, 2 survived
TRUE 10 female
TRUE 10 female
FALSE 20 male # row 3 of short data: 2 died, 1 survived
FALSE 20 male
TRUE 20 male
FALSE 20 female # row 4 of short data: 2 died, 1 survived
FALSE 20 female
TRUE 20 female
In this example the total number of survived and died for each row in the short data is the same, but in general that need not be true.
## S3 method for class 'formula'
expand.bpairs(formula = stop("no 'formula' argument"), data = NULL, sort = FALSE, ...)
## Default S3 method:
expand.bpairs(data = stop("no 'data' argument"), y = NULL, sort = FALSE, ...)
formula |
Model formula such as |
data |
Matrix or dataframe containing the data. |
y |
Model response. One of:
|
sort |
Default |
... |
Unused, but provided for generic/method consistency. |
A dataframe of the data in the long form, with expanded binomial pairs.
The first column of the data will be the response column
(a column of TRUEs and FALSEs).
Additionally, the returned value has two attached attributes:
bpairs.index A vector of row indices into the returned data.
Can be used to reconstruct the short data from the long data
(although this package does not yet provide a function to do so).
ynames Column names of the original response (a two-element character vector).
survived <- c(3,2,1,1) # short data for demo (too short to build a real model)
died <- c(0,1,2,2)
dose <- c(10,10,20,20)
sex <- factor(c("male", "female", "male", "female"))
short.data <- data.frame(survived, died, dose, sex)
expand.bpairs(survived + died ~ ., short.data) # returns long form of the data
# expand.bpairs(data=short.data, y=cbind(survived, died)) # equivalent
# expand.bpairs(short.data, c(1,2)) # equivalent
# expand.bpairs(short.data, c("survived", "died")) # equivalent
# For example models, see the earth vignette
# section "Short versus long binomial data".
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.