data(quine, package="MASS") #loads quine from MASS
str(quine)
# split quine in two subsets
suppressWarnings(RNGversion("3.5.0"))
set.seed(7654)
lab.A <- sample(nrow(quine), 70, replace=TRUE)
quine.A <- quine[lab.A, 1:3]
quine.B <- quine[-lab.A, 2:4]
# compute the tables required by Frechet.bounds.cat()
freq.xA <- xtabs(~Sex+Age, data=quine.A)
freq.xB <- xtabs(~Sex+Age, data=quine.B)
freq.xy <- xtabs(~Sex+Age+Eth, data=quine.A)
freq.xz <- xtabs(~Sex+Age+Lrn, data=quine.B)
# apply Frechet.bounds.cat()
bounds.yz <- Frechet.bounds.cat(tab.x=freq.xA+freq.xB, tab.xy=freq.xy,
tab.xz=freq.xz, print.f="data.frame")
bounds.yz
# harmonize distr. of Sex vs. Age during computations
# in Frechet.bounds.cat()
#compare marg. distribution of Xs in A and B vs. pooled estimate
comp.prop(p1=margin.table(freq.xy,c(1,2)), p2=freq.xA+freq.xB,
n1=nrow(quine.A), n2=nrow(quine.A)+nrow(quine.B), ref=TRUE)
comp.prop(p1=margin.table(freq.xz,c(1,2)), p2=freq.xA+freq.xB,
n1=nrow(quine.A), n2=nrow(quine.A)+nrow(quine.B), ref=TRUE)
bounds.yz <- Frechet.bounds.cat(tab.x=freq.xA+freq.xB, tab.xy=freq.xy,
tab.xz=freq.xz, print.f="data.frame", align.margins=TRUE)
bounds.yz
Run the code above in your browser using DataLab