USE MICE PACKAGE FOR multiple imputation
>install.packages("mice")
> library(mice)
AND create new data set using
old data set "r"
new data set "sample"
sample = r[c("Rasmussen", "SurveyUSA", "PropR", "DiffCount")]
summary(r)
State Year Rasmussen SurveyUSA DiffCount
Arizona : 3 Min. :2004 Min. :-41.0000 Min. :-33.0000 Min. :-19.000
Arkansas : 3 1st Qu.:2004 1st Qu.: -8.0000 1st Qu.:-11.7500 1st Qu.: -6.000
California : 3 Median :2008 Median : 1.0000 Median : -2.0000 Median : 1.000
Colorado : 3 Mean :2008 Mean : 0.0404 Mean : -0.8243 Mean : -1.269
Connecticut: 3 3rd Qu.:2012 3rd Qu.: 8.5000 3rd Qu.: 8.0000 3rd Qu.: 4.000
Florida : 3 Max. :2012 Max. : 39.0000 Max. : 30.0000 Max. : 11.000
(Other) :127 NA's :46 NA's :71
PropR Republican
Min. :0.0000 Min. :0.0000
1st Qu.:0.0000 1st Qu.:0.0000
Median :0.6250 Median :1.0000
Mean :0.5259 Mean :0.5103
3rd Qu.:1.0000 3rd Qu.:1.0000
Max. :1.0000 Max. :1.0000
> install.packages("mice")
> library(mice)
]
> sample = r[c("Rasmussen", "SurveyUSA", "PropR", "DiffCount")]
> summary(sample)
Rasmussen SurveyUSA PropR DiffCount
Min. :-41.0000 Min. :-33.0000 Min. :0.0000 Min. :-19.000
1st Qu.: -8.0000 1st Qu.:-11.7500 1st Qu.:0.0000 1st Qu.: -6.000
Median : 1.0000 Median : -2.0000 Median :0.6250 Median : 1.000
Mean : 0.0404 Mean : -0.8243 Mean :0.5259 Mean : -1.269
3rd Qu.: 8.5000 3rd Qu.: 8.0000 3rd Qu.:1.0000 3rd Qu.: 4.000
Max. : 39.0000 Max. : 30.0000 Max. :1.0000 Max. : 11.000
NA's :46 NA's :71
> set.seed(144)
> imputed = complete(mice(sample))
iter imp variable
1 1 Rasmussen SurveyUSA
1 2 Rasmussen SurveyUSA
1 3 Rasmussen SurveyUSA
1 4 Rasmussen SurveyUSA
1 5 Rasmussen SurveyUSA
2 1 Rasmussen SurveyUSA
2 2 Rasmussen SurveyUSA
2 3 Rasmussen SurveyUSA
2 4 Rasmussen SurveyUSA
2 5 Rasmussen SurveyUSA
3 1 Rasmussen SurveyUSA
3 2 Rasmussen SurveyUSA
3 3 Rasmussen SurveyUSA
3 4 Rasmussen SurveyUSA
3 5 Rasmussen SurveyUSA
4 1 Rasmussen SurveyUSA
4 2 Rasmussen SurveyUSA
4 3 Rasmussen SurveyUSA
4 4 Rasmussen SurveyUSA
4 5 Rasmussen SurveyUSA
5 1 Rasmussen SurveyUSA
5 2 Rasmussen SurveyUSA
5 3 Rasmussen SurveyUSA
5 4 Rasmussen SurveyUSA
5 5 Rasmussen SurveyUSA
> summary(imputed)
Rasmussen SurveyUSA
Min. :-41.000 Min. :-33.000
1st Qu.: -8.000 1st Qu.:-11.000
Median : 3.000 Median : 1.000
Mean : 1.731 Mean : 1.517
3rd Qu.: 11.000 3rd Qu.: 18.000
Max. : 39.000 Max. : 30.000
> no NA values
now change both the new variable
given below
r$Rasmussen = imputed$Rasmussen
> r$SurveyUSA = imputed$SurveyUSA
> summary(r)
State Year Rasmussen SurveyUSA DiffCount
Arizona : 3 Min. :2004 Min. :-41.000 Min. :-33.000 Min. :-19.000
Arkansas : 3 1st Qu.:2004 1st Qu.: -8.000 1st Qu.:-11.000 1st Qu.: -6.000
California : 3 Median :2008 Median : 3.000 Median : 1.000 Median : 1.000
Colorado : 3 Mean :2008 Mean : 1.731 Mean : 1.517 Mean : -1.269
Connecticut: 3 3rd Qu.:2012 3rd Qu.: 11.000 3rd Qu.: 18.000 3rd Qu.: 4.000
Florida : 3 Max. :2012 Max. : 39.000 Max. : 30.000 Max. : 11.000
(Other) :127
PropR Republican
Min. :0.0000 Min. :0.0000
1st Qu.:0.0000 1st Qu.:0.0000
Median :0.6250 Median :1.0000
Mean :0.5259 Mean :0.5103
3rd Qu.:1.0000 3rd Qu.:1.0000
Max. :1.0000 Max. :1.0000
>install.packages("mice")
> library(mice)
AND create new data set using
old data set "r"
new data set "sample"
sample = r[c("Rasmussen", "SurveyUSA", "PropR", "DiffCount")]
summary(r)
State Year Rasmussen SurveyUSA DiffCount
Arizona : 3 Min. :2004 Min. :-41.0000 Min. :-33.0000 Min. :-19.000
Arkansas : 3 1st Qu.:2004 1st Qu.: -8.0000 1st Qu.:-11.7500 1st Qu.: -6.000
California : 3 Median :2008 Median : 1.0000 Median : -2.0000 Median : 1.000
Colorado : 3 Mean :2008 Mean : 0.0404 Mean : -0.8243 Mean : -1.269
Connecticut: 3 3rd Qu.:2012 3rd Qu.: 8.5000 3rd Qu.: 8.0000 3rd Qu.: 4.000
Florida : 3 Max. :2012 Max. : 39.0000 Max. : 30.0000 Max. : 11.000
(Other) :127 NA's :46 NA's :71
PropR Republican
Min. :0.0000 Min. :0.0000
1st Qu.:0.0000 1st Qu.:0.0000
Median :0.6250 Median :1.0000
Mean :0.5259 Mean :0.5103
3rd Qu.:1.0000 3rd Qu.:1.0000
Max. :1.0000 Max. :1.0000
> install.packages("mice")
> library(mice)
]
> sample = r[c("Rasmussen", "SurveyUSA", "PropR", "DiffCount")]
> summary(sample)
Rasmussen SurveyUSA PropR DiffCount
Min. :-41.0000 Min. :-33.0000 Min. :0.0000 Min. :-19.000
1st Qu.: -8.0000 1st Qu.:-11.7500 1st Qu.:0.0000 1st Qu.: -6.000
Median : 1.0000 Median : -2.0000 Median :0.6250 Median : 1.000
Mean : 0.0404 Mean : -0.8243 Mean :0.5259 Mean : -1.269
3rd Qu.: 8.5000 3rd Qu.: 8.0000 3rd Qu.:1.0000 3rd Qu.: 4.000
Max. : 39.0000 Max. : 30.0000 Max. :1.0000 Max. : 11.000
NA's :46 NA's :71
> set.seed(144)
> imputed = complete(mice(sample))
iter imp variable
1 1 Rasmussen SurveyUSA
1 2 Rasmussen SurveyUSA
1 3 Rasmussen SurveyUSA
1 4 Rasmussen SurveyUSA
1 5 Rasmussen SurveyUSA
2 1 Rasmussen SurveyUSA
2 2 Rasmussen SurveyUSA
2 3 Rasmussen SurveyUSA
2 4 Rasmussen SurveyUSA
2 5 Rasmussen SurveyUSA
3 1 Rasmussen SurveyUSA
3 2 Rasmussen SurveyUSA
3 3 Rasmussen SurveyUSA
3 4 Rasmussen SurveyUSA
3 5 Rasmussen SurveyUSA
4 1 Rasmussen SurveyUSA
4 2 Rasmussen SurveyUSA
4 3 Rasmussen SurveyUSA
4 4 Rasmussen SurveyUSA
4 5 Rasmussen SurveyUSA
5 1 Rasmussen SurveyUSA
5 2 Rasmussen SurveyUSA
5 3 Rasmussen SurveyUSA
5 4 Rasmussen SurveyUSA
5 5 Rasmussen SurveyUSA
> summary(imputed)
Rasmussen SurveyUSA
Min. :-41.000 Min. :-33.000
1st Qu.: -8.000 1st Qu.:-11.000
Median : 3.000 Median : 1.000
Mean : 1.731 Mean : 1.517
3rd Qu.: 11.000 3rd Qu.: 18.000
Max. : 39.000 Max. : 30.000
> no NA values
now change both the new variable
given below
r$Rasmussen = imputed$Rasmussen
> r$SurveyUSA = imputed$SurveyUSA
> summary(r)
State Year Rasmussen SurveyUSA DiffCount
Arizona : 3 Min. :2004 Min. :-41.000 Min. :-33.000 Min. :-19.000
Arkansas : 3 1st Qu.:2004 1st Qu.: -8.000 1st Qu.:-11.000 1st Qu.: -6.000
California : 3 Median :2008 Median : 3.000 Median : 1.000 Median : 1.000
Colorado : 3 Mean :2008 Mean : 1.731 Mean : 1.517 Mean : -1.269
Connecticut: 3 3rd Qu.:2012 3rd Qu.: 11.000 3rd Qu.: 18.000 3rd Qu.: 4.000
Florida : 3 Max. :2012 Max. : 39.000 Max. : 30.000 Max. : 11.000
(Other) :127
PropR Republican
Min. :0.0000 Min. :0.0000
1st Qu.:0.0000 1st Qu.:0.0000
Median :0.6250 Median :1.0000
Mean :0.5259 Mean :0.5103
3rd Qu.:1.0000 3rd Qu.:1.0000
Max. :1.0000 Max. :1.0000
No comments:
Post a Comment