Clear Filters
Clear Filters

Model II regression to a linear model

2 views (last 30 days)
Casey Vanderlip
Casey Vanderlip on 7 Jun 2022
Answered: Sai Pavan on 4 Oct 2023
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?

Answers (1)

Sai Pavan
Sai Pavan on 4 Oct 2023
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!