How to make slope 1in fitlm?

4 Ansichten (letzte 30 Tage)
behnam ashtarayeh
behnam ashtarayeh am 18 Feb. 2021
Hello there,
Is it possible to force slope to 1 in in the fitlm function.
Many thanks!
Mohammad
  1 Kommentar
the cyclist
the cyclist am 18 Feb. 2021
I think you need to post some more information about what you are trying to do. Are you asking if you can fit a model of the form
y = a + x
and estimate the value of the intercept a, using fitlm?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

the cyclist
the cyclist am 19 Feb. 2021
I don't believe you can do it with fitlm, but you can with fitnlm:
% Set seed for reproducibility
rng default
% Make up some data that obeys your model, with a little noise
x = (1:10)';
y = 7 + x + 0.05*randn(size(x));
% Tabulate the data. (fitnlm does not require this, but it is convenient)
tbl = table(x,y);
% Define the fit equation
f = @(F,x) F(1) + x;
% Define starting guess for parameter
b0 = 1;
% Fit the data
mdl = fitnlm(tbl,f,b0)
mdl =
Nonlinear regression model: y ~ F1 + x Estimated Coefficients: Estimate SE tStat pValue ________ ________ ______ __________ F1 7.0312 0.027984 251.26 1.2752e-18 Number of observations: 10, Error degrees of freedom: 9 Root Mean Squared Error: 0.0885 R-Squared: 0.999, Adjusted R-Squared 0.999 F-statistic vs. zero model: 2.11e+05, p-value = 5.55e-21

Weitere Antworten (2)

behnam ashtarayeh
behnam ashtarayeh am 19 Feb. 2021
Thanks for your answer. Yes, I exatly mean what you said. Is it possible to fit a model of form (y = a + x) using fitlm and estimate intercept (a)?

behnam ashtarayeh
behnam ashtarayeh am 19 Feb. 2021
Thanks a lot!
It solved my problem.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by