Multiple regression with categorical variables

47 ビュー (過去 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 Center および File ExchangeMeasurements and Feature Extraction についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by