# Using R's formula style lm() with SPSS

Is there a way to type in a regression formula in SPSS in the same manner as R, with weights?

For example, in R, I would write something like:

lm(y ~ B1 + B2 + B1*B2, data=df, weights=x)


How would I go about recreating this in SPSS/PASW?

-

In recent versions of SPSS you can run R code directly in SPSS on your SPSS datasets.

-
+1 Thanks for the tip Jeromy, this would certainly help! The version I have access to is through my school PASW 18. Hopefully it also contains this functionality! Wouldn't that make life easy. –  Brandon Bertelsen Nov 12 '10 at 6:02
And it works like a charm. You're a life saver. –  Brandon Bertelsen Nov 12 '10 at 6:20

In SPSS you can have the GUI write the syntax for you via the paste button. If you go through the regression command in the window there is an option to include weights.

Here is some sample code it just had the program output for me:

  REGRESSION
/MISSING LISTWISE
/REGWGT=VAR3
/STATISTICS COEFF OUTS R ANOVA
/CRITERIA=PIN(.05) POUT(.10)
/NOORIGIN
/DEPENDENT VAR1
/METHOD=ENTER VAR2.


As with any program, I would suggest you check the documentation on how SPSS implements weights in OLS (I personally have no idea).

A comment by Wolfgang below points out that R and SPSS implement weights in the same manner (although I would still suggest checking out the documentation of how they implement weights.)

-
+1 Thanks for pointing that out. I somehow doubt that the implementation of weights within R is the same as that for SPSS –  Brandon Bertelsen Nov 12 '10 at 4:06
I know SAS and SPSS are not the same, but that is all I know. –  Andy W Nov 12 '10 at 4:14
Actually, they are the same for SPSS and R. Simple example: yi <- c(1,3,2,2,3,5,4,6); xi <- c(1,2,2,3,3,4,5,5); wi <- c(.2,.3,.2,.1,.4,.3,.2,.3); summary(lm(yi ~ xi, weights=wi)) gives the exact same results as using the same data in SPSS with: REGRESSION /MISSING LISTWISE /REGWGT=wi /STATISTICS COEFF OUTS R ANOVA /CRITERIA=PIN(.05) POUT(.10) /NOORIGIN /DEPENDENT yi /METHOD=ENTER xi . –  Wolfgang Nov 12 '10 at 13:34
@Wolfgang, thank you you pointing that out. –  Andy W Nov 12 '10 at 14:24