How does one ideally handle and display multidimenstional contingency tables in R v. 2.6.2? E.g.: > prob1<- data.frame(victim=c(rep('white',4),rep('black',4)), + perp=c(rep('white',2),rep('black',2),rep('white',2),rep('black',2)), + death=rep(c('yes','no'),4), count=c(19,132,11,52,0,9,6,97)) > prob1 victim perp death count 1 white white yes 19 2 white white no 132 3 white black yes 11 4 white black no 52 5 black white yes 0 6 black white no 9 7 black black yes 6 8 black black no 97 The xtabs() function doesn't seem appropriate, as it has no means of using 'count'. This must be a common problem. ===============================================================Robert A. LaBudde, PhD, PAS, Dpl. ACAFS e-mail: ral at lcfltd.com Least Cost Formulations, Ltd. URL: http://lcfltd.com/ 824 Timberlake Drive Tel: 757-467-0954 Virginia Beach, VA 23464-3239 Fax: 757-467-2947 "Vere scire est per causas scire"
xtabs(count ~., prob1) On Mon, Apr 21, 2008 at 10:46 PM, Robert A. LaBudde <ral at lcfltd.com> wrote:> How does one ideally handle and display multidimenstional contingency > tables in R v. 2.6.2? > > E.g.: > > > prob1<- data.frame(victim=c(rep('white',4),rep('black',4)), > + perp=c(rep('white',2),rep('black',2),rep('white',2),rep('black',2)), > + death=rep(c('yes','no'),4), count=c(19,132,11,52,0,9,6,97)) > > prob1 > victim perp death count > 1 white white yes 19 > 2 white white no 132 > 3 white black yes 11 > 4 white black no 52 > 5 black white yes 0 > 6 black white no 9 > 7 black black yes 6 > 8 black black no 97 > > The xtabs() function doesn't seem appropriate, as it has no means of > using 'count'. > > This must be a common problem. > > ===============================================================> Robert A. LaBudde, PhD, PAS, Dpl. ACAFS e-mail: ral at lcfltd.com > Least Cost Formulations, Ltd. URL: http://lcfltd.com/ > 824 Timberlake Drive Tel: 757-467-0954 > Virginia Beach, VA 23464-3239 Fax: 757-467-2947 > > "Vere scire est per causas scire" > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
On Mon, Apr 21, 2008 at 9:46 PM, Robert A. LaBudde <ral at lcfltd.com> wrote:> How does one ideally handle and display multidimenstional contingency > tables in R v. 2.6.2? > > E.g.: > > > prob1<- data.frame(victim=c(rep('white',4),rep('black',4)), > + perp=c(rep('white',2),rep('black',2),rep('white',2),rep('black',2)), > + death=rep(c('yes','no'),4), count=c(19,132,11,52,0,9,6,97)) > > prob1 > victim perp death count > 1 white white yes 19 > 2 white white no 132 > 3 white black yes 11 > 4 white black no 52 > 5 black white yes 0 > 6 black white no 9 > 7 black black yes 6 > 8 black black no 97 > > The xtabs() function doesn't seem appropriate, as it has no means of > using 'count'. > > This must be a common problem.You can also use the reshape package (http://had.co.nz/reshape) cast(prob1, victim ~ perp, sum, value="count") cast(prob1, victim ~ perp ~ death, sum, value="count") cast(prob1, death + victim ~ perp, sum, value="count") etc. Hadley -- http://had.co.nz/
Possibly Parallel Threads
- Analisys in Multidimensional contingency tables
- Is there a good package for multiple imputation of missing values in R?
- S-Plus "resample" package and associated functions
- R function which finds confidence interval for binomial variance
- Problem accessing functions in package 'roxygen'