How can I fit linear regression model with the measured data with a known intercept?

3 ビュー (過去 30 日間)
I am working on close-in reference path loss model in MATLAB, where the code is given below:
PL_dB= file(:,2); dis_inch=file(:,1); dis_m= dis_inch * 0.0254
c = 3*10^8; %in light speed in free space fc = 2.4*10^9; lamda=c/fc; do =0.0254; % free space refernce distance for 5.8Ghz 1 inch=0.3048m PL_do = 20*log10(4*pi*do/lamda);% y intercept dis_dB = 10* log10 (dis_m/do); % slope of the regression line/ path loss exponent, n % find the z-score of measurement values z_dis = dis_dB- mean(dis_dB)/sqrt(var(dis_dB)); z_PL = PL_dB- mean(PL_dB)/sqrt(var(PL_dB)); r= sum(z_dis.* z_PL)/ length(z_PL) % correlation coefficient
In this case, the intercept is known. How can I find the linear regression plot based on y and x-axis data?

採用された回答

Star Strider
Star Strider 2018 年 2 月 2 日
You have not stated what ‘x’ and ‘y’ are in your code. However, knowing that ‘PL_do’ is the desired y-intercept, I would do:
b = x(:) \ [y(:)-PL_do]; % Linear Regression
then to estimate a linear regression line to plot with the desired x-data:
y_fit = x(:)*b + PL_do;
You can then plot ‘y_fit’ as a function of ‘x’.

その他の回答 (2 件)

Mahfuza Khatun
Mahfuza Khatun 2018 年 2 月 2 日
編集済み: Mahfuza Khatun 2018 年 2 月 2 日
Then, b will provide another intercept which is not similar to PL_do. PL_dB is the y-axis value and dis_dB is the x-axis value in the code.
Thanks for your reply!
  1 件のコメント
Star Strider
Star Strider 2018 年 2 月 3 日
As always, my pleasure!
The revised code (using your variables) are:
b = dis_dB(:) \ [PL_dB(:)-PL_do]; % Linear Regression
y_fit = dis_dB(:)*b + PL_do;
The regression that calculates ‘b’ will have a 0 intercept. Adding ‘PL_do’ to the evaluated line will produce the linear regression with the y-intercept you want.

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


mer potter
mer potter 2022 年 6 月 28 日
Hello. Do you still happen to have a code for this problem, cause I have a very simillar asignment and i'm completely lost. Thank you in advance.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by