From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Segmented regression analysis

Solved!
Go to solution

Hi,

 

I am writing a  tool that allows me to calculate a segmental curve fit for discontinuous data, comparable to example 1 or 3 here or to this picture. It is supposed to consist of a linear, followed by an exponential curve fit, which meet at a breakpoint. Just splitting the data array into part does not do the job, because the fits won't meet at the optimal point (see example 2 in the link given above). Is there any way to do this with readily existing LabVIEW VIs, or do I have to go into the mathematics? There are indeed closed mathematical formulations for lin-lin segmented curve fits that could be more or less easily implemented, however, I did not succeed to find any for the given problem.

 

Thank you,

Frank

0 Kudos
Message 1 of 9
(3,258 Views)

Hi Frank,

 

the interpolation VIs offer several ways of limiting the results: ExponentialFit offers "weight" for each sample and "parameter bounds" to limit offset...

 

Did you play with those inputs?

Can you attach a VI containing a sample waveform with your data?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 9
(3,254 Views)

I found an iterative solution by setting a large weight to an approximate breakpoint and then evaluating the sum of regressions for both fit curves. It's not what I'd consider a "nice" solution, but at least I get something that looks right. Unfortunately I don't have a way of checking whether the output is correct or not.

Download All
0 Kudos
Message 3 of 9
(3,243 Views)

To fit a segmented curve is absolutely no problem and I've done it many times. The switch point is simply another fitting parameter to be used in the evaluation of the model. Use "nonlinear fit" and implement the model accordingly. The initial amplitude will be more accurate, because more points contribute to it.

 

 

0 Kudos
Message 4 of 9
(3,234 Views)
Solution
Accepted by Frank_Lehmann

Your data is quite noisy and you don't have many points. This gives some uncertainty and also some sensitivity to initial parameter guesses. Do you know more about the system under study? For example is the switchover point known exactly? In that case you don't need to fit for it.

 

Here's a quick draft how you could do it. Modify as needed.

 

Download All
Message 5 of 9
(3,232 Views)

Thanks a lot altenbach. I actually did try to use the nonlinear fit, but obviously without fully understanding its concept. By the way, the data shows the development of yearly averages of sulfur dioxide immissions in Germany (data from the Federal Environmental Agency). So the switchover point is not "exactly" known - I was rather surprised to find something the like. Whether the proposed segmented curve is appropriate to fit the data may be at question.

0 Kudos
Message 6 of 9
(3,208 Views)

Christian beat me to it, but here is a similar implementation.  I borrowed some of Christian's notation.  There are two differences:

1.  The first segment is a line with slope, not a simple level.

2.  The only initial guess required is the offset.

This also shows the use of constrained nonlinear fitting.

 

-Jim

0 Kudos
Message 7 of 9
(3,182 Views)

Looks like you're using a LabVIEW Version > 2011; I can't open the VIs. Would you mind posting them again, saved in another version? Thanks.

0 Kudos
Message 8 of 9
(3,160 Views)

Apologies.  Here is the 2011 version.

Message 9 of 9
(3,154 Views)