欢迎光临散文网 会员登陆 & 注册

R语言在不同样本量下的Little's MCAR检验

2021-03-08 09:23 作者:拓端tecdat  | 我要投稿

原文链接:http://tecdat.cn/?p=10134

我进行一个小型仿真,以在不同样本量下测试Little的MCAR检验1。我可以研究线性回归中的异方差。我能够找到一些使用Little's MCAR检验的小样本研究人员的例子,因此我进行了仿真。

  1. library(BaylorEdPsych)

  2. library(simglm)

  3. library(ggplot2)

  4. library(dplyr)

  5. library(mice)

  6. fixed <- ~1 + age + income

  7. fixed_param <- c(2, 0.3, 1.3)

  8. cov_param <- list(dist_fun = c('rnorm', 'rnorm'),

  9. var_type = c("single", "single"),

  10. opts = list(list(mean = 0, sd = 4),

  11. list(mean = 0, sd = 3)))

  1. ggplot(little.mcar.p, aes(x = n, y = p)) + geom_boxplot() +

  2. geom_crossbar(aes(ymin = q025, y = q05, ymax = q075), data = summarise(

  3. group_by(little.mcar.p, n), q025 = quantile(p, .025, na.rm = TRUE),

  4. q05 = quantile(p, .05, na.rm = TRUE), q075 = quantile(p, .075, na.rm = TRUE)

  5. )) +

  6. geom_hline(yintercept = .05) +

  7. scale_y_continuous(breaks = seq(0, 1, .05), limits = c(0, 1)) +

  8. labs(x = "Sample size", y = "p-value",

  9. title = "Little's MCAR test for data that are MCAR",

  10. subtitle = "2000 replications",

  11. caption = paste(paste("For the narrow boxes, going from top to bottom, lines",

  12. "represent 7.5th, 5th and 2.5th percentiles of p-values."),

  13. "Test maintains nominal error rate across wide range of sample sizes.",

  14. sep = "\n"))

 

数据是MCAR

  1. ggplot(little.mcar.p.mar, aes(x = n, y = p)) + geom_boxplot() +

  2. geom_crossbar(aes(ymin = q925, y = q95, ymax = q975), data = summarise(

  3. group_by(little.mcar.p.mar, n), q925 = quantile(p, .925, na.rm = TRUE),

  4. q95 = quantile(p, .95, na.rm = TRUE), q975 = quantile(p, .975, na.rm = TRUE)

  5. ), linetype = 2) +

  6. geom_hline(yintercept = .05) +

  7. scale_y_continuous(breaks = seq(0, 1, .05), limits = c(0, 1)) +

  8. labs(x = "Sample size", y = "p-value",

  9. title = "Little's MCAR test for data that are MAR",

  10. subtitle = "2000 replications",

  11. caption = paste(paste("For the dashed boxes, going from top to bottom, lines",

  12. "represent 97.5th, 95th and 92.5th percentiles of p-values."),

  13. "Test only maintains nominal error rate around sample size of 120.",

  14. sep = "\n"))

数据是MAR

回归接近完美(没有多重共线性)。

 

R语言在不同样本量下的Little's MCAR检验的评论 (共 条)

分享到微博请遵守国家法律