How can I run a piecewise regression in SPSS?

How can I run a piecewise regression in SPSS?

To perform a piecewise regression in SPSS, begin by opening the “Analyze” menu and selecting “Regression” followed by “Linear.” Then, select the “Plots” option and choose “Piecewise.” Next, specify the variables to be included in the regression and set the breakpoints for the piecewise segments. Finally, click “Run” to generate the results and interpret the output. Piecewise regression in SPSS allows for the analysis of data with non-linear relationships between variables, providing a more accurate and comprehensive understanding of the data.

How can I run a piecewise regression in SPSS? | SPSS FAQ

Say that you want to look at the relationship between how much a child talks
on the phone and the age of the child.  You get a random sample of 200 kids. 
You
ask them how old they are and how many minutes they spend talking on the phone. 
Finally, you save the data as https://stats.idre.ucla.edu/wp-content/uploads/2016/02/talk.sav.  You then
make a scatterplot of the data as shown below.

GGRAPH
  /GRAPHDATASET NAME="iGraphDataset" VARIABLES= talk age 
  /GRAPHSPEC SOURCE=INLINE INLINETEMPLATE=["<addFitLine  type='linear' target='pair'/> "].
BEGIN GPL
SOURCE: s=userSource( id( "iGraphDataset" ) )
DATA:talk=col( source(s), name( "talk" ) )
DATA: age=col( source(s), name( "age" ) )
GUIDE: axis( dim( 1 ), label( "age" ) )
GUIDE: axis( dim( 2 ), label( "talk" ) )
SCALE: linear( dim( 1 ), min( 5 ), max( 25 ) )
SCALE: linear( dim( 2 ), min( 0 ), max( 80 ) )
ELEMENT: point( position( ( age * talk ) ) )
END GPL.
Image

Thinking about this more, you decide that you think that the amount of time that kids talk
on the phone changes dramatically at age 14, and that the slope might change at that age as well.  You think that a piecewise regression might make more sense, where before age 14
there is an intercept and linear slope, and after age 14, there is a different
intercept and different linear slope, kind of like pictured below with just
freehand drawing of what the two regression lines might look like.

Image piecew3

Try 1: Separate regressions

To investigate this, we can run two separate regressions, one for before age 14, and one for after age 14.  We can compare the results of these two models.

* Before age 14.
compute before14 = (age < 14).
filter by before14.
regression /dep=talk /method=enter age.
filter off.Image
* At age 14 and after.
compute after14 = (age >= 14).
filter by after14.
regression /dep=talk /method=enter age.
filter off.Image

Note how the slopes do seem quite different for the two groups.  However, the
intercepts don’t make much sense, since they are the predicted time talking on
the phone when one is 0 years old.

Try 2: Separate regression with age centered at 14

Let’s rescale (center) age by subtracting 14. Then, when age is 0, that really
refers to being 14 years old.

* age14 subtracts 14 from age, so age is 0 when child is 14.
compute age14 = (age - 14).

* Now, rerun regression when child is below 14.
compute before14 = (age < 14).
filter by before14.
regression /dep=talk /method=enter age14.
filter off.

Image

* Now, rerun regression when child is 14 years of age or older.
compute after14 = (age >= 14).
filter by after14.
regression /dep=talk /method=enter age14.
filter off.

Image
Note how the slopes for the two groups stayed the same, but now the
intercepts (Constant) are the predicted talking time at age 14 for the two
groups.  We can see that at age 14 there seems to be not only a change
in the slope (from .682 to 3.62) but also a jump in the intercept
(from 17.6 to 25.8).  This suggest that at age 14, there is discontinuous
jump in time talking on the phone as well as a change in the slope as well. 
However, this is merely suggestive; we should really test this in a combined
model.

Try 3: Combined model, coding for separate slope and intercept

We now combine the two models into a single model.  To do this, we need to
create some new variables.

compute  age1 = (age - 14). 
if (age >= 14) age1 = 0 .
compute  age2 = (age - 14).
if (age < 14) age2 = 0 .

compute  int1 = 1.
if (age >= 14) int1 = 0.
compute  int2 = 1.
if (age < 14)  int2 = 0.
execute.

That might have been confusing, so let us show what these variables look like in a table below.  Note that we have a strange person who is 13.99 years old (very, very close to being 14, but
not quite).  This person will be helpful for seeing the effect of the jump from going
from being under 14 to being 14.

* Check the coding.

* Save our data file so far.
save outfile = "c:datatalk2.sav".
execute.

* Collapse the data to make the coding easier to see.
aggregate
  /outfile=* mode = addvaraibles
  /break=age int1 int2 age1 age2
  /count=N.
list cases.
     age     int1     int2     age1     age2   count

     5.00     1.00      .00    -9.00      .00       4
     6.00     1.00      .00    -8.00      .00       4
     7.00     1.00      .00    -7.00      .00       2
     8.00     1.00      .00    -6.00      .00       5
     9.00     1.00      .00    -5.00      .00       6
    10.00     1.00      .00    -4.00      .00      13
    11.00     1.00      .00    -3.00      .00       3
    12.00     1.00      .00    -2.00      .00      13
    13.00     1.00      .00    -1.00      .00      11
    13.99     1.00      .00     -.01      .00       1
    14.00      .00     1.00      .00      .00      11
    15.00      .00     1.00      .00     1.00       2
    16.00      .00     1.00      .00     2.00      15
    17.00      .00     1.00      .00     3.00      20
    18.00      .00     1.00      .00     4.00      12
    19.00      .00     1.00      .00     5.00      25
    20.00      .00     1.00      .00     6.00       8
    21.00      .00     1.00      .00     7.00      22
    22.00      .00     1.00      .00     8.00      16
    23.00      .00     1.00      .00     9.00       7

Now we can go back to the talk2.sav data file before we did this
collapsing.

get file = "c:datatalk2.sav".

Now we are ready to run our combined regression.  We will
put in the intercept for both groups, so we don’t need
an intercept from SPSS so we use the origin option to put the regression
through the origin (i.e., no intercept).  This is necessary because our model has
an implied constant, int1 plus int2
adds up to 1.  Note that the r-square is not valid for this model and should not be
reported.

* Run the regression, compare to try 2.
regression  /origin /dependent=talk 
  /method=enter int1 int2 age1 age2
  /save=pred(yhat).

Image

Now let’s obtain the predicted values (shown in the table below) and relate those to the meaning of the coefficients above.

means tables=yhat by age.

Image

Below we show a graph of the results.

compute newage = 0.
if age ge 14 newage = 1.
exe.

GGRAPH
  /GRAPHDATASET NAME="iGraphDataset" VARIABLES= talk age newage 
  /GRAPHSPEC SOURCE=INLINE EDITABLE=YES
      INLINETEMPLATE=["<addFitLine  type='linear' target='subgroup'/>" ].
BEGIN GPL
SOURCE: s=userSource( id( "iGraphDataset" ) )
DATA: talk=col( source(s), name( "talk" ) )
DATA: age=col( source(s), name( "age" ) )
DATA: newage=col( source(s), name( "newage" ), unit.category()  )
GUIDE: axis( dim( 1 ), label( "age" ) )
GUIDE: axis( dim( 2 ), label( "talking on the phone" ) )
GUIDE: legend( aesthetic( aesthetic.shape.interior ), label( "newage" ) )
SCALE: linear( dim( 1 ), min( 5 ), max( 25 ) )
SCALE: linear( dim( 2 ), min( 0 ), max( 80 ) )
GUIDE: form.line(position(14, *))
ELEMENT: point( position( age * talk ), shape.interior(newage) )
ELEMENT: line( position( smooth.linear(age * talk ) ), shape.interior( newage) )
GUIDE: legend(aesthetic(aesthetic.shape), label("Newage") )
END GPL.
Image pw2

You might want to test whether the difference in the intercepts
is 0 or whether the change in the slopes is different from 0.  The next section
shows how we can do this.

Try 4: Alternate coding, coding to compare intercepts and slopes

This is another way you can code this model.  Note that we include age14 and
age2 for the two terms for age, and
include the intercept (by not excluding it) and int2 to represent the intercept values. 
With this coding, age2 and int2 represent the change in slope
and intercept from being
less than 14 to being 14 and older.

regression  
/dependent=talk 
/method=enter age14 age2 int2
/save=pred(yhat2).

Image

Using this coding scheme, here is the meaning of the coefficients.

As you can see, the coefficients for age2 and int2 now focus on the change that results from becoming 14 years old.

Below we compute the predicted values calling them yhat2.  Note how the predicted values are the same for this model and the prior model, because the models are essentially the same, they are just parameterized differently.

means tables=yhat2 by age.

Image

Summary

This brief FAQ compared different ways of creating piecewise regression models.  All of these models are equivalent,
just parameterized differently.  They all generate the exact predicted values.  The differences in parameterization are merely a rescrambling
of the intercepts and slopes for the two segments of the regression model.  You
can choose the coding strategy that you like best, although it is often useful
to use both schemes.

 

Cite this article

stats writer (2024). How can I run a piecewise regression in SPSS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-run-a-piecewise-regression-in-spss/

stats writer. "How can I run a piecewise regression in SPSS?." PSYCHOLOGICAL SCALES, 30 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-run-a-piecewise-regression-in-spss/.

stats writer. "How can I run a piecewise regression in SPSS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-run-a-piecewise-regression-in-spss/.

stats writer (2024) 'How can I run a piecewise regression in SPSS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-run-a-piecewise-regression-in-spss/.

[1] stats writer, "How can I run a piecewise regression in SPSS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How can I run a piecewise regression in SPSS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top