LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2006)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 28 Jul 2006 19:27:51 -0400
Reply-To:     Matthew <matthewpharr@GMAIL.COM>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Matthew <matthewpharr@GMAIL.COM>
Subject:      SPSS-Python Regression Loop
Content-Type: text/plain; charset=ISO-8859-1

I need to iteratively run a regression analysis against a constant dependent variable (DV) until all of the independent variables (IV) have beta weights with a positive value. I am trying to set up a looping structure that will run the regression, dropping the IV's with negative values, and then run the regression again with the IV's that contain positive values. I must do this until all IVs have positive values. I have upwards of a hundred IVís -I know collinearity is a problem- but for now I am just trying to deal with the programming task. My attempt at this has involved using SPSS v14 with the new Python module to retrieve the beta values from the XML output. However, I cannot get the looping structure correct in Python. I can manage to loop through a list I've created, but I cannot force the loop to continue iterating until all beta weights are positive. Is using Python the right approach? Is there a better way outside of Python to attack this problem? I am very grateful for any assistance offered. I've included a sample of the current syntax I am using. Thank You.

*Retrieve procedure output. BEGIN PROGRAM. import spss, spssaux regressionfiltered= "REGRESSION / DEPENDENT dv /METHOD=ENTER %s." iv = ["iv_1", "iv_2", "iv_3", "iv_4", "iv_5", "iv_6", "iv_7", "iv_8", "iv_9", "iv,10"] spss.Submit(regression % " ".join(iv)) reg_table,errcode=spssaux.CreateXMLOutput( regression % " ".join(iv), omsid="Regression") beta_value=spssaux.GetValuesFromXMLWorkspace( reg_table, tableSubtype="Coefficients", colCategory="Beta", cellAttrib="number") print "The Beta is: ", beta_value negative = [] for i, b in enumerate(beta_value): if float(b) < 0: negative.append(i) print negative for i in reversed(negative): iv.pop(i) print iv spss.Submit(regression % " ".join(iv))

Back to: Top of message | Previous page | Main SPSSX-L page