# How do I do a regress like this?

6 ビュー (過去 30 日間)
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.
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Walter Roberson 2023 年 9 月 16 日

サインインしてコメントする。

### 採用された回答

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 件のコメント3 件の古いコメントを表示3 件の古いコメントを非表示
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 2023 年 9 月 26 日
Thank you so much!

サインインしてコメントする。

### その他の回答 (1 件)

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

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeLinear Predictive Coding についてさらに検索

R2023a

### Community Treasure Hunt

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

Start Hunting!

Translated by