How to know the slope and intercept of a straight line in a log log plot and how to connect the data in log log scale by a straight line?

49 visualizzazioni (ultimi 30 giorni)
DARSHAN KUMAR BISWAS il 20 Lug 2022
Risposto: Star Strider il 21 Lug 2022
for this two graph, I want to do a linear regression, and find out the slope and intercept of that straight line.
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Risposte (2)

dpb il 20 Lug 2022
If one is not concerned about stastical estimation but simply the coefficients, then just use
b=polyfit(log10(x),log10(y),1); % coefficients in log-log space
yhat=10.^polyval(b,log10(xNew));
2 CommentiMostra NessunoNascondi Nessuno
DARSHAN KUMAR BISWAS il 21 Lug 2022
Can you please explain the 2nd line.
dpb il 21 Lug 2022
Modificato: dpb il 21 Lug 2022
How to use coefficients (b) in log space to predict new values...
Try
x=logspace(3,5);y=logspace(2,5);
b=polyfit(log10(x),log10(y),1);
xh=(linspace(1000,100000));
yh=10.^polyval(b,xh);
hold on
plot(xh,yh,'or-')

Accedi per commentare.

Star Strider il 21 Lug 2022
The problem with doing regressions on logarithmic transformed variables is that they transform additive errors (that parameter estimation techniques assume) into multiplicative errors (that they do not). The result is that the parameter estimates on transformed variables are not correct.
A better approach would be to use the fminsearch (or fitnlm if you want statistics) function to estimate the parameters directly since:
coding it as:
pwrfcn = @(p,x) exp(p(1)).*x.^p(2); % Logarithmic Intercept = p(1), Logarithmic Slope = p(2)
This can be used as written in fitnlm, however the code for fminsearch requires:
P0 = rand(2,1); % Initial Parameter Estimates (Choose Appropriate Values), Necessary For ‘fminsearch’ & ‘¹fitnlm’
P = fminsearch(@(p) norm(y = pwrfun(p,x)), P0) % Estimate Parameters
yfit = pwrfcn(P,x); % Evaluate Regression
Then plot the data and ‘yfit’ on a loglog plot, as functions of ‘x’.
.
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Categorie

Scopri di più su Linear and Nonlinear Regression in Help Center e File Exchange

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by