Methods for Storing and Analyzing Multiple Choice Variables
mChoice.RdmChoice is a function that is useful for grouping
variables that represent
individual choices on a multiple choice question. These choices are
typically factor or character values but may be of any type. Levels
of component factor variables need not be the same; all unique levels
(or unique character values) are collected over all of the multiple
variables. Then a new character vector is formed with integer choice
numbers separated by semicolons. Optimally, a database system would
have exported the semicolon-separated character strings with a
levels attribute containing strings defining value labels
corresponding to the integer choice numbers. mChoice is a
function for creating a multiple-choice variable after the fact.
mChoice variables are explicitly handed by the describe
and summary.formula functions. NAs or blanks in input
variables are ignored.
format.mChoice will convert the multiple choice representation
to text form by substituting levels for integer codes.
as.double.mChoice converts the mChoice object to a
binary numeric matrix, one column per used level (or all levels of
drop=FALSE. This is called by
the user by invoking as.numeric. There is a
print method and a summary method, and a print
method for the summary.mChoice object. The summary
method computes frequencies of all two-way choice combinations, the
frequencies of the top 5 combinations, information about which other
choices are present when each given choice is present, and the
frequency distribution of the number of choices per observation. This
summary output is used in the describe function. The
print method returns an html character string if
options(prType='html') is in effect if render=FALSE or
renders the html otherwise. This is used by print.describe and
is most effective when short=TRUE is specified to summary.
in.mChoice creates a logical vector the same length as x
whose elements are TRUE when the observation in x
contains at least one of the codes or value labels in the second
argument.
match.mChoice creates an integer vector of the indexes of all
elements in table which contain any of the speicified levels
nmChoice returns an integer vector of the number of choices
that were made
is.mChoice returns TRUE is the argument is a multiple
choice variable.
Usage
mChoice(..., label='',
sort.levels=c('original','alphabetic'),
add.none=FALSE, drop=TRUE, ignoreNA=TRUE)
# S3 method for class 'mChoice'
format(x, minlength=NULL, sep=";", ...)
# S3 method for class 'mChoice'
as.double(x, drop=FALSE, ...)
# S3 method for class 'mChoice'
print(x, quote=FALSE, max.levels=NULL,
width=getOption("width"), ...)
# S3 method for class 'mChoice'
as.character(x, ...)
# S3 method for class 'mChoice'
summary(object, ncombos=5, minlength=NULL,
drop=TRUE, short=FALSE, ...)
# S3 method for class 'summary.mChoice'
print(x, prlabel=TRUE, render=TRUE, ...)
# S3 method for class 'mChoice'
x[..., drop = FALSE]
match.mChoice(x, table, nomatch=NA, incomparables=FALSE)
inmChoice(x, values, condition=c('any', 'all'))
inmChoicelike(x, values, condition=c('any', 'all'),
ignore.case=FALSE, fixed=FALSE)
nmChoice(object)
is.mChoice(x)
# S3 method for class 'mChoice'
Summary(..., na.rm)Arguments
- na.rm
Logical: remove
NA's from data- table
a vector (mChoice) of values to be matched against.
- nomatch
value to return if a value for
xdoes not exist intable.- incomparables
logical whether incomparable values should be compaired.
- ...
a series of vectors
- label
a character string
labelattribute to attach to the matrix created bymChoice- sort.levels
set
sort.levels="alphabetic"to sort the columns of the matrix created bymChoicealphabetically by category rather than by the original order of levels in component factor variables (if there were any input variables that were factors)- add.none
Set
add.nonetoTRUEto make a new category'none'if it doesn't already exist and if there is an observations with no choices selected.- drop
set
drop=FALSEto keep unused factor levels as columns of the matrix produced bymChoice- ignoreNA
set to
FALSEto keep anyNAs present in data as a real level. Prior to Hmisc 4.7-2FALSEwas the default.- x
an object of class
"mchoice"such as that created bymChoice. Foris.mChoiceis any object.- object
an object of class
"mchoice"such as that created bymChoice- ncombos
maximum number of combos.
- width
With of a line of text to be formated
- quote
quote the output
- max.levels
max levels to be displayed
- minlength
By default no abbreviation of levels is done in
formatandsummary. Specify a positive integer to use abbreviation in those functions. Seeabbreviate.- short
set to
TRUEto havesummary.mChoiceuse integer choice numbers in its tables, and to print the choice level definitions at the top- sep
character to use to separate levels when formatting
- prlabel
set to
FALSEto keepprint.summary.mChoicefrom printing the variable label and number of unique values. Ignore for html output.- render
applies of
options(prType='html')is in effect. Set toFALSEto return the html text instead of rendering the html.- values
a scalar or vector. If
valuesis integer, it is the choice codes, and if it is a character vector, it is assumed to be value labels. ForinmChoicelikevaluesmust be character strings which are pieces of choice labels.- condition
set to
'all'forinmChoiceto require that all choices invaluesbe present instead of the default of any of them present.- ignore.case
set to
TRUEto haveinmChoicelikeignore case in the data when matching onvalues- fixed
see
grep
Value
mChoice returns a character vector of class "mChoice"
plus attributes "levels" and "label".
summary.mChoice returns an object of class
"summary.mChoice". inmChoice and inmChoicelike
return a logical vector.
format.mChoice returns a character vector, and
as.double.mChoice returns a binary numeric matrix.
nmChoice returns an integer vector.
print.summary.mChoice returns an html character string if
options(prType='html') is in effect.
Author
Frank Harrell
Department of Biostatistics
Vanderbilt University
fh@fharrell.com
Examples
options(digits=3)
set.seed(3)
n <- 20
sex <- factor(sample(c("m","f"), n, rep=TRUE))
age <- rnorm(n, 50, 5)
treatment <- factor(sample(c("Drug","Placebo"), n, rep=TRUE))
# Generate a 3-choice variable; each of 3 variables has 5 possible levels
symp <- c('Headache','Stomach Ache','Hangnail',
'Muscle Ache','Depressed')
symptom1 <- sample(symp, n, TRUE)
symptom2 <- sample(symp, n, TRUE)
symptom3 <- sample(symp, n, TRUE)
cbind(symptom1, symptom2, symptom3)[1:5,]
#> symptom1 symptom2 symptom3
#> [1,] "Hangnail" "Headache" "Headache"
#> [2,] "Muscle Ache" "Depressed" "Depressed"
#> [3,] "Muscle Ache" "Hangnail" "Muscle Ache"
#> [4,] "Stomach Ache" "Muscle Ache" "Stomach Ache"
#> [5,] "Headache" "Muscle Ache" "Depressed"
Symptoms <- mChoice(symptom1, symptom2, symptom3, label='Primary Symptoms')
Symptoms
#> [1] Hangnail;Headache Muscle Ache;Depressed
#> [3] Hangnail;Muscle Ache Muscle Ache;Stomach Ache
#> [5] Muscle Ache;Headache;Depressed Hangnail;Muscle Ache;Headache
#> [7] Stomach Ache;Headache;Depressed Stomach Ache;Depressed
#> [9] Stomach Ache;Depressed Muscle Ache;Depressed
#> [11] Hangnail;Stomach Ache;Headache Hangnail;Muscle Ache;Stomach Ache
#> [13] Hangnail;Stomach Ache;Depressed Muscle Ache;Headache
#> [15] Hangnail;Muscle Ache;Stomach Ache Hangnail;Stomach Ache;Headache
#> [17] Depressed Hangnail;Muscle Ache;Headache
#> [19] Stomach Ache;Headache Muscle Ache;Stomach Ache;Headache
#> attr(,"label")
#> [1] Primary Symptoms
#> Levels: Hangnail Muscle Ache Stomach Ache Headache Depressed
print(Symptoms, long=TRUE)
#> [1] Hangnail;Headache Muscle Ache;Depressed
#> [3] Hangnail;Muscle Ache Muscle Ache;Stomach Ache
#> [5] Muscle Ache;Headache;Depressed Hangnail;Muscle Ache;Headache
#> [7] Stomach Ache;Headache;Depressed Stomach Ache;Depressed
#> [9] Stomach Ache;Depressed Muscle Ache;Depressed
#> [11] Hangnail;Stomach Ache;Headache Hangnail;Muscle Ache;Stomach Ache
#> [13] Hangnail;Stomach Ache;Depressed Muscle Ache;Headache
#> [15] Hangnail;Muscle Ache;Stomach Ache Hangnail;Stomach Ache;Headache
#> [17] Depressed Hangnail;Muscle Ache;Headache
#> [19] Stomach Ache;Headache Muscle Ache;Stomach Ache;Headache
#> attr(,"label")
#> [1] Primary Symptoms
#> Levels: Hangnail Muscle Ache Stomach Ache Headache Depressed
format(Symptoms[1:5])
#> [1] "Hangnail;Headache" "Muscle Ache;Depressed"
#> [3] "Hangnail;Muscle Ache" "Muscle Ache;Stomach Ache"
#> [5] "Muscle Ache;Headache;Depressed"
inmChoice(Symptoms,'Headache')
#> [1] TRUE FALSE FALSE FALSE TRUE TRUE TRUE FALSE FALSE FALSE TRUE FALSE
#> [13] FALSE TRUE FALSE TRUE FALSE TRUE TRUE TRUE
inmChoicelike(Symptoms, 'head', ignore.case=TRUE)
#> [1] TRUE FALSE FALSE FALSE TRUE TRUE TRUE FALSE FALSE FALSE TRUE FALSE
#> [13] FALSE TRUE FALSE TRUE FALSE TRUE TRUE TRUE
levels(Symptoms)
#> [1] "Hangnail" "Muscle Ache" "Stomach Ache" "Headache" "Depressed"
inmChoice(Symptoms, 3)
#> [1] FALSE FALSE FALSE TRUE FALSE FALSE TRUE TRUE TRUE FALSE TRUE TRUE
#> [13] TRUE FALSE TRUE TRUE FALSE FALSE TRUE TRUE
# Find all subjects with either of two symptoms
inmChoice(Symptoms, c('Headache','Hangnail'))
#> [1] TRUE FALSE TRUE FALSE TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE
#> [13] TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE
# Note: In this example, some subjects have the same symptom checked
# multiple times; in practice these redundant selections would be NAs
# mChoice will ignore these redundant selections
# Find all subjects with both symptoms
inmChoice(Symptoms, c('Headache', 'Hangnail'), condition='all')
#> [1] TRUE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE TRUE FALSE
#> [13] FALSE FALSE FALSE TRUE FALSE TRUE FALSE FALSE
meanage <- N <- numeric(5)
for(j in 1:5) {
meanage[j] <- mean(age[inmChoice(Symptoms,j)])
N[j] <- sum(inmChoice(Symptoms,j))
}
names(meanage) <- names(N) <- levels(Symptoms)
meanage
#> Hangnail Muscle Ache Stomach Ache Headache Depressed
#> 47.9 47.8 48.1 47.5 49.9
N
#> Hangnail Muscle Ache Stomach Ache Headache Depressed
#> 9 11 11 10 8
# Manually compute mean age for 2 symptoms
mean(age[symptom1=='Headache' | symptom2=='Headache' | symptom3=='Headache'])
#> [1] 47.5
mean(age[symptom1=='Hangnail' | symptom2=='Hangnail' | symptom3=='Hangnail'])
#> [1] 47.9
summary(Symptoms)
#>
#> 15 unique combinations
#>
#> Primary Symptoms
#>
#> Frequencies of Numbers of Choices Per Observation
#>
#> 1 2 3
#> 1 9 10
#>
#> Pairwise Frequencies (Diagonal Contains Marginal Frequencies)
#>
#> Hangnail Muscle Ache Stomach Ache Headache Depressed
#> Hangnail 9 5 5 5 1
#> Muscle Ache 11 4 5 3
#> Stomach Ache 11 5 4
#> Headache 10 2
#> Depressed 8
#>
#> Frequencies of Top 5 Combinations
#>
#> Hangnail;Muscle Ache;Headache Hangnail;Muscle Ache;Stomach Ache
#> 2 2
#> Hangnail;Stomach Ache;Headache Muscle Ache;Depressed
#> 2 2
#> Stomach Ache;Depressed
#> 2
#Frequency table sex*treatment, sex*Symptoms
summary(sex ~ treatment + Symptoms, fun=table)
#> sex N= 20
#>
#> +---------+------------+--+--+-+
#> | | | N| f|m|
#> +---------+------------+--+--+-+
#> |treatment| Drug|11| 6|5|
#> | | Placebo| 9| 7|2|
#> +---------+------------+--+--+-+
#> | Symptoms| Hangnail| 9| 6|3|
#> | | Muscle Ache|11| 8|3|
#> | |Stomach Ache|11| 6|5|
#> | | Headache|10| 7|3|
#> | | Depressed| 8| 5|3|
#> +---------+------------+--+--+-+
#> | Overall| |20|13|7|
#> +---------+------------+--+--+-+
# Check:
ma <- inmChoice(Symptoms, 'Muscle Ache')
table(sex[ma])
#>
#> f m
#> 8 3
# could also do:
# summary(sex ~ treatment + mChoice(symptom1,symptom2,symptom3), fun=table)
#Compute mean age, separately by 3 variables
summary(age ~ sex + treatment + Symptoms)
#> age N= 20
#>
#> +---------+------------+--+----+
#> | | | N| age|
#> +---------+------------+--+----+
#> | sex| f|13|47.7|
#> | | m| 7|49.8|
#> +---------+------------+--+----+
#> |treatment| Drug|11|47.4|
#> | | Placebo| 9|49.7|
#> +---------+------------+--+----+
#> | Symptoms| Hangnail| 9|47.9|
#> | | Muscle Ache|11|47.8|
#> | |Stomach Ache|11|48.1|
#> | | Headache|10|47.5|
#> | | Depressed| 8|49.9|
#> +---------+------------+--+----+
#> | Overall| |20|48.4|
#> +---------+------------+--+----+
summary(age ~ sex + treatment + Symptoms, method="cross")
#>
#> mean by sex, treatment, Symptoms
#>
#> sex treatment Symptoms N age
#> 1 f Drug Depressed 0 NA
#> 2 m Drug Depressed 0 NA
#> 3 ALL Drug Depressed 0 NA
#> 4 f Placebo Depressed 1 55.8
#> 5 m Placebo Depressed 0 NA
#> 6 ALL Placebo Depressed 1 55.8
#> 7 f ALL Depressed 1 55.8
#> 8 m ALL Depressed 0 NA
#> 9 ALL ALL Depressed 1 55.8
#> 10 f Drug Hangnail;Headache 0 NA
#> 11 m Drug Hangnail;Headache 1 46.3
#> 12 ALL Drug Hangnail;Headache 1 46.3
#> 13 f Placebo Hangnail;Headache 0 NA
#> 14 m Placebo Hangnail;Headache 0 NA
#> 15 ALL Placebo Hangnail;Headache 0 NA
#> 16 f ALL Hangnail;Headache 0 NA
#> 17 m ALL Hangnail;Headache 1 46.3
#> 18 ALL ALL Hangnail;Headache 1 46.3
#> 19 f Drug Hangnail;Muscle Ache 1 46.4
#> 20 m Drug Hangnail;Muscle Ache 0 NA
#> 21 ALL Drug Hangnail;Muscle Ache 1 46.4
#> 22 f Placebo Hangnail;Muscle Ache 0 NA
#> 23 m Placebo Hangnail;Muscle Ache 0 NA
#> 24 ALL Placebo Hangnail;Muscle Ache 0 NA
#> 25 f ALL Hangnail;Muscle Ache 1 46.4
#> 26 m ALL Hangnail;Muscle Ache 0 NA
#> 27 ALL ALL Hangnail;Muscle Ache 1 46.4
#> 28 f Drug Hangnail;Muscle Ache;Headache 1 48.5
#> 29 m Drug Hangnail;Muscle Ache;Headache 0 NA
#> 30 ALL Drug Hangnail;Muscle Ache;Headache 1 48.5
#> 31 f Placebo Hangnail;Muscle Ache;Headache 0 NA
#> 32 m Placebo Hangnail;Muscle Ache;Headache 1 55.1
#> 33 ALL Placebo Hangnail;Muscle Ache;Headache 1 55.1
#> 34 f ALL Hangnail;Muscle Ache;Headache 1 48.5
#> 35 m ALL Hangnail;Muscle Ache;Headache 1 55.1
#> 36 ALL ALL Hangnail;Muscle Ache;Headache 2 51.8
#> 37 f Drug Hangnail;Muscle Ache;Stomach Ache 0 NA
#> 38 m Drug Hangnail;Muscle Ache;Stomach Ache 0 NA
#> 39 ALL Drug Hangnail;Muscle Ache;Stomach Ache 0 NA
#> 40 f Placebo Hangnail;Muscle Ache;Stomach Ache 2 46.4
#> 41 m Placebo Hangnail;Muscle Ache;Stomach Ache 0 NA
#> 42 ALL Placebo Hangnail;Muscle Ache;Stomach Ache 2 46.4
#> 43 f ALL Hangnail;Muscle Ache;Stomach Ache 2 46.4
#> 44 m ALL Hangnail;Muscle Ache;Stomach Ache 0 NA
#> 45 ALL ALL Hangnail;Muscle Ache;Stomach Ache 2 46.4
#> 46 f Drug Hangnail;Stomach Ache;Depressed 0 NA
#> 47 m Drug Hangnail;Stomach Ache;Depressed 1 49.0
#> 48 ALL Drug Hangnail;Stomach Ache;Depressed 1 49.0
#> 49 f Placebo Hangnail;Stomach Ache;Depressed 0 NA
#> 50 m Placebo Hangnail;Stomach Ache;Depressed 0 NA
#> 51 ALL Placebo Hangnail;Stomach Ache;Depressed 0 NA
#> 52 f ALL Hangnail;Stomach Ache;Depressed 0 NA
#> 53 m ALL Hangnail;Stomach Ache;Depressed 1 49.0
#> 54 ALL ALL Hangnail;Stomach Ache;Depressed 1 49.0
#> 55 f Drug Hangnail;Stomach Ache;Headache 1 46.3
#> 56 m Drug Hangnail;Stomach Ache;Headache 0 NA
#> 57 ALL Drug Hangnail;Stomach Ache;Headache 1 46.3
#> 58 f Placebo Hangnail;Stomach Ache;Headache 1 47.1
#> 59 m Placebo Hangnail;Stomach Ache;Headache 0 NA
#> 60 ALL Placebo Hangnail;Stomach Ache;Headache 1 47.1
#> 61 f ALL Hangnail;Stomach Ache;Headache 2 46.7
#> 62 m ALL Hangnail;Stomach Ache;Headache 0 NA
#> 63 ALL ALL Hangnail;Stomach Ache;Headache 2 46.7
#> 64 f Drug Muscle Ache;Depressed 0 NA
#> 65 m Drug Muscle Ache;Depressed 0 NA
#> 66 ALL Drug Muscle Ache;Depressed 0 NA
#> 67 f Placebo Muscle Ache;Depressed 2 47.7
#> 68 m Placebo Muscle Ache;Depressed 0 NA
#> 69 ALL Placebo Muscle Ache;Depressed 2 47.7
#> 70 f ALL Muscle Ache;Depressed 2 47.7
#> 71 m ALL Muscle Ache;Depressed 0 NA
#> 72 ALL ALL Muscle Ache;Depressed 2 47.7
#> 73 f Drug Muscle Ache;Headache 1 41.7
#> 74 m Drug Muscle Ache;Headache 0 NA
#> 75 ALL Drug Muscle Ache;Headache 1 41.7
#> 76 f Placebo Muscle Ache;Headache 0 NA
#> 77 m Placebo Muscle Ache;Headache 0 NA
#> 78 ALL Placebo Muscle Ache;Headache 0 NA
#> 79 f ALL Muscle Ache;Headache 1 41.7
#> 80 m ALL Muscle Ache;Headache 0 NA
#> 81 ALL ALL Muscle Ache;Headache 1 41.7
#> 82 f Drug Muscle Ache;Headache;Depressed 1 50.8
#> 83 m Drug Muscle Ache;Headache;Depressed 0 NA
#> 84 ALL Drug Muscle Ache;Headache;Depressed 1 50.8
#> 85 f Placebo Muscle Ache;Headache;Depressed 0 NA
#> 86 m Placebo Muscle Ache;Headache;Depressed 0 NA
#> 87 ALL Placebo Muscle Ache;Headache;Depressed 0 NA
#> 88 f ALL Muscle Ache;Headache;Depressed 1 50.8
#> 89 m ALL Muscle Ache;Headache;Depressed 0 NA
#> 90 ALL ALL Muscle Ache;Headache;Depressed 1 50.8
#> 91 f Drug Muscle Ache;Stomach Ache 0 NA
#> 92 m Drug Muscle Ache;Stomach Ache 0 NA
#> 93 ALL Drug Muscle Ache;Stomach Ache 0 NA
#> 94 f Placebo Muscle Ache;Stomach Ache 0 NA
#> 95 m Placebo Muscle Ache;Stomach Ache 1 51.3
#> 96 ALL Placebo Muscle Ache;Stomach Ache 1 51.3
#> 97 f ALL Muscle Ache;Stomach Ache 0 NA
#> 98 m ALL Muscle Ache;Stomach Ache 1 51.3
#> 99 ALL ALL Muscle Ache;Stomach Ache 1 51.3
#> 100 f Drug Muscle Ache;Stomach Ache;Headache 0 NA
#> 101 m Drug Muscle Ache;Stomach Ache;Headache 1 44.3
#> 102 ALL Drug Muscle Ache;Stomach Ache;Headache 1 44.3
#> 103 f Placebo Muscle Ache;Stomach Ache;Headache 0 NA
#> 104 m Placebo Muscle Ache;Stomach Ache;Headache 0 NA
#> 105 ALL Placebo Muscle Ache;Stomach Ache;Headache 0 NA
#> 106 f ALL Muscle Ache;Stomach Ache;Headache 0 NA
#> 107 m ALL Muscle Ache;Stomach Ache;Headache 1 44.3
#> 108 ALL ALL Muscle Ache;Stomach Ache;Headache 1 44.3
#> 109 f Drug Stomach Ache;Depressed 0 NA
#> 110 m Drug Stomach Ache;Depressed 2 51.4
#> 111 ALL Drug Stomach Ache;Depressed 2 51.4
#> 112 f Placebo Stomach Ache;Depressed 0 NA
#> 113 m Placebo Stomach Ache;Depressed 0 NA
#> 114 ALL Placebo Stomach Ache;Depressed 0 NA
#> 115 f ALL Stomach Ache;Depressed 0 NA
#> 116 m ALL Stomach Ache;Depressed 2 51.4
#> 117 ALL ALL Stomach Ache;Depressed 2 51.4
#> 118 f Drug Stomach Ache;Headache 0 NA
#> 119 m Drug Stomach Ache;Headache 0 NA
#> 120 ALL Drug Stomach Ache;Headache 0 NA
#> 121 f Placebo Stomach Ache;Headache 1 49.6
#> 122 m Placebo Stomach Ache;Headache 0 NA
#> 123 ALL Placebo Stomach Ache;Headache 1 49.6
#> 124 f ALL Stomach Ache;Headache 1 49.6
#> 125 m ALL Stomach Ache;Headache 0 NA
#> 126 ALL ALL Stomach Ache;Headache 1 49.6
#> 127 f Drug Stomach Ache;Headache;Depressed 1 45.2
#> 128 m Drug Stomach Ache;Headache;Depressed 0 NA
#> 129 ALL Drug Stomach Ache;Headache;Depressed 1 45.2
#> 130 f Placebo Stomach Ache;Headache;Depressed 0 NA
#> 131 m Placebo Stomach Ache;Headache;Depressed 0 NA
#> 132 ALL Placebo Stomach Ache;Headache;Depressed 0 NA
#> 133 f ALL Stomach Ache;Headache;Depressed 1 45.2
#> 134 m ALL Stomach Ache;Headache;Depressed 0 NA
#> 135 ALL ALL Stomach Ache;Headache;Depressed 1 45.2
#> 136 f Drug ALL 6 46.5
#> 137 m Drug ALL 5 48.5
#> 138 ALL Drug ALL 11 47.4
#> 139 f Placebo ALL 7 48.7
#> 140 m Placebo ALL 2 53.2
#> 141 ALL Placebo ALL 9 49.7
#> 142 f ALL ALL 13 47.7
#> 143 m ALL ALL 7 49.8
#> 144 ALL ALL ALL 20 48.4
f <- summary(treatment ~ age + sex + Symptoms, method="reverse", test=TRUE)
#> Warning: Chi-squared approximation may be incorrect
#> Warning: Chi-squared approximation may be incorrect
#> Warning: Chi-squared approximation may be incorrect
#> Warning: Chi-squared approximation may be incorrect
#> Warning: Chi-squared approximation may be incorrect
#> Warning: Chi-squared approximation may be incorrect
f
#>
#>
#> Descriptive Statistics by treatment
#>
#> +---------------------------+----------------------+----------------------+------------------------------+
#> | |Drug |Placebo | Test |
#> | |(N=11) |(N=9) |Statistic |
#> +---------------------------+----------------------+----------------------+------------------------------+
#> |age | 45.8/46.4/48.7| 47.1/49.6/51.3| F=2.09 d.f.=1,18 P=0.166 |
#> +---------------------------+----------------------+----------------------+------------------------------+
#> |sex : m | 45% (5) | 22% (2) |Chi-square=1.17 d.f.=1 P=0.279|
#> +---------------------------+----------------------+----------------------+------------------------------+
#> |Primary Symptoms : Hangnail| 45% (5) | 44% (4) |Chi-square=0.00 d.f.=1 P=0.964|
#> +---------------------------+----------------------+----------------------+------------------------------+
#> | Muscle Ache | 45% (5) | 67% (6) |Chi-square=0.90 d.f.=1 P=0.343|
#> +---------------------------+----------------------+----------------------+------------------------------+
#> | Stomach Ache | 55% (6) | 56% (5) |Chi-square=0.00 d.f.=1 P=0.964|
#> +---------------------------+----------------------+----------------------+------------------------------+
#> | Headache | 64% (7) | 33% (3) |Chi-square=1.82 d.f.=1 P=0.178|
#> +---------------------------+----------------------+----------------------+------------------------------+
#> | Depressed | 45% (5) | 33% (3) |Chi-square=0.30 d.f.=1 P=0.582|
#> +---------------------------+----------------------+----------------------+------------------------------+
# trio of numbers represent 25th, 50th, 75th percentile
print(f, long=TRUE)
#>
#>
#> Descriptive Statistics by treatment
#>
#> +----------------+----------------------+----------------------+------------------------------+
#> | |Drug |Placebo | Test |
#> | |(N=11) |(N=9) |Statistic |
#> +----------------+----------------------+----------------------+------------------------------+
#> |age | 45.8/46.4/48.7| 47.1/49.6/51.3| F=2.09 d.f.=1,18 P=0.166 |
#> +----------------+----------------------+----------------------+------------------------------+
#> |sex | | |Chi-square=1.17 d.f.=1 P=0.279|
#> +----------------+----------------------+----------------------+------------------------------+
#> | m | 45% (5) | 22% (2) | |
#> +----------------+----------------------+----------------------+------------------------------+
#> |Primary Symptoms| | | |
#> +----------------+----------------------+----------------------+------------------------------+
#> | Hangnail | 45% (5) | 44% (4) |Chi-square=0.00 d.f.=1 P=0.964|
#> +----------------+----------------------+----------------------+------------------------------+
#> | Muscle Ache | 45% (5) | 67% (6) |Chi-square=0.90 d.f.=1 P=0.343|
#> +----------------+----------------------+----------------------+------------------------------+
#> | Stomach Ache| 55% (6) | 56% (5) |Chi-square=0.00 d.f.=1 P=0.964|
#> +----------------+----------------------+----------------------+------------------------------+
#> | Headache | 64% (7) | 33% (3) |Chi-square=1.82 d.f.=1 P=0.178|
#> +----------------+----------------------+----------------------+------------------------------+
#> | Depressed | 45% (5) | 33% (3) |Chi-square=0.30 d.f.=1 P=0.582|
#> +----------------+----------------------+----------------------+------------------------------+