小编che*_*sea的帖子

R中缺失和审查数据的多重插补

我有一个同时包含随机缺失(MAR)和审查数据的数据集。这些变量是相关的,因此我尝试有条件地估算缺失的数据,以便可以估计相关的多元正态分布的分布参数。我想使用Gibbs MCMC,但是很难执行该程序。我的数据框有5个变量(表示为x1:x5),1099个样本,其中包含MAR,检查值和观察值的某种组合。到目前为止,这是我尝试过的:

# packages
library(msm, tmvtnorm, MCMCpack)

# priors 
theta0<-c(rep(0, 5))
Sigma0<-S0<-diag(5)  
nu0<-4 

# initialize parameters
theta<-c(rep(0, 5))
Tau<-diag(5) 

# initialize output matrix
n_samples <- 1000
mu_MCMC <- matrix(0, nrow = n_samples, ncol = 5)
mu_MCMC[1,] <- theta
cov_MCMC <- matrix(0, nrow = n_samples, ncol = 25)
cov_MCMC[1,] <- c(diag(5))

# detection limits
det_lim <- matrix(c(-1.7, 0, 0, 0, 0), nrow = 1, ncol = 5)

# function to detect NaN (i.e., below detection data)
is.nan.data.frame <- function(x)
    do.call(cbind, lapply(x, …
Run Code Online (Sandbox Code Playgroud)

r missing-data imputation

8
推荐指数
1
解决办法
706
查看次数

标签 统计

imputation ×1

missing-data ×1

r ×1