【问题标题】:R- How to conduct two-sample t-test with two different survey designsR-如何使用两种不同的调查设计进行两样本 t 检验
【发布时间】:2022-01-12 15:34:14
【问题描述】:

我想对两种均值的相等性执行双样本(welch 的)t 检验,其中一个是使用简单随机抽样 (srsmean) 获得的,另一个是使用调查加权计算得出的调查包 (mean_weighted)。我还在mean_weighted 与在调查设计中实施加权和分层时获得的平均值之间进行了 t 检验 (mean_strat)。

我知道有一个svyttest() 函数,但是,据我所知,这个函数只测试两个样本的均值在一个调查设计中,而不是通过不同调查设计获得的均值.

我也尝试使用 rnorm 创建虚构样本,例如 c(rnorm(9710, mean = 156958.8, sd = 364368)),但这种方法的问题在于,在分层等复杂抽样方法中,有效 n 通常小于 名义上的 n,所以我不确定应该把什么写成n。此外,这种方法感觉有点做作,因为我会将数据拟合到特定类型的分布。

最后,我尝试自己写出 t 统计量的方程,但是,在计算涉及复杂调查设计的“均值差的标准误差”时,我也遇到了与“有效样本量”相关的问题。”

是否有另一种方法适用于srsmean, mean_weighted 之间的 t 检验和mean_weighted, mean_strat 之间的 t 检验?

library(survey)

wel <- c(68008.19, 128504.61,  21347.69,
         33272.95,  61828.96,  32764.44,
         92545.62,  58431.89,  95596.82,
         117734.27)
rmul <- c(16, 16, 16, 16, 16, 16, 16,
          20, 20, 20)
strat <- c(101, 101, 101, 101, 101, 102, 102, 102, 102, 102)


survey.data <- data.frame(wel, rmul, strat)

srsmean <- mean(survey.data$wel)

survey_weighted <- svydesign(data = survey.data,
                             ids = ~wel, 
                             weights = ~rmul, 
                             nest = TRUE)

mean_weighted <- svymean(~wel, survey_weighted)

survey_strat <- survey_strat <- svydesign(data = surveydata, 
                                          ids= ~wel, 
                                          weights = ~rmul, 
                                          strata = ~strat, 
                                          nest = TRUE)
mean_strat <- svymean(~wel, survey_strat)

【问题讨论】:

    标签: r survey t-test


    【解决方案1】:

    我对您的mean_weightedmean_strat 之间的 t 检验的目的感到困惑,因为这些系数之间的差异总是为零?我可能会将简单的随机样本与这样的复杂设计进行比较?

    library(survey)
    
    wel <- c(68008.19, 128504.61,  21347.69,
             33272.95,  61828.96,  32764.44,
             92545.62,  58431.89,  95596.82,
             117734.27)
    rmul <- c(16, 16, 16, 16, 16, 16, 16,
              20, 20, 20)
    strat <- c(101, 101, 101, 101, 101, 102, 102, 102, 102, 102)
    
    survey.data <- data.frame(wel, rmul, strat)
    
    survey_unweighted <- svydesign(data = survey.data,
                                 ids = ~1)
    
    mean_unweighted <- svymean(~wel, survey_unweighted)
    
    survey_strat <- survey_strat <- svydesign(data = survey.data, 
                                              ids= ~wel, 
                                              weights = ~rmul, 
                                              strata = ~strat, 
                                              nest = TRUE)
    mean_strat <- svymean(~wel, survey_strat)
    
    
    coef_one <- coef( mean_unweighted )
    coef_two <- coef( mean_strat )
    se_one <- SE( mean_unweighted )
    se_two <- SE( mean_strat )
    
    t_statistic <- abs( coef_one - coef_two ) / sqrt ( se_one ^2 + se_two ^2 )
    p_value <- ( 1 - pnorm( abs( coef_one - coef_two ) / sqrt( se_one ^2 + se_two ^2 ) ) ) * 2
    sig_diff <- ifelse( 1 - pnorm( abs( coef_one - coef_two ) / sqrt( se_one ^2 + se_two ^2 ) ) < 0.025 , "*" , "" )
    

    【讨论】:

    • 感谢您,这非常有帮助。您的困惑是有道理的:该代码用于计量经济学教育资源,以演示加权和复杂抽样如何影响均值/方差(我将继续对方差进行 F 检验)。测试权重相同的两个调查设计之间的均值差异可能看起来很平庸,但这是为了演示(但现在我正在考虑更多,我可能会忽略它......)跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-06
    • 2023-03-23
    • 2018-05-17
    • 2020-08-06
    • 2020-09-05
    • 2021-05-27
    • 1970-01-01
    相关资源
    最近更新 更多