Eric Miner
2011-Jul-14 18:09 UTC
[R] Amelia_Multiple_Imputation_with_observational_priors_noms
I am fairly new at using R/programming in general so I apologize if I am leaving crucial parts of the puzzle out, but here goes. First and foremost this is the error I am receiving: Error in muPriors[priors[, 1:2]] <- priors[, 3] : NAs are not allowed in subscripted assignments This occurs only when I am using observational priors and some number of nominal variables, it does not occur when I change to specifying the variables as ordinal, or if I do not use priors. Using a doctored version of the example from the Amelia User Guide this is what I came up with: library(Amelia) library(MatchIt) library(Zelig) library(foreign) data(freetrade) a.out = amelia(freetrade, m=5, ts = "year", cs = "country") newtrade = which(is.na(freetrade), arr.ind = TRUE) newtrade newtradeMean c(30,29,28,31,32,34,30,34,26,32,30,29,28,31,32,34,30,34,26,32,30,29,28,31,32,34,30,34,26, 32,30,29,28,31,32,34,30,34,26,32,30,29,28,31,32,34,30,34,26,32,31,31,32,33,34,35,20,21, 7,8,2.0,2.1,2.2,2.0,2.5,2.3,2.5,2.1,1.9,1.8,1.7,2.9,2.0,0,0,1,.3,.4,.5,.3,.2,.3,.2,.4,.5,.3,.2,.3,.3,.4,.5,.3,.2,.3) newishtrade = cbind(newtrade,newtradeMean) newishtrade newtradeSD c(5,5,5,4,3,3,2,4,5,4,5,5,5,4,3,3,2,4,5,4,5,5,5,4,3,3,2,4,5,4,5,5,5,4,3,3,2,4,5,4,5,5,5,4,3,3,2,4,5,4,3,4,5,6,4,3,4,2, 4,1,1.2,.3,.4,.3,.4,.3,.2,.3,.4,.3,.3,.3,.2,.3,.2,.3,.3,.1,.1,.2,.2,.3,.3,.1,.1,.2,.2,.3,.3,.1,.1,.2,.2,.3) newishtrade = cbind(newtrade,newtradeMean, newtradeSD) newishtrade a.out = amelia(freetrade, m=5, ts = "year", cs = "country", priors newishtrade, p2s=2, noms="signed") a.out = amelia(freetrade, m=5, ts = "year", cs = "country", priors newishtrade, p2s=2, ords="signed") I followed the trail back through the source code to try and see what was occurring. I learned some debugging techniques and tried to discern if it was something with the code or perhaps some incorrect steps in using priors with nominal variables. To summarize, I cannot get observational priors to work when I specify nominal variables. If it helps below is my sourcing output scattered through the various functions in the source code. Thoughts? amelia starting before prep amelia.prep started beginning prep functions Variables used: tariff polity pop gdp.pc intresmi fiveop usheg noms.signed.2 after prep running bootstrap does this work Error in muPriors[priors[, 1:2]] <- priors[, 3] : NAs are not allowed in subscripted assignments [[alternative HTML version deleted]]
Uwe Ligges
2011-Jul-17 13:58 UTC
[R] Amelia_Multiple_Imputation_with_observational_priors_noms
I'd write to the Amelia maintainer. Maybe it is a bug in the package, or just an inappropriate error message (where the error should have been caught earlier). Uwe Ligges On 14.07.2011 20:09, Eric Miner wrote:> I am fairly new at using R/programming in general so I apologize if I am > leaving crucial parts of the puzzle out, but here goes. > > > > First and foremost this is the error I am receiving: > > > > Error in muPriors[priors[, 1:2]]<- priors[, 3] : > > NAs are not allowed in subscripted assignments > > > > This occurs only when I am using observational priors and some number of > nominal variables, it does not occur when I change to specifying the > variables as ordinal, or if I do not use priors. Using a doctored version of > the example from the Amelia User Guide this is what I came up with: > > > > library(Amelia) > > library(MatchIt) > > library(Zelig) > > library(foreign) > > > > data(freetrade) > > > > a.out = amelia(freetrade, m=5, ts = "year", cs = "country") > > > newtrade = which(is.na(freetrade), arr.ind = TRUE) > > newtrade > > newtradeMean > c(30,29,28,31,32,34,30,34,26,32,30,29,28,31,32,34,30,34,26,32,30,29,28,31,32,34,30,34,26, > > 32,30,29,28,31,32,34,30,34,26,32,30,29,28,31,32,34,30,34,26,32,31,31,32,33,34,35,20,21, > > 7,8,2.0,2.1,2.2,2.0,2.5,2.3,2.5,2.1,1.9,1.8,1.7,2.9,2.0,0,0,1,.3,.4,.5,.3,.2,.3,.2,.4,.5,.3,.2,.3,.3,.4,.5,.3,.2,.3) > > newishtrade = cbind(newtrade,newtradeMean) > > newishtrade > > newtradeSD > c(5,5,5,4,3,3,2,4,5,4,5,5,5,4,3,3,2,4,5,4,5,5,5,4,3,3,2,4,5,4,5,5,5,4,3,3,2,4,5,4,5,5,5,4,3,3,2,4,5,4,3,4,5,6,4,3,4,2, > > 4,1,1.2,.3,.4,.3,.4,.3,.2,.3,.4,.3,.3,.3,.2,.3,.2,.3,.3,.1,.1,.2,.2,.3,.3,.1,.1,.2,.2,.3,.3,.1,.1,.2,.2,.3) > > newishtrade = cbind(newtrade,newtradeMean, newtradeSD) > > newishtrade > > > > a.out = amelia(freetrade, m=5, ts = "year", cs = "country", priors > newishtrade, p2s=2, noms="signed") > > > > a.out = amelia(freetrade, m=5, ts = "year", cs = "country", priors > newishtrade, p2s=2, ords="signed") > > > > > I followed the trail back through the source code to try and see what was > occurring. I learned some debugging techniques and tried to discern if it > was something with the code or perhaps some incorrect steps in using priors > with nominal variables. To summarize, I cannot get observational priors to > work when I specify nominal variables. If it helps below is my sourcing > output scattered through the various functions in the source code. Thoughts? > > > amelia starting > before prep > amelia.prep started > beginning prep functions > Variables used: tariff polity pop gdp.pc intresmi fiveop usheg > noms.signed.2 > after prep > running bootstrap > does this work > Error in muPriors[priors[, 1:2]]<- priors[, 3] : > NAs are not allowed in subscripted assignments > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.