IQSS / Amelia

Amelia: A Package for Missing Data
http://gking.harvard.edu/amelia
61 stars 17 forks source link

Amelia - data integrity violation using priors parameter in cs column #31

Open LutzDE opened 2 years ago

LutzDE commented 2 years ago

Bug:

ONLY !!! If using priors - parameter AND using a exchanged cs and ts dataset-position, amelia generates in the following example "NAs" in cs-entries which are imputed.

Based on the documentation a fixed position of ts and cs in a dataset is not necessary. The parameter cs= and ts= exists to make everything dynamical.

Using Version 1.8 a warning is thrown, but it's only a warning. There should be an error ;-)

Source:

africa_switch<-data.frame( country= africa$country,year= africa$year, gdp_pc= africa$gdp_pc , infl= africa$infl, trade= africa$trade, civlib= africa$civlib, population=africa$population)

imp_amelia<-amelia(africa_switch,ts=c("year"),cs=c("country"),m=2,logs=c("trade","population"), lags=c("trade","population"),leads=c("trade","population"), idvars=c("infl"), polytime=2, boot.type="ordinary",
splinetime=1, bound = rbind(c(5, 0, Inf)), priors=matrix(c(35,5,100,95),nrow=1,ncol=4 ), p2s=1)

unique(imp_amelia$imputations$imp1$country) [1] Burkina Faso NA Burundi Cameroon Congo Senegal Zambia
Levels: Burkina Faso Burundi Cameroon Congo Senegal Zambia

unique(africa_switch$country) [1] Burkina Faso Burundi Cameroon Congo Senegal Zambia
Levels: Burkina Faso Burundi Cameroon Congo Senegal Zambia

(Greater and smaller symbols surrounding NA removed)

Problem:

In other situations (more cases and priors) the cs value is overwritten with a unique value (1,2,3,4...) which could be identical with a real cs value. It's not clear (for me) if there is an impact on the EM process and other parts in amelia() imputation. The generated output is - in such a case - not very useful.

Workaround:

Change column position in datasets.