2

I am trying to learn R after learning SPSS and using SPSS for my statistics on a couple papers. I have been using my data to help me learn and understand R as well. In my data, i had to find some Linear Regressions in SPSS using a stepwise comparison to eliminate variables that do not "fit" the model. I tried using stepAIC with the MASS package, because i thought it was the equivalent, and got some completely different output, as well as stuff i did not understand and had to look up. My question is, what are the differences between stepwise in SPSS and stepAIC? (is stepwise more conservative than stepAIC?) Is there a way to write stepAIC code that would be equivalent to stepwise? Or is there a different package that could help me out?

Here is my code:

mydata <- read.csv("Eric.csv")
AveSBP <- mydata[, 3]
MaxVi <- mydata[, 7]
PeakForce <- mydata[, 8]
MaxPO <- mydata[, 9]
Height <- mydata[, 10]
BMI <- mydata[, 11]
NeckCirc <- mydata[, 12]
ArmLength <- mydata[, 13]
ArmSpan <- mydata[, 14]
WaistCircum <- mydata[, 15]
LegLength <- mydata[, 16]
FatAth <- mydata[, 17]
Diff <- mydata[, 18]
Ratio <- mydata[, 19]
lm1 <- lm(AveSBP ~ MaxVi + PeakForce + MaxPO + Height + BMI + NeckCirc + ArmLength + ArmSpan + WaistCircum + LegLength + FatAth + Diff + Ratio)
summary(lm1)
stepAIC(lm1, directions="both")

I am running them on Windows 7 Pro x64, R x64 3.1.0, and SPSS x64 v21.

jlhoward
  • 58,004
  • 7
  • 97
  • 140
Kunio
  • 149
  • 1
  • 11
  • self/contained, reproducible example with disagreements between spss and r please. Also the source code for spss's stepwise function would help. you're building `lm` weird and spelled `direction` in `MASS::stepAIC` wrong. you should also specify all the packages needed to run your code – rawr Jul 19 '14 at 19:01
  • It would be better to just give names to the columns of the data.frame (if they aren't already there) instead of putting the columns in their own vectors. You would then use `lm` like you are not but just add the parameter `data=mydata` – Dason Jul 19 '14 at 19:18
  • @rawr I did run the "Enter" method on SPSS and compared to to the summary(lm1) output and it lined up perfectly. So something is different between the stepwise and stepAIC methods. I also removed direction all together (stepAIC(lm1)) and got exactly the same output as with directions="both" in there. I also ONLY had the MASS package loaded with the standard R build of 3.1.0. I am trying to locate the Stepwise code. – Kunio Jul 19 '14 at 23:58
  • @Dason I actually need them to be separate columns for other comparisons and need to select individual vectors, and helps me identify everything based on what i assign each vector. – Kunio Jul 19 '14 at 23:59
  • They already are separate columns. I'm just wondering why you going through and assigning them to objects instead of just referencing them as variables in your data frame. – Dason Jul 20 '14 at 00:12
  • @Dason I was fairly new to R, so i had only seen assigning them to objects when i did a tutorial. – Kunio May 08 '15 at 12:07

1 Answers1

2

SPSS does not use the AIC criteria for stepwise (either forward or backward) in linear regression, so it is not guaranteed that they will converge to the same solution. See the SPSS help files on regression and the F-value criteria it uses.

Some quick googling provides this answer by Joris Meys for an R function to replicate this type of selection criteria.

Obligatory note, do you really want to use stepwise regression to select the model?

Community
  • 1
  • 1
Andy W
  • 5,031
  • 3
  • 25
  • 51
  • Stepwise regression was just to get my data finished up for my thesis. I did Multivariate and Cluster Analysis for my presentation and when getting ready for publication. – Kunio May 07 '15 at 12:18