Linear model fit error

7 ビュー (過去 30 日間)
Noe Sanchez
Noe Sanchez 2020 年 12 月 18 日
回答済み: dpb 2020 年 12 月 19 日
clear all;
close all;
clc;
x1 = [7 8 7 8 7 8 7 8 7 8 7 8 7 8 7 8 6.5 8.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5];
x2 = [12 12 12 12 12 12 12 12 20 20 20 20 20 20 20 20 16 16 16 16 16 16 8 24 16 16 16];
x3 = [25 19 19 25 19 25 25 19 19 25 25 19 25 19 19 25 22 22 22 22 22 22 22 22 16 28 22];
y = [147 273.2 244.4 176.5 243.5 203.1 169.9 247.6 253.1 164.1 127.9 250.1 124.9 235.5 197.2 166.7 189.6 170.9 199.7 233.1 216 218.5 223.2 229.5 244.2 37.12 228.8];
x = [x1 x2 x3];
Mdl = fitlm(x,y,'polyijk');
disp(Mdl);
I am trying to get the estimates for the beta parameters of an equation by using least square method. There are three variables. I am trying to fit the data and do it but I get this error message.
Error in fitlm (line 121)
model = LinearModel.fit(X,varargin{:});
Error in leastsquare (line 9)
Mdl = fitlm(x,y,'polyijk');
Any tips are appreciated, thank you

回答 (2 件)

Jeff Miller
Jeff Miller 2020 年 12 月 19 日
Use the transpose operator on x1, x2, x3 and y so that these are column variables, like this for x1:
x1 = [7 8 7 8 7 8 7 8 7 8 7 8 7 8 7 8 6.5 8.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5]';
Also, you are supposed to replace the 'ijk' with numbers in polyijk. For example, 'poly222' would give you a quadratic term for each predictor.
  1 件のコメント
Noe Sanchez
Noe Sanchez 2020 年 12 月 19 日
Ok, I will try this tomorrow morning and will let you know if it works. Thank you very much

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


dpb
dpb 2020 年 12 月 19 日
x1 = [7 8 7 8 7 8 7 8 7 8 7 8 7 8 7 8 6.5 8.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5].';
x2 = [12 12 12 12 12 12 12 12 20 20 20 20 20 20 20 20 16 16 16 16 16 16 8 24 16 16 16].';
x3 = [25 19 19 25 19 25 25 19 19 25 25 19 25 19 19 25 22 22 22 22 22 22 22 22 16 28 22].';
y = [147 273.2 244.4 176.5 243.5 203.1 169.9 247.6 253.1 164.1 127.9 250.1 124.9 235.5 197.2 166.7 189.6 170.9 199.7 233.1 216 218.5 223.2 229.5 244.2 37.12 228.8];
x = [x1 x2 x3];
Mdl = fitlm(x,y,'poly111')
Mdl =
Linear regression model:
y ~ 1 + x1 + x2 + x3
Estimated Coefficients:
Estimate SE tStat pValue
________ ______ _______ __________
(Intercept) 451.82 98.208 4.6007 0.00012594
x1 14.292 11.423 1.2511 0.22346
x2 -1.8031 1.4279 -1.2628 0.21931
x3 -14.981 1.9038 -7.8691 5.6852e-08
Number of observations: 27, Error degrees of freedom: 23
Root Mean Squared Error: 28
R-squared: 0.739, Adjusted R-Squared: 0.705
F-statistic vs. constant model: 21.7, p-value = 6.77e-07
>>

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by