How to make slope 1in fitlm?
4 views (last 30 days)
Show older comments
behnam ashtarayeh
on 18 Feb 2021
Answered: behnam ashtarayeh
on 19 Feb 2021
Hello there,
Is it possible to force slope to 1 in in the fitlm function.
Many thanks!
Mohammad
1 Comment
the cyclist
on 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?
Accepted Answer
the cyclist
on 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)
0 Comments
More Answers (2)
See Also
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!