Computing standard error in weighted mean estimation Suppose that $w_1,w_2,\ldots,w_n$ and $x_1,x_2,...,x_n$ are each drawn i.i.d. from some distributions, with $w_i$ independent of $x_i$. The $w_i$ are strictly positive. You observe all the $w_i$, but not the $x_i$; rather you observe $\sum_i x_i w_i$. I am interested in estimating $\operatorname{E}\left[x\right]$ from this information. Clearly the estimator
$$
\bar{x} = \frac{\sum_i w_i x_i}{\sum_i w_i}
$$
is unbiased, and can be computed given the information at hand.
How might I compute the standard error of this estimator? For the sub-case where $x_i$ takes only values 0 and 1, I naively tried
$$
se \approx \frac{\sqrt{\bar{x}(1-\bar{x})\sum_i w_i^2}}{\sum_i w_i},
$$
basically ignoring the variability in the $w_i$, but found that this performed poorly for sample sizes smaller than around 250. (And this probably depends on the variance of the $w_i$.) It seems that maybe I don't have enough information to compute a 'better' standard error.
 A: The variance of your estimate given the $w_i$ is
$$
\frac{\sum w_i^2 Var(X)}{(\sum w_i)^2} = Var(X) \frac{\sum w_i^2 }{(\sum w_i)^2}.
$$
Because your estimate is unbiased for any $w_i$, the variance of its conditional mean is zero. Hence, the variance of your estimate is
$$
Var(X) \mathbb{E}\left(\frac{\sum w_i^2 }{(\sum w_i)^2}\right)
$$
With all the data observed, this would be easy to estimate empirically. But with only a measure of location of the $X_i$ observed, and not their spread, I don't see how it's going to be possible to get an estimate of $Var(X)$, without making rather severe assumptions.
A: I ran into the same issue recently. The following is what I found: 
Unlike a simple random sample with equal weights, there is no widely accepted definition of standard error of the weighted mean. These days, it would be straight-forward to do a bootstrap and obtain the empirical distribution of the mean, and based on that estimate the standard error. 
What if one wanted to use a formula to do this estimation? 
The main reference is this paper, by Donald F. Gatz and Luther Smith, where 3 formula based estimators are compared with bootstrap results. The best approximation to the bootstrap result comes from Cochran (1977):
$(SEM_w)^2={\dfrac{n}{(n-1)(\sum {P_i})^2}}[\sum (P_i X_i-\bar{P}\bar{X}_w)^2-2 \bar{X}_w \sum (P_i-\bar{P})(P_i X_i-\bar{P}\bar{X}_w)+\bar{X}^2_w \sum (P_i-\bar{P})^2]$
The following is the corresponding R code that came from this R listserve thread. 
weighted.var.se <- function(x, w, na.rm=FALSE)
#  Computes the variance of a weighted mean following Cochran 1977 definition
{
  if (na.rm) { w <- w[i <- !is.na(x)]; x <- x[i] }
  n = length(w)
  xWbar = weighted.mean(x,w,na.rm=na.rm)
  wbar = mean(w)
  out = n/((n-1)*sum(w)^2)*(sum((w*x-wbar*xWbar)^2)-2*xWbar*sum((w-wbar)*(w*x-wbar*xWbar))+xWbar^2*sum((w-wbar)^2))
  return(out)
}

Hope this helps! 
A: @Ming K 's equation is not working for me. @Hugh mentioned  Hmisc::wtd.var(x, w), but this is for variance, if you are wondering about weighted standard error, this would be useful. But read assumption and equation here, following
$$
\sigma _{x}^{-} = \sigma \sqrt{\sum_{i=1}^{n}\omega _{i}^{'2}}
$$
For your convenient, I copy them here.
wtd.stderror <- function(x, weights){
  var <- Hmisc::wtd.var(x, weights)
  weights <- sum( (weights / sum(weights))^2 )
  
  sqrt(var*weights)
}

But I am not sure whether this will work for dateset with a Bernoulli distribution
