This is an R question. I have $n$ observations of the variable $y$, with each observation, $i$, weighted by $w(i)$. Each $w(i)$ weight falls between zero and 1, with the sum of the weights, $m<n$. I am testing whether the weighted mean of $y$ equals zero, with $std(mean)$ denoting the weighted sample standard deviation of the mean, computed using cov.wt and dividing by sqrt(m).

At a later time, I would like to run a weighted regression of $y$ against some explanatory variables. However, as an intermediate step, I have run the regression lm(y~1,weights=w), which returns an intercept equal to the weighted mean of $y$. However, the standard error of the intercept is based on $n-1$ degress of freedom and, therefore, is smaller than the standard deviation of the weighted sample standard deviation of the mean, computed using cov.wt and dividing by sqrt(m).

Is there a way to run a regression in R in which the degrees of freedom in the simple regression above would be $m-1$ rather than $n-1$?

Note, I have $m$ "cases" of the variable $y$. In most cases, there is only one observation. But if there were two observations in a given case, I would give each a weight of $1/2$, if three observations in a case, each would get a weight of $1/3$, etc.

  • $\begingroup$ This sounds more like a repeated measures model than a "weighted" model. Have you consider using this instead of weights (lmer package)? ie fitting a random intercept model with the random effect being the "case" $\endgroup$ – probabilityislogic Jan 12 '14 at 6:21
  • $\begingroup$ Since my original posting, I have learned that there is no consensus on the proper standard error of a weighted mean. However, I have run a test on 100,000 bootstrap samples, where in each sample, each case is equally likely to be sampled and within each case, each item is equally likely to be selected. I computed 100,000 bootstrap sample means and the standard deviation of the sample means and obtained bootstrap standard errors and p-values essentially identical to what I computed analytically. I would like to try the lmer method that @probabilityislogic has suggested, but don't know how to. $\endgroup$ – RichardRendleman Jan 12 '14 at 13:05
  • $\begingroup$ Following up on my last comment, I tried the following, which I think accomplishes what @probabilityislogic suggested: $\endgroup$ – RichardRendleman Jan 12 '14 at 15:43
  • $\begingroup$ Using the lme4 package, I ran lmer(y~1+(1|as.factor(caseNum))). This did not give back the results I was looking for. $\endgroup$ – RichardRendleman Jan 12 '14 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.