I have used the mice
package for calculating imputations (10 iterations, 5 imputations). Because I am new to this area, my 'methodologist' - who is very patient with me! - want to judge the imputed values (so not the completed sets). I can't seem to find a way to collect all imputed values in one clear dataframe.
The data is about youngsters who answered a lot of questions in a 5 point Likert scale. I have several imp
per age category. For example:
With my command imp_val_15_plus <- Filter(Negate(is.null), imp_15plus$imp)
I can see all imputed values per question and per id. So for example imp_val_15plus[1:2]
gives:
$X02_07
1 2 3 4 5
qwertyuiop123456789 4 4 4 4 4
$X02_12
1 2 3 4 5
adfghjkl09823430233 2 2 5 2 2
zcvnmoi987412597800 1 2 1 1 2
So here are two questions (X02_07 and X02_12). The first has one NA (id qwe...789) and the latter has two NA's (id adf...0233 and zcvn...7800)
I would like to have a dataframe like this:
q_nr id 1 2 3 4 5
$X02_07 qwertyuiop123456789 4 4 4 4 4
$X02_12 adfghjkl09823430233 2 2 5 2 2
$X02_12 zcvnmoi987412597800 1 2 1 1 2
So I thought of a way to extract the values I need and then try to use a loop for all these values. I tried to extract the values:
names(imp_val_15plus[1])
gives me the question number [1] "X02_07"
row.names(imp_val_15plus[[1]])
gives me the id number [1] "qwertyuiop123456789"
But then I go wrong with the imputed values.
With as.integer(imp_val_15plus[[1]])
I get [1] 3 3 3 3 3
instead of what I wanted [1] 4 4 4 4 4
. The three's are logic, because of the factors available for question $X02_07. Normally there should be the factorlevels 1 - 5, but none of the youngsters used a 1, so my levels for this question are 2 - 5.
Have a look at str(imp_val_15plus[[1]])
, it gives:
'data.frame': 1 obs. of 5 variables:
$ 1: Factor w/ 4 levels "2","3","4","5": 3
..- attr(*, "contrasts")= num [1:4, 1:3] 0 1 0 0 0 0 1 0 0 0 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr "2" "3" "4" "5"
.. .. ..$ : chr "2" "3" "4"
$ 2: Factor w/ 4 levels "2","3","4","5": 3
..- attr(*, "contrasts")= num [1:4, 1:3] 0 1 0 0 0 0 1 0 0 0 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr "2" "3" "4" "5"
.. .. ..$ : chr "2" "3" "4"
etc., etc.
It makes sense that I got the three's, because this is the number of the factor with the levels "2","3","4","5". How do I obtain the value of the value itself (the 4) instead of the 3? Or is there an other way to present all imputed values (not the completed set!!) in a neat way?