# NOT RUN {
set.seed(1)
d <- expand.grid(major=c('Alabama', 'Alaska', 'Arkansas'),
minor=c('East', 'West'),
group=c('Female', 'Male'),
city=0:2)
n <- nrow(d)
d$num <- round(100*runif(n))
d$denom <- d$num + round(100*runif(n))
d$x <- d$num / d$denom
d$lower <- d$x - runif(n)
d$upper <- d$x + runif(n)
with(d,
dotchartpl(x, major, minor, group, city, lower=lower, upper=upper,
big=city==0, num=num, denom=denom, xlab='x'))
# Show half-width confidence intervals for Female - Male differences
# after subsetting the data to have only one record per
# state/region/group
d <- subset(d, city == 0)
with(d,
dotchartpl(x, major, minor, group, num=num, denom=denom, refgroup='Male')
)
n <- 500
set.seed(1)
d <- data.frame(
race = sample(c('Asian', 'Black/AA', 'White'), n, TRUE),
sex = sample(c('Female', 'Male'), n, TRUE),
treat = sample(c('A', 'B'), n, TRUE),
smoking = sample(c('Smoker', 'Non-smoker'), n, TRUE),
hypertension = sample(c('Hypertensive', 'Non-Hypertensive'), n, TRUE),
region = sample(c('North America','Europe','South America',
'Europe', 'Asia', 'Central America'), n, TRUE))
d <- upData(d, labels=c(race='Race', sex='Sex'))
dm <- addMarginal(d, region)
s <- summaryP(race + sex + smoking + hypertension ~
region + treat, data=dm)
s$region <- ifelse(s$region == 'All', 'All Regions', as.character(s$region))
with(s,
dotchartpl(freq / denom, major=var, minor=val, group=treat, mult=region,
big=region == 'All Regions', num=freq, denom=denom)
)
s2 <- s[- attr(s, 'rows.to.exclude1'), ]
with(s2,
dotchartpl(freq / denom, major=var, minor=val, group=treat, mult=region,
big=region == 'All Regions', num=freq, denom=denom)
)
# Note these plots can be created by plot.summaryP when options(grType='plotly')
# }
Run the code above in your browser using DataLab