Multiple regression with categorical variables

조회 수: 31 (최근 30일)
SAMIA ALGHAMDI
SAMIA ALGHAMDI 2017년 6월 5일
댓글: Tanvir Kaisar 2019년 2월 22일
Hi, I'm new to Matlab sorry if my question is silly. I have dataset consists of 100 rows and 10 column which are Age, Diastolic, Gender, Height, systolic, LastName, Weight, Smoker, Location, SelfAssessedHealthStatus. I need to create a linear regression to predict systolic based on Age, Gender, Height, Weight, Smoker, Location, SelfAssessedHealthStatus. the problem for me is I have 3 categorical variables I'm not sure about how to deal with them in right way. belew is my try. can you please suggest to me how to deal with them..
if true
load ('patients');
patients= table(Age, Gender, Height, Location, SelfAssessedHealthStatus, Smoker, Weight);
patients.Gender = nominal(patients.Gender);
dv = dummyvar(patients.Gender);
patients.Location = nominal(patients.Location);
dv1 = dummyvar(patients.Location);
patients.SelfAssessedHealthStatus = nominal(patients.SelfAssessedHealthStatus);
dv2= dummyvar(patients.Location);
x=[Age dv Height Weight Smoker dv1 dv2];
y= Systolic;
ml=fitlm(x,y)
end

채택된 답변

Sid Jhaveri
Sid Jhaveri 2017년 6월 7일
편집: Sid Jhaveri 2017년 6월 7일
In "fitlm" function you can specify which variables are categorical. For more information on how to achieve this, I would suggest to refer the documentation example given in the link below:
  댓글 수: 1
Tanvir Kaisar
Tanvir Kaisar 2019년 2월 22일
Hello, I have followed the suggested link. I have 2 questions:
1. Will it work when there are more than 2 levels of category? (Say for sex - male, female and transgender)
2.Will this approach also work for multinomial logistic regression mnrfit function? If it won't then how should I approach to deal with the categorical variables in case of mnrfit?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ebby Thomas
Ebby Thomas 2017년 12월 7일
what i believe is that the following code should work for you as per the documentation.
linearmodel = fitlm(patients,'ResponseVar','Weight','PredictorVars',{'Age', 'Gender', 'Height', 'Location', 'SelfAssessedHealthStatus', 'Smoker'},'CategoricalVar',{'Gender','Location','SelfAssessedHealthStatus'})
However, I am interested to know about your interpretation s of the result. Please share your findings as well..
Ebby

카테고리

Help CenterFile Exchange에서 Multiple Linear Regression에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by