フィルターのクリア

Model II regression to a linear model

5 ビュー (過去 30 日間)
Casey Vanderlip
Casey Vanderlip 2022 年 6 月 7 日
回答済み: Sai Pavan 2023 年 10 月 4 日
I have previously used fitlm for linear models, however, I have data that requires model II regression. I have used the gmregress function and can determine the slope and y-intercept of my data from this. However, I would like to create a model similar to how fitlm does so. Does anyone know a way to do this?

回答 (1 件)

Sai Pavan
Sai Pavan 2023 年 10 月 4 日
Hi Casey,
I understand that you are trying to convert a model II regression model into a linear model.
As you have rightly said, we can determine the slope and y-intercept of the data using the “gmregress” function. This task can be performed using the following command:
[b, bintr, bintjm] = gmregress(X, Y);
To convert this model into a linear model, we can use the slope and intercept values stored in “b” to calculate the predicted Y values by multiplying the X values by the slope and adding the y-intercept. Then, we can calculate the residuals by subtracting the predicted Y values from the actual Y values in the dataset as demonstrated in the code snippet shown below:
Y_pred = X * b(2) + b(1); % Calculate predicted Y values
residuals = Y - Y_pred; % Calculate residuals
The relevant model information can be stored in a structure using the code snippet shown below:
model = struct('Coefficients', b, 'CoefficientIntervals', bintr, 'Residuals', residuals);
You can refer to the below documentation to learn more about the “gmregress” function:
Hope it helps.
Regards,
Sai Pavan

Community Treasure Hunt

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

Start Hunting!

Translated by