controlVariates(x, mu, method="linear", positive=T, weights=NULL)
p
columns.
p
; the goal is to find weights
such that the weighted mean (column means) of
x
is
mu
.
"linear"
,
"exponential"
,
"ml"
(maximum likelihood),
or
"binary"
.
Matrix
x
is currently only supported for
"linear"
.
"binary"
requires that
x
only take on values 0 or 1
(or
FALSE
and
TRUE
).
TRUE
and the method can produce negative weights
(
"linear"
), weights are forced to be non-negative, and the
weighted mean may not exactly match
mu
.
numRows(x)
(length of vector, or
number of rows or a matrix).
If supplied then output weights are roughly proportion to these
weights.
w
such that
colMeans(x,weights=w)=mu
.
The approach to control variates here is non-traditional, resulting in a weighted distribution rather than just an adjusted estimate for a mean. This approach is more general. The weights can be used for quantiles and moments, and for adjusting the distributions of multivariate statistics.
In the traditional approach,
Y
and
X
are correlated,
X
with known mean
mu
, and one wishes to estimate the expected
value of
Y
; the usual estimate is
mean(Y)-b1*(mean(X)-mu)
,
where
b1
is the estimated regression slope.
That estimate can also be computed as a weighted average,
with weights calculated by this function
mean(Y,weights=controlVariates(X,mu))
.
There are two advantages to the non-traditional approach.
First,
the weights are more generally useful--in addition to expected values,
we may use them for estimating quantiles or other
aspects of the distribution of
Y
.
Second,
note that the weights are independent of
Y
. Given a single
X
and multiple
Y
, we may compute a single set of weights,
to be used for all
Y
s. The weighted distributions for each
Y
will typically be more accurate than the empirical (unweighted)
distributions; the extent of improvement depends on the
correlation between
X
and each
Y
.
For estimating quantiles of
Y
, it is paticularly useful to
include covariates which have high correlation with the
corresponding indicator function for
Y
. E.g. if the
original data are positively correlated
X1
and
Y1
,
and we wish to estimate the
95% quantile for
Y1
, then an effective control variate is
(X1>Xq95)
, with mu = 0.05; here
Xq95
is the
95% quantile of the underlying distribution for X1.
This may be used instead of or in addition to
X1
itself.
If used alone, this is equivalent to post-stratification.
Similarly, to obtain accurate estimates of both the mean
and variance of
Y1
, it would be useful to use both
X1
and
X1^2
as covariates, e.g.
x=cbind(X1,X1^2)
.
The
"linear"
weights are of the form
w = c * weights * (1 + t (x - mean(x)))
for univariate
x
,
where
c
normalizes so that
w
sums to 1, and
t
determines the
amount by which the weights are tilted in order to satisfy
sum(w*x)=mu
. If
positive==TRUE
then any negative weights
are set to zero and the weights renormalized to sum to 1, and the
weighted mean equality no longer holds exactly.
The
"exponential"
and
"ml"
weights are of the forms
w = c * weights * exp(t * x)
and
w = c * weights / (1 - t * (x - mean(x)))
, respectively.
In these cases this function is a front end
to
tiltMeanSolve
and
tiltWeights
.
If
mu
is outside the range of
x
, these methods are undefined,
and
method
is automatically switched to
"linear"
with
positive=T
.
In the simple control variate problem, when observations
are independent and identically distributed from a joint distribution
with certain finite moments, the linear method has bias
of order
O(1/n)
, where the leading term depends on
E[Y(X-mu)^2]
, the exponential method is biased with a leading
term half that of the linear method, and the
"ml"
method
has bias of order
o(1/n)
.
Hesterberg, T.C. and Nelson, B.L. (1998), "Control Variates for Probability and Quantile Estimation," Management Science, 44(9), 1295-1312.
Hesterberg, T.C. (1996), "Control Variates and Importance Sampling for Efficient Bootstrap Simulations," Statistics and Computing 6(2), 147-157.
set.seed(0); x <- runif(30) w1 <- controlVariates(x, 0.5) w2 <- controlVariates(x, 0.5, method="exponential") w3 <- controlVariates(x, 0.5, method="ml") sum(x * w1); sum(x * w2); sum(x * w3) # all 0.5 y <- x^2 + runif(30)/3 mean(y) # raw estimate for E[Y] mean(y, weight=w1) # control variate adjustment mean(y, weight=w2) # ditto mean(y, weight=w3) # ditto # mean(x) = .56, is greater than 0.5, and x and y are positively # correlated; so the control variate adjusted estimates are # less than the raw estimate, and closer to the true E[Y] = 0.5 b <- bootstrap(1:9, mean, seed=0, save.indices=T) y <- b$replicates mean(y) # not exactly equal to 5 # A univariate control variate -- number of indices <= 5 x <- colMeans(b$indices <= 5) plot(x, y) # not perfect correlation w <- controlVariates(x, 5/9) mean(y, weights=w) # closer to 5 (on average, and for this seed) mean(y) - coef(lm(y ~ x))[2] * (mean(x) - 5/9) # equivalent # A multivariate control variate - (#indices<=3, #indices<=6) x <- cbind(colMeans(b$indices <= 3), colMeans(b$indices <= 6)) w <- controlVariates(x, c(3/9, 6/9)) mean(y, weights=w) mean(y) - coef(lm(y ~ x))[-1] %*% (colMeans(x) - c(3,6)/9)