panel.densitystrip: Display Distributions with Respect to Reference Values

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

These are panel functions that compare distributions with respect to reference values. panel.densitystrip plots a filled polygon for each unique value of y. panel.cuts calculates the portion of each distribution (unique y) falling within specified limits. panel.ref shades a swath of the panel between specified limits of the primary axis. covplot uses the other panel functions to assemble a sample display of covariate data.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
panel.densitystrip(
	x,
	y,
	horizontal,
	col.line,
	fill,
	factor,
	border=col.line,
	col=fill,
	...
)
panel.ref(
    x, 
    y, 
    col = 'grey90', 
    horizontal, 
    rlim, 
    ...
)
panel.cuts(
    x, 
    y, 
    cuts,
    col,
    col.line,
    text=col.line,
    horizontal = TRUE, 
    offset = -0.2, 
    increment = 0,
    format = function(x,...) as.numeric(round(x/sum(x) * 100)), 
    include.range = TRUE, 
    zero.rm = TRUE, 
    cex=0.7,
    ...
)
panel.covplot(
    x,
    y,
    ref=1,
    rlim=ref * c(0.75,1.25),
    cuts=ref * c(0.75,1,1.25),
    horizontal=TRUE,
    border='black',
    fill='grey',
    text='black',
    shade='grey90',
    col='white',
    ...
)
unitDensity(x,...)

Arguments

x

numeric

y

numeric

horizontal

if TRUE, strips run horizontally (x is primary axis)

col.line

panel.density: polygon border color if border not specified; panel.cuts: text color if text not specified

fill

polygon fill color if col not specified

factor

relative height of the density polygon

border

polygon border color

col

panel.density: polygon fill color; panel.ref: reference area fill color; panel.covplot: color of cut lines panel.cuts: ignored

...

extra arguments passed to other functions

rlim

length 2 vector: the limits of the shaded region

cuts

the values at which to divide the primary axis

text

text color for cut statistics

offset

distance from nominal value on secondary axis, at which to plot cut statistics

increment

distance from nominal value on primary axis, at which to plot cut statistics

format

a function to post-process counts of elements between cuts (should accept ...)

include.range

if TRUE, cuts is supplemented with the range of the data

zero.rm

If TRUE, zeros are not printed

cex

scale factor for text

ref

position of a black reference line; may be NULL

shade

reference fill color

Details

Unlike panel.densityplot, panel.densitystrip has both x and y arguments. In panel.stripplot and panel.bwplot, panel data is implicitly subset by the discrete values on the secondary axis. I.e, visual elements are panel subsets. Here, panel data is explicitly subset using panel.stratify. (The same pertains to panel.cuts). Densities are calculated using the default arguments of density (alternatives will be passed to density if supplied). unitDensity rescales densities so that the maximum value is one. panel.densitystrip uses factor (traditionally used to control jitter) to rescale densities again.

A grouping variable can be used at the ‘panel subset’ level to give the same graphical parameters to several subsets, e.g., several polygons can share a color.

For panel.cuts, calculated values are by default converted to character and printed below (horizontal==TRUE) the density strips. Zeros are not printed by default, for less visual clutter; zeros are stripped before the conversion to character. The actual values calculated are ‘bin counts’, i.e., the number of elements in each vector that fall between adjacent cut points. Only inner cuts need be specified, as the limits of the data are included by default as the outer limits. Cuts are converted to percent by default; use format=function(x)x to get actual counts. cex will control the size of the text.

panel.covplot is optimized for a sample presentation of covariate effects. Values are assumed to be relative, so the center cut is 1 with +/- 25 region. Five color features are specifiable. ref, rlim, and cuts can be specified independently.

Formally, these panel functions are alternatives to panel.stripplot, and thus can be passed to stripplot. xyplot gives similar results, and bwplot seems to give identical results.

Value

used for side-effects

Author(s)

Tim Bergsma

References

http://metrumrg.googlecode.com

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
## Not run: metrumrgURL('example/project/script/covplot.pdf')

#a bootstrap of a pharmacokinetic model
set.seed(0)
boot <- data.frame(
	CL =      exp(rnorm(100,mean=3,    sd=0.25)),
	WT =   exp(rnorm(100,mean=-0.25,sd=0.25)),
	MALE = exp(rnorm(100,mean=0.3,  sd=0.25)),
	ASIAN =  exp(rnorm(100,mean=-.1,    sd=0.05))
)

#Model: CL = theta1 * (WT/70)**theta2 * theta3**MALE * theta4**ASIAN

#Normalize the structural parameter.
boot <- within(boot, CL <- CL/median(CL))

#Realize the submodel for non-normal instances of the continuous covariate.
boot <- within(boot, WT_35 <- (35/70) ** WT)
boot <- within(boot, WT_140 <- (140/70) ** WT)
boot$WT <- NULL

#(Categorical covariates are already expressed proportionally.)

#Reorganize the table.  rev() anticpates bottom-up plotting.
boot <- melt(rev(boot))

#Limit to 90% of the data, for independence from number of bootstraps.
boot <- boot[
	with(
		boot,
		value >= reapply(value,variable,quantile,0.05) &
		value <= reapply(value,variable,quantile,0.95)
	),
]

#plot using panel.covplot().
stripplot(
	variable~value,
	boot,
	panel=panel.covplot,
	xlab='relative clearance'
)
#with groups
stripplot(
	variable~value,
	boot,
	groups=contains('WT',variable),
	panel=panel.covplot,
	xlab='relative clearance'
)

#variations
data(crabs)
soup <- melt(crabs,id.var=c('sp','sex','index'))
soup$relative <- with(soup,value/mean(value[variable=='CL']))
soup$grp <- 'depth'
soup$grp[contains('W',soup$variable)] <- 'width'
soup$grp[contains('L',soup$variable)] <- 'length'
stripplot(variable~value,soup,panel=panel.stratify,panel.levels=panel.densitystrip)
stripplot(
	variable~relative|sp+sex,
	soup,
	panel=panel.stratify,
	panel.levels=panel.densitystrip
)
stripplot(
	variable~relative|sp+sex,
	soup,
	panel=panel.covplot
)
stripplot(
	variable~relative|sp+sex,
	soup,
	panel=panel.covplot,
	groups=grp,
	auto.key=TRUE,
	cex=0.5,
	offset=0.2
)
stripplot(
	value~variable|sp+sex,
	soup,
	groups=grp,
	panel=panel.covplot,
	auto.key=TRUE,
	horizontal=FALSE,
	ref=NULL,
	rlim=c(10,50),
	lty=3,
	lwd=2,
	border='transparent',
	text='blue',
	shade='turquoise',
	col='magenta',
	cuts=c(10,20,30,40,50)
)

metrumrg documentation built on May 2, 2019, 5:55 p.m.