더미회귀분석의 개념과 원리

더미변수의 개념

  • 실제 사회현상에서는 종속변수에 영향을 미치는 주요한 독립변수가 범주형 자료인 경우가 많음

  • 더미변수란 코딩된 숫자의 의미(예 기혼=1,미혼=2)는 없애고 특정 범주에 해당되는지 여부(미혼=1, 기혼=0)으로 변경한 변수

dummy1

  • 참고사이트 : https://m.blog.naver.com/y4769/220442966629

  • 보건과학통계 SPSS 이야기 / 네이버블로그 참고함

  • 범주형 변수를 연속형 변수로 변화는 방법

  • 각 범주값을 표현하기 위해 0과 1로 코딩 변경

  • 가변수라고 함

성별 x
0
1
연령 x1 x2 x3
10대 0 0 0
20대 1 0 0
30대 0 1 0
40대 이상 0 0 1

실습과 시각화

1
a <-read.csv('cosmetics.csv',header = T)
1
a
gendermarriageedujobmincomeawarecountamountdecisionpropensityskinpromolocationsatisf_bsatisf_isatisf_alrepurchase
1 1 4 1 2 2 1 110002 1 1 1 2 5 2 2 2
2 1 4 9 2 1 4 300001 1 3 2 3 2 3 3 4
2 2 4 4 3 1 6 1000003 2 3 2 2 4 5 4 4
2 2 4 7 5 2 6 650003 2 5 2 3 3 4 4 4
1 2 6 6 5 2 2 500002 2 3 2 3 3 3 3 3
2 2 2 7 3 1 2 1000002 1 4 2 3 3 4 4 3
2 1 6 4 5 1 5 1000003 2 5 2 3 2 2 3 4
1 1 6 4 5 4 10 390003 2 2 1 2 4 4 4 4
2 2 4 5 2 2 2 400003 2 3 2 3 3 4 4 4
2 2 4 5 2 1 2 1000003 3 3 1 3 2 3 4 4
2 1 7 4 3 10 3 500001 3 1 2 3 3 3 4 4
1 1 2 5 3 2 1 300003 2 3 2 2 3 3 3 3
2 2 4 4 3 4 4 3200002 3 3 3 2 4 4 4 4
2 2 4 4 2 3 2 2000001 2 3 1 3 3 3 3 3
1 2 4 4 6 2 2 600003 2 1 2 5 3 3 3 4
2 1 4 5 2 2 3 500001 2 4 1 3 3 4 3 3
1 2 8 3 2 5 3 10000001 3 1 2 2 3 3 3 3
2 1 3 8 5 1 6 15000003 3 2 4 1 4 4 4 4
1 2 2 6 2 4 1 800002 3 1 2 3 3 3 4 4
1 1 4 4 3 8 3 300002 2 3 2 3 3 3 3 3
2 2 2 4 2 8 4 3500003 2 3 2 2 3 4 4 4
2 2 4 7 6 1 4 2500003 3 2 2 3 2 3 4 4
2 2 4 7 3 1 25 500002 2 1 2 3 3 4 4 4
2 2 2 9 1 1 1 200001 1 5 1 3 3 3 3 3
1 1 3 8 4 2 3 420001 2 3 1 3 3 3 4 4
1 1 4 8 4 2 3 420003 3 2 1 3 3 4 4 4
2 1 4 4 3 2 20 400003 1 5 2 3 2 4 4 4
2 2 4 4 6 1 6 700003 3 5 2 1 3 4 4 4
2 2 8 4 5 5 6 2000002 1 4 1 1 4 4 4 3
1 2 4 2 6 2 1 2000003 2 1 2 2 3 4 4 4
...................................................
2 2 4 5 2 1 10 300002 2 2 4 3 3 4 4 4
1 2 4 6 6 7 5 500003 2 4 2 2 3 4 4 4
1 2 4 1 4 1 1 100001 3 1 1 1 5 1 3 1
1 1 4 4 3 2 1 100001 1 4 3 2 2 3 3 3
1 1 4 4 3 2 3 500003 2 5 2 3 2 4 4 4
1 2 2 5 4 2 1 600001 1 1 4 5 3 3 3 3
1 1 6 1 3 2 2 500003 2 5 1 2 4 4 3 4
2 2 6 4 6 1 3 5000003 3 5 2 1 3 4 4 4
1 2 4 1 3 2 1 500003 2 1 2 3 2 3 3 3
2 2 6 3 4 1 1 1000003 2 1 2 1 3 3 3 3
2 2 4 7 4 1 2 500003 1 5 2 2 3 2 3 4
2 2 4 4 2 2 12 200002 2 3 2 3 3 3 3 3
1 1 4 4 4 2 4 350002 2 1 3 2 3 3 4 4
1 1 4 4 4 2 4 300002 2 1 2 3 3 4 4 3
2 2 4 7 1 2 2 500001 1 3 2 5 3 4 4 4
2 2 4 7 1 2 3 500001 2 3 2 5 3 3 3 3
2 1 4 4 2 2 7 800003 2 3 2 2 3 3 3 3
1 1 4 1 3 2 6 200003 1 3 1 3 2 3 4 4
1 1 4 10 2 2 2 250003 1 3 2 3 3 4 4 4
2 1 3 8 1 1 7 1000002 1 5 2 3 3 3 1 2
1 2 4 4 3 2 2 500001 2 5 2 2 3 4 3 3
1 2 4 4 5 2 1 800002 2 1 2 3 3 3 3 3
2 2 6 7 5 1 2 3000003 3 2 3 2 3 4 3 3
2 2 7 7 4 1 2 2000002 2 4 3 2 3 3 3 3
1 1 2 1 2 2 5 30001 1 2 1 1 1 1 1 1
1 1 4 2 3 2 6 40001 1 1 1 4 2 1 1 1
2 2 4 4 2 1 10 1500003 2 2 1 2 3 4 4 4
2 2 7 8 1 2 3 1000001 2 1 1 5 2 5 4 4
1 1 4 6 1 3 2 200003 1 1 1 3 4 3 3 2
2 2 6 10 1 1 10 10000003 2 3 1 3 2 3 3 3
1
library(pequod)
1
attach(a)
1
model1 <-lm(satisf_al~satisf_i+factor(gender))
1
summary(model1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Call:
lm(formula = satisf_al ~ satisf_i + factor(gender))

Residuals:
    Min      1Q  Median      3Q     Max
-2.7684 -0.2567  0.2137  0.2316  2.2730

Coefficients:
                Estimate Std. Error t value Pr(>|t|)
(Intercept)      1.64979    0.16793   9.824   <2e-16 ***
satisf_i         0.52966    0.04712  11.240   <2e-16 ***
factor(gender)2  0.01790    0.07826   0.229    0.819
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.6132 on 244 degrees of freedom
Multiple R-squared:  0.3418,	Adjusted R-squared:  0.3364
F-statistic: 63.35 on 2 and 244 DF,  p-value: < 2.2e-16
  • Multiple R-squared: 0.3418, Adjusted R-squared: 0.3364 차이가 0.02 % 정도 차이나면 독립변수로 둘다 잘 선택되었다는 의미이다.

  • p-value: < 2.2e-16 이므로 대립가설 만족, 귀무가설 기각됨 , 모델 의미있음

  • factor(gender)2 0.01790 (의미)

여자가 남자보다 종속변수가 0.01790 높다. 그러나 Pr값이 0.05보다 높아 유의하지 않다.

gender 1이 남자고 gender 2가 여자이다.

상수: 1.65 , 구매문의만족: 0.53, 성별(여성): 0.02 =>반올림 함

y(전반만족) =0.53*구매문의만족(x1) + 0.02 * 성별(여성) + 1.65

여 : 0.53*구매문의만족 + 1.67

남 : 0.53*구매문의만족 + 1.65 (여성만 0.02 곱해줌 ,남자는 0임)

1
a$gender <-factor(a$gender, levels=c(1,2), labels=c('male','female'))
1
model1 <-lm(a$satisf_al~a$satisf_i+a$gender)
1
summary(model1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Call:
lm(formula = a$satisf_al ~ a$satisf_i + a$gender)

Residuals:
    Min      1Q  Median      3Q     Max
-2.7684 -0.2567  0.2137  0.2316  2.2730

Coefficients:
               Estimate Std. Error t value Pr(>|t|)
(Intercept)     1.64979    0.16793   9.824   <2e-16 ***
a$satisf_i      0.52966    0.04712  11.240   <2e-16 ***
a$genderfemale  0.01790    0.07826   0.229    0.819
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.6132 on 244 degrees of freedom
Multiple R-squared:  0.3418,	Adjusted R-squared:  0.3364
F-statistic: 63.35 on 2 and 244 DF,  p-value: < 2.2e-16
1
model2<-lm(satisf_al~satisf_b + satisf_i + factor(gender) + factor(decision))
1
summary(model2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Call:
lm(formula = satisf_al ~ satisf_b + satisf_i + factor(gender) +
    factor(decision))

Residuals:
    Min      1Q  Median      3Q     Max
-2.7590 -0.3143  0.1110  0.2992  2.1434

Coefficients:
                  Estimate Std. Error t value Pr(>|t|)
(Intercept)        1.67889    0.22582   7.435 1.83e-12 ***
satisf_b          -0.03889    0.05019  -0.775   0.4392
satisf_i           0.51617    0.04733  10.906  < 2e-16 ***
factor(gender)2    0.01963    0.07807   0.251   0.8017
factor(decision)2  0.05426    0.12075   0.449   0.6536
factor(decision)3  0.20353    0.10844   1.877   0.0617 .
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.61 on 241 degrees of freedom
Multiple R-squared:  0.3566,	Adjusted R-squared:  0.3432
F-statistic: 26.71 on 5 and 241 DF,  p-value: < 2.2e-16
  • decision (구매 동기) 1은 사회적 요인 , 2는 심리적인 요인, 3은 외모적 요인이다.

결론 : factor(decision)3가 factor(decision)2보다 0.05에 Pr값이 더 가까워서 외모적요인때문에 구매하는 구매자들이 더욱 전반적인 만족도가 높다

satisf_i(구매문의만족)이 0.516 유의하다는 의미는 다른변수들이 동일한 상태이라는 것이고 구매문의만족도가 대략 1점 차이날때 종속변수가 0.516 정도 차이로 달라진다는 뜻이다.

Meta Info

Categories:

Published At:

Modified At:

Leave a comment