R

sas파일가설검즘

S0LL 2024. 10. 20. 12:19

h0 평균시간이같다
h1 평균시간이다르다 (일한는사람과 안하는사람의 수면시간)

EC1_1 (경제)
BP16_1 (수면시간)
age
sex

> d = read_sas("hn22_all.sas7bdat")
> df = d[,c("EC1_1","BP16_1","sex","age")]
> df2 = df[df$sleep<=24 & df$job<=2,]
> df3 = na.omit(df2)

> qqnorm(df3$sleep)

> var.test(sleep~job, data=df3)  //분산분석 (두 그룹의 수면시간은 다르다는 결과)

        F test to compare two variances

data:  sleep by job
F = 0.7063, num df = 2999, denom df = 2023, p-value < 2.2e-16
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.6519469 0.7647096
sample estimates:
ratio of variances 
         0.7063021 


> t.test(sleep~job, data=df3, var.equal=F) #경제활동하는 그룹이 더 조금잔다라는결과.

        Welch Two Sample t-test

data:  sleep by job
t = -2.8051, df = 3824.5, p-value = 0.005055
alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
95 percent confidence interval:
 -0.18358953 -0.03253432
sample estimates:
mean in group 1 mean in group 2 
       6.692333        6.800395 


> df4 = df3[df3$age>29 & df3$age<61,]  //나이 범위 설정(30~60세)
> var.test(sleep~job, data=df4)

        F test to compare two variances

data:  sleep by job
F = 0.75265, num df = 1754, denom df = 586, p-value = 1.578e-05
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.6578813 0.8572541
sample estimates:
ratio of variances 
         0.7526457 

> t.test(sleep~job, data=df4,var.equal=F)

        Welch Two Sample t-test

data:  sleep by job
t = -3.5302, df = 899.14, p-value = 0.0004364
alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
95 percent confidence interval:
 -0.32168595 -0.09180483
sample estimates:
mean in group 1 mean in group 2 
       6.653561        6.860307 

---------------------------------------------
> df_man = df4[df4$sex==1,]   #남녀구분
> df_woman = df4[df4$sex==2,]
> var.test(sleep~job, data=df_man)

        F test to compare two variances

data:  sleep by job
F = 0.70199, num df = 885, denom df = 84, p-value = 0.01909
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.4999865 0.9448459
sample estimates:
ratio of variances 
         0.7019855 
---------------------------------------------

> var.test(sleep~job, data=df_woman)

        F test to compare two variances

data:  sleep by job
F = 0.77898, num df = 868, denom df = 501, p-value = 0.001447
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.6655903 0.9086936
sample estimates:
ratio of variances 
         0.7789812 
-----------------------------------------

> t.test(sleep~job, data=df_man,var.equal=F)

        Welch Two Sample t-test

data:  sleep by job
t = -3.0455, df = 95.654, p-value = 0.003002
alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
95 percent confidence interval:
 -0.7318348 -0.1542627
sample estimates:
mean in group 1 mean in group 2 
       6.627540        7.070588 
---------------------------------------------

> t.test(sleep~job, data=df_woman,var.equal=F)

        Welch Two Sample t-test

data:  sleep by job
t = -2.1339, df = 943.12, p-value = 0.03311
alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
95 percent confidence interval:
 -0.27760306 -0.01161521
sample estimates:
mean in group 1 mean in group 2 
       6.680092        6.824701 


---------------------------------------------




> df_means = aggregate(BP16_1~EC1_1, data = df_economic, FUN=mean)
> print(df_means)
  EC1_1   BP16_1
1     1 6.784549
2     2 7.163386
> df_means = aggregate(BP16_1~EC1_1, data = df_economic, FUN=sd)
> print(df_means)
  EC1_1   BP16_1
1     1 3.153079
2     2 5.947984