Azzera filtri
Azzera filtri

How do I do a regress like this?

3 visualizzazioni (ultimi 30 giorni)
Leon
Leon il 16 Set 2023
Commentato: Leon il 26 Set 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.

Risposta accettata

Image Analyst
Image Analyst il 16 Set 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)
deltaY = 1×4
-5 -4 -5 -6
percentageDecreases = 100 * deltaY ./ y(1:end-1)
percentageDecreases = 1×4
-5.0000 -4.2105 -5.4945 -6.9767
averagePercentageDecrease = mean(percentageDecreases)
averagePercentageDecrease = -5.4204
  5 Commenti
Image Analyst
Image Analyst il 19 Set 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.
Leon
Leon il 26 Set 2023
Thank you so much!

Accedi per commentare.

Più risposte (1)

Sam Chak
Sam Chak il 16 Set 2023
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
mdl =
Linear regression model: y ~ 1 + x1 Estimated Coefficients: Estimate SE tStat pValue ________ _______ _______ __________ (Intercept) 105.1 0.63509 165.49 4.8652e-07 x1 -4.9 0.19149 -25.589 0.00013089 Number of observations: 5, Error degrees of freedom: 3 Root Mean Squared Error: 0.606 R-squared: 0.995, Adjusted R-Squared: 0.994 F-statistic vs. constant model: 655, p-value = 0.000131
plot(mdl)
  2 Commenti
Leon
Leon il 16 Set 2023
Thanks for the reply.
The change should be exponential (e.g., 5% decrease during each time period), instead of linear (a fixed decrease rate of 5). In this case, how should I do the regression?
Sam Chak
Sam Chak il 16 Set 2023
Hi @Leon, you can refer to the example of the exponential regression shared by @Image Analyst.

Accedi per commentare.

Prodotti


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by