Model II regression to a linear model
조회 수: 10 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!