How do I do a regress like this?

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

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

Leon
Leon il 16 Set 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.
You can use fitnlm. I'm attaching some examples for an exponential decay and a power law. Adapt as needed.
Leon
Leon il 18 Set 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!
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)

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

Accedi per commentare.

Categorie

Prodotti

Release

R2023a

Richiesto:

il 16 Set 2023

Commentato:

il 26 Set 2023

Community Treasure Hunt

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

Start Hunting!

Translated by