필터 지우기
필터 지우기

How do I do a regress like this?

조회 수: 3 (최근 30일)
Leon
Leon 2023년 9월 16일
댓글: Leon 2023년 9월 26일
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.

채택된 답변

Image Analyst
Image Analyst 2023년 9월 16일
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
Image Analyst
Image Analyst 2023년 9월 19일
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 2023년 9월 26일
Thank you so much!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sam Chak
Sam Chak 2023년 9월 16일
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
Leon
Leon 2023년 9월 16일
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 2023년 9월 16일
Hi @Leon, you can refer to the example of the exponential regression shared by @Image Analyst.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by