Comparing Coefficients Between Models

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Comparing Coefficients Between Models

Chao yawo-2
Hello:

I am fitting a series of nested logistic regression models, say model 1 and model 2

model 1, with the following IVs:  A, B, C
model 2 adds the following IV:  D

I want to compare the effects of adding variable D, on the original 3 ivs:  A, B, C - to see its effects on each of the original coefficients - specifically, if the change exceed a certain percentage - say, 10, 15 or 20 percent

So, at the end, I would like a small tabulation that lists each variable in model2, by the difference in coefficients, and percent change, as in:

variable: difference ---> . percent change
varA:  0.001---> 0.05%
varB:  0.231---> 15% change
varC:  0.001---> 0.09% change.

Finally, I would also appreciate a command that gives a partial likelihood ratio test for model 2 vrs model 1, to see if overall, adding variable D improves the model.

Thanks very much, in advance for your assistance.

best - cY
===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Comparing Coefficients Between Models

Jon Peck
The way to do this is to capture the Variables in the Equation tables from LOGISTIC with OMS and then retrieve this into Python code to do the arithmetic and display  the results as a pivot table.

The code follows, but the indentation in the Python code matters, so if this email messes that up, let me know, and I will send the code as a file.

This will work with any number (>0) of variables in the two blocks.


The regular LOGISTIC output includes tests for the added variables, so I haven't included that here.

The code.

dataset declare coefs.
* capture oms coefficient table.
oms select tables /if subtypes='Variables in the Equation'
/destination outfile=coefs format=sav.

* insert your LOGISTIC command here.  It must have two ENTER statements.
* There must be a constant term.  The two blocks may have any number of variables.
LOGISTIC REGRESSION VARIABLES gender
  /METHOD=ENTER jobtime minority prevexp jobcat 
  /METHOD=ENTER salary 
  /CONTRAST (jobcat)=Indicator.
omsend.


* retrieve the coefficients and calculate and display the percentage changes.
dataset activate coefs.
begin program.
import spss, spssdata

results = spssdata.Spssdata("Var2 B").fetchall()
results.pop(0)
names, values = zip(*results)
names = [item.rstrip() for item in names]
blocklen = names.index('Constant') + 1

spss.StartProcedure("Logistic Coefficient Changes")
table = spss.BasePivotTable("Coefficient Changes from First to Second Block", "logisticDelta")
results2 = []
names2 = []
for v in range(blocklen):
    try:
        if v == blocklen - 1:
            comp = values[-1]
        else:
            comp = values[v+blocklen]
        delta = -(values[v] - comp)/abs(values[v]) * 100
        results2.extend([values[v], comp, delta])
        names2.append(names[v])
    except:
        pass
table.SimplePivotTable("Variable", rowlabels=names2,
    coldim= "Statistics", collabels = ["Coefficent1", "Coefficient2", "Pct Change"],
    cells = results2)

spss.EndProcedure()
end program.



On Sat, Sep 15, 2018 at 10:44 AM Chao yawo <[hidden email]> wrote:
Hello:

I am fitting a series of nested logistic regression models, say model 1 and model 2

model 1, with the following IVs:  A, B, C
model 2 adds the following IV:  D

I want to compare the effects of adding variable D, on the original 3 ivs:  A, B, C - to see its effects on each of the original coefficients - specifically, if the change exceed a certain percentage - say, 10, 15 or 20 percent

So, at the end, I would like a small tabulation that lists each variable in model2, by the difference in coefficients, and percent change, as in:

variable: difference ---> . percent change
varA:  0.001---> 0.05%
varB:  0.231---> 15% change
varC:  0.001---> 0.09% change.

Finally, I would also appreciate a command that gives a partial likelihood ratio test for model 2 vrs model 1, to see if overall, adding variable D improves the model.

Thanks very much, in advance for your assistance.

best - cY
===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD


--
Jon K Peck
[hidden email]

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD