[R] Fwd: ad. Amelia Package for R: Error; contrasts can be applied only to factors with 2 or more levels

Joanna Cieslak joanna.cieslak.mobile at gmail.com
Sat Jan 10 20:12:08 CET 2015


Hello,

I am trying to use the multiple imputation method to replace NAs in the
columns denoting net recalled salary (variable q32) from the file
downloadable here:
http://www.ads.org.pl/pobieranie-zbioru-danych.php?id=91
It is a survey with 17497 observations of 1681 variables, so I am reducing
the number of variables as much as possible. Actually, I am not that much
interested in replacing NAs in other columns, but I have not found any way
to replace NAs in only one column of a data-set.

I am subsetting the data for each year instead of using "ts" due to the
changes in the survey, e.g. number of administrative regions changed, hence
the column with 16 current regions is empty in year 1992, while the column
with old 49 regions is empty in year 2010. Amelia seems not to tolerate it.

Please see the attached R code.
Unfortunately, I get the message

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
  contrasts can be applied only to factors with 2 or more levelsIn
addition: Warning messages:1: In `levels<-`(`*tmp*`, value = if (nl ==
nL) as.character(labels) else paste0(labels,  :
  duplicated levels in factors are deprecated2: In `levels<-`(`*tmp*`,
value = if (nl == nL) as.character(labels) else paste0(labels,  :
  duplicated levels in factors are deprecated3: In `levels<-`(`*tmp*`,
value = if (nl == nL) as.character(labels) else paste0(labels,  :
  duplicated levels in factors are deprecated

Though you will see that the str() command shows that all factor
variables have more than 2 levels.

I have found this thread online:
http://stackoverflow.com/questions/20645926/contrasts-can-be-applied-only-to-factor

that suggests that the solution is to eliminate NAs from the dataset,
but this is actually what I am using the multiple imputation for: I do
not want to get rid of NAs to apply the multiple imputation.. I have
also downloaded the subset as an excel file to check if due to NAs
there is a variable having only representatives of 1 factor only, but
it is not the case.

Could you help out?

Kind regards

Joanna


More information about the R-help mailing list