5
$\begingroup$

In SPSS, you can use a variable as WLS Weight when carrying regression.

In R, you can use a variable as an argument weight in lm().

I was wondering if they are the same thing or if there is any difference between them? I think there is none, but can not find anything on this topic.

If there is a difference, how should I proceed with R to do the same as an WLS Weight regression in SPSS?

Thank you!


UPDATE

My question is specific to standardized beta. Overall both approaches lead to the same results, but not the standardized beta.

jd <- data.frame(x = 1:10,
                 w = 1/x,
                 y = x^2)
res <- lm(y ~ x, weights = w, data = jd)
summary(res)

Call:
lm(formula = y ~ x, data = jd, weights = w)

Weighted Residuals:
   Min     1Q Median     3Q    Max 
-4.159 -3.276 -1.193  2.516  5.993 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -13.5039     3.7870  -3.566  0.00734 ** 
x             9.4553     0.8739  10.819  4.7e-06 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 3.991 on 8 degrees of freedom
Multiple R-squared:  0.936, Adjusted R-squared:  0.928 
F-statistic: 117.1 on 1 and 8 DF,  p-value: 4.701e-06

QuantPsyc::lm.beta(res)
        x (weights) 
0.8377007 0.0767146 

And here is the SPSS output for the same toy data set.

enter image description here

Estimates and standard error are the same, but the standardized beta is not (using QuantPsyc::lm.beta() function).

It this a bug or is it intended? If so, why does this occur?

$\endgroup$
5
  • 1
    $\begingroup$ If you run a simple artificial regression, like y=1:10 against x=(1:10)^2 with weights given by w = (1/1):(1/10), how do the results of R and SPSS compare? $\endgroup$ Commented Aug 17, 2022 at 17:18
  • 1
    $\begingroup$ It does the exact same. I have "unexpected" results at hand though, so I should probably investigate the general cases, rather than a specific question. $\endgroup$
    – POC
    Commented Aug 17, 2022 at 18:09
  • 1
    $\begingroup$ I'm not familiar with SPSS, but different parameterizations of weights exist (namely, one is the square root of the other, depending on whether we are implicitly specifying the diagonal of the error term's covariance matrix, or the diagonal of its Cholesky decomposition). The fact that they agree in one case suggests to me that they are prolly using the same parameterization. If an SPSS expert happens by maybe they'll have a different view ¯_(ツ)_/¯. It sounds from your response like you have a specific question about your results, maybe it's worth editing that into the OP? $\endgroup$ Commented Aug 17, 2022 at 21:09
  • $\begingroup$ thank you very much for your great help. One more question, how to compute 95% CI for the new beta get from my.lm.beta. Thanks. $\endgroup$
    – Mr Li
    Commented Dec 25, 2022 at 7:15
  • $\begingroup$ @MrLi I updated my answer. $\endgroup$
    – POC
    Commented Jan 4, 2023 at 15:35

2 Answers 2

1
$\begingroup$

I found out SPSS uses weighted means and weighted standard deviations to standardize data whereas the QuantPsyc::lm.beta() function does not.

jd <- data.frame(x <- 1:10,
                 w = 1/x,
                 y = x^2)

res <- lm(y ~ x, weights = w, data = jd)

# Compute weighted SD like SPSS
sd.wt <- function(x, w){
  sqrt(sum(w * (x - weighted.mean(x, w))^2) / (length(x) -1))
}

my.lm.beta <- function(MOD){
  b <- coef(MOD)[-1]
  w <- as.double(MOD$model$`(weights)`)
  D <- MOD$model[-which(names(MOD$model) == "(weights)")]
  s <- sapply(D, sd.wt, w = w)
  b * s[-1] /  s[1]
}

QuantPsyc::lm.beta(res)
       x1 (weights) 
0.8377007 0.0767146 
my.lm.beta(res)
       x1 
0.9674867 

SPSS uses a different method than R for weighted covariances though. SPSS uses $$s_x = \sqrt{\frac{\sum w_i (x- \bar{x^*})^2}{n-1}}$$ whereas R computes $$s_x = \frac{\sum \sqrt{t_i}(x_i-\bar{x^*})^2}{1-\sum t_i^2}$$ where $$t = \frac{w}{\sum w}$$ via cov.wt().


To get the confidence intervals.

# Compute weighted SD like SPSS
sd.wt <- function(x, w){
  sqrt(sum(w * (x - weighted.mean(x, w))^2) / (length(x) -1))
}

# Updated my.lm.beta for non-weighted lm
my.lm.beta <- function(MOD){
  b <- coef(MOD)[-1]
  wei <- MOD$model$`(weights)`
  if(is.null(wei)){
    s <- sapply(MOD$model, sd)
  }else{
    w <- as.double(wei)
    D <- MOD$model[-which(names(MOD$model) == "(weights)")]
    s <- sapply(D, sd.wt, w = w)
  }
  b * s[-1] /  s[1]
}

# CI
my.lm.ci <- function(MOD, alpha = .05){
  OUT <- data.frame(b = my.lm.beta(MOD))
  SE <- sqrt(diag(vcov(MOD)))[-1] * OUT$b / coef(MOD)[-1]
  OUT$CI.inf <- OUT$b + qnorm(alpha/2) * SE
  OUT$CI.sup <- OUT$b + qnorm((1-alpha/2)) * SE
  OUT
}

# Test
my.lm.ci(res)
$\endgroup$
0
$\begingroup$

SPSS Statistics supports two basic kinds of weights: simple case weighting usable by almost any of the statistical procedures and complex sampling weights for nonrandom surveys. The latter are applicable to the complex sampling procedures, but a sample design specification is also required.

Some procedures such as WLS have special weighting schemes built in that you would specify in their commands. The CTABLES procedure also supports effective base weighting.

The statistical formulas for all these are documented in the Algorithms manual, which is available via Help > Documentation in PDF format.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.