I would like to delete some of the entries in my dataframe and impute them by using the remaining information by means of aregImpute function. However, when I randomly delete 25% of the data in some of the columns, some columns are left with only one single value (i.e. they are each equal to a constant number n). Then I get the following error:
Error in aregImpute(fmla, data = df_pmm_imp, n.impute = 5, nk = 0) :
X01154H.exp is constant
Here is a reproducible example:
df = data.frame(replicate(10,sample(0:100,1000,rep=TRUE)))
df[,10]= 0
smp_size = floor(0.25 * nrow(df))
set.seed(123)
missing_ind = sample(seq_len(nrow(df)), size = smp_size)
df_pmm_imp[missing_ind,c(6:10)] = NA
fmla = as.formula(paste(" ~ ", paste(names(df), collapse=" +")))
impute_arg = aregImpute(fmla , data = df, n.impute=5, nk=0)
# Error in aregImpute(fmla, data = df, n.impute = 5, nk = 0) :
X10 is constant
Is there a way to fix this problem? I understand that a constant column does not provide much information, so it might be leading to problems. However, i don't think it should prevent the whole imputation. For instance, a better practice that comes to my mind would be to assign that constant value to all of the missing variables in the column.
Thanks in advance.