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.

 Réponse acceptée

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 commentaires

Leon
Leon le 16 Sep 2023
Thanks for the reply.
In my real world example, I would have missing values in lots of the time periods, so it is not as straightforward as this. That's why I decide to do regression for the calculation.
Image Analyst
Image Analyst le 16 Sep 2023
You can use fitnlm. I'm attaching some examples for an exponential decay and a power law. Adapt as needed.
Leon
Leon le 18 Sep 2023
Wow, this is amazing! Thank you so much.
Would you please help me with a few questions? Is the final modeled equation strongly influenced by the initial guessed values? I notice that the coefficnets are very close to the guessed values. Why would we need guessed values? What if we use some really weird numbers for the guessed values?
Thanks!
Image Analyst
Image Analyst le 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.
Leon
Leon le 26 Sep 2023
Thank you so much!

Connectez-vous pour commenter.

Plus de réponses (1)

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 commentaires

Leon
Leon le 16 Sep 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 le 16 Sep 2023
Hi @Leon, you can refer to the example of the exponential regression shared by @Image Analyst.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Linear and Nonlinear Regression dans Centre d'aide et File Exchange

Produits

Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by