How do I do a regress like this?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Leon
am 16 Sep. 2023
Kommentiert: Leon
am 26 Sep. 2023
I have a series of numbers that decrease by about the same percetentage rate with time. How do I do the regression to find the exact percentage rate it is changing?
For example, it can be something like the below:
1 100
2 95
3 91
4 86
5 80
Many thanks.
1 Kommentar
Akzeptierte Antwort
Image Analyst
am 16 Sep. 2023
Not sure why you need a regression. How about this to just find out the percentage decrease at each time point. Then compute the average percentage decrease over all time points if you want.
y = [100, 95, 91, 86, 80];
deltaY = diff(y)
percentageDecreases = 100 * deltaY ./ y(1:end-1)
averagePercentageDecrease = mean(percentageDecreases)
5 Kommentare
Image Analyst
am 19 Sep. 2023
fitnlm just needs a starting point for some reason. So what I usually do is to just put anything there. It will do it's best and then I use the returned, estimated coordinates for the guess next time and do it again. After a few times of this, the values should converge. You could put it in a loop and do it like 5 or 10 times and see how the values settle on the final, good values.
Weitere Antworten (1)
Sam Chak
am 16 Sep. 2023
Hi @Leon
I'm not exactly sure what you want. If you're looking to find the exact percentage drop, as @Image Analyst has shown you, that's one approach. If you want to use MATLAB to create a linear regression model fit, you can do so using the 'fitlm()' function.
y = [100, 95, 91, 86, 80]; % data
x = 1:numel(y);
mdl = fitlm(x, y) % linear regression model
plot(mdl)
Siehe auch
Kategorien
Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
