Multiple regression with categorical variables

30 Ansichten (letzte 30 Tage)
SAMIA ALGHAMDI
SAMIA ALGHAMDI am 5 Jun. 2017
Kommentiert: Tanvir Kaisar am 22 Feb. 2019
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

Akzeptierte Antwort

Sid Jhaveri
Sid Jhaveri am 7 Jun. 2017
Bearbeitet: Sid Jhaveri am 7 Jun. 2017
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 Kommentar
Tanvir Kaisar
Tanvir Kaisar am 22 Feb. 2019
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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Ebby Thomas
Ebby Thomas am 7 Dez. 2017
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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by