fitnlm and dummy variables

조회 수: 1 (최근 30일)
Tania
Tania 2014년 6월 18일
댓글: the cyclist 2014년 6월 23일
Hi all, Fitnlm allows automatic creation of dummy variables, if one input the categorical predictor as a nominal or ordinal array. It worked fine for me with fitlm. But I do not understand how I know how many input arguments I get after using the automatic creation of dummy variables. As I need to specify my beta0 I need to know how many input arguments I have. Thank you!

채택된 답변

the cyclist
the cyclist 2014년 6월 18일
편집: the cyclist 2014년 6월 18일
I haven't used the automatic creation of dummy variables, so I don't know the answer to your question. However, the dummyvar() function might also be helpful for you, so I thought I'd mention it.
  댓글 수: 3
Tania
Tania 2014년 6월 23일
Hi, I have created a dummyvar for my postcode variable now: dv=dummyvar(B) But I am not sure how I use this now in fitlm (or fitnlm). Without dummyvar I would do the following: >> ds = dataset(price, bedroom, school, transport); >> mdl =fitlm(ds, 'price~bedroom + school + transport') How do I include my dv now into my dataset? My dv has 29 columns. Thank you! PS: I have my document attached!
the cyclist
the cyclist 2014년 6월 23일
Suppose you have the following grouping variable (where "1", "2", etc represent the groups):
group = [1;1;1;2;2;3;3;3;3;4]
Then
dv = dummyvar(group)
gives
dv =
1 0 0 0
1 0 0 0
1 0 0 0
0 1 0 0
0 1 0 0
0 0 1 0
0 0 1 0
0 0 1 0
0 0 1 0
0 0 0 1
Each column of dv is a variable in your regression. The first column is the binary variable "is_member_of_group?", where 1=yes and 0=no. Likewise for other columns.

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

추가 답변 (0개)

카테고리

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