Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Piecewise regression

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 06-17-2023 02:49 PM
(2221 views)

Hello,

I have a math problem that is not straight forward. I have data where the slope is not increasing or decreasing. It is flat some time and then increasing or decreasing. This type of data called piecewise linear regression. I suppose to calculate the slopes and only keep the slope where it is significant change and not flat. The issue all solutions online present some codes that I suppose to decide manually.

I need to decide in the slope automatically bc I have 20 subjects and they have 5 treatments and 3 conditions. Please let me know if you can help I can send a dummy data.

I have a math problem that is not straight forward. I have data where the slope is not increasing or decreasing. It is flat some time and then increasing or decreasing. This type of data called piecewise linear regression. I suppose to calculate the slopes and only keep the slope where it is significant change and not flat. The issue all solutions online present some codes that I suppose to decide manually.

I need to decide in the slope automatically bc I have 20 subjects and they have 5 treatments and 3 conditions. Please let me know if you can help I can send a dummy data.

8 REPLIES 8

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Example of piecewise regression in SAS

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_nlin_examples01.htm

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Your question is also known as

- segmented regression
- change point models

Segmented regression models in SAS

By Rick Wicklin on The DO Loop December 14, 2020

https://blogs.sas.com/content/iml/2020/12/14/segmented-regression-sas.html

A segmented regression model is a piecewise regression model that has two or more sub-models, each defined on a separate domain for the explanatory variables.

SAS/STAT User's Guide

The MCMC Procedure

Example 80.12 Change Point Models

https://go.documentation.sas.com/doc/en/pgmsascdc/v_037/statug/statug_mcmc_examples18.htm

Koen

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

these only demonstrate if the model is quadratic and not linear. I need it for a linear equation.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Do you have many repeated measurements for your patients?

Are the repeated measurements equally spaced and forming a time series?

You could also work with so-called "structural break detection"-methods in time series analysis.

You can detect changing level , changing slope , changing regressor influence , changing variability , changing seasonality , ...

Koen

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

it is equally spaced and structured.

I'm not familiar with Time series. Do you have an example?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

SAS® 9.4 and SAS® Viya® 3.5 Programming Documentation

SAS/ETS 15.3 User's Guide

The UCM Procedure

Example 42.7 Detection of Level Shift

https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/etsug/etsug_ucm_examples07.htm

(checkbreak option in LEVEL statement of PROC UCM)

The UCM procedure analyzes and forecasts equally spaced univariate time series data by using an unobserved components model (UCM). The UCMs are also called *structural models* in the time series literature.

Koen

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I don't have time value for the interval= option!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You can make a row number and use interval=day (space between adjacent observations = 1) :

Like here :

```
data work.class; set sashelp.class; rownum=_N_; run;
proc ucm data=work.class;
id rownum interval=day;
model height;
irregular;
level plot=smooth checkbreak;
estimate;
*forecast plot=decomp;
run;
/* end of program */
```

[EDIT]

Do you have a datetime variable for your measurements?

In that case, and if the (equal) interval in-between measurements is not a typical one (like day, week, 10-days, month, ...), then you can make a **custom interval** and specify that one in interval= option.

Koen

**SAS Innovate 2025** is scheduled for May 6-9 in Orlando, FL. Sign up to be **first to learn** about the agenda and registration!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Ready to level-up your skills? Choose your own adventure.