R Markdown

Using the famous Galton data set from the mosaicData package:

library(mosaic)
## Loading required package: dplyr
## Warning: Installed Rcpp (0.12.10) different from Rcpp used to build dplyr (0.12.11).
## Please reinstall dplyr to avoid random crashes or undefined behavior.
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## Loading required package: lattice
## Loading required package: ggplot2
## Loading required package: mosaicData
## Loading required package: Matrix
## 
## The 'mosaic' package masks several functions from core packages in order to add additional features.  
## The original behavior of these functions should not be affected by this.
## 
## Attaching package: 'mosaic'
## The following object is masked from 'package:Matrix':
## 
##     mean
## The following objects are masked from 'package:dplyr':
## 
##     count, do, tally
## The following objects are masked from 'package:stats':
## 
##     binom.test, cor, cov, D, fivenum, IQR, median, prop.test,
##     quantile, sd, t.test, var
## The following objects are masked from 'package:base':
## 
##     max, mean, min, prod, range, sample, sum
head(Galton)
##   family father mother sex height nkids
## 1      1   78.5   67.0   M   73.2     4
## 2      1   78.5   67.0   F   69.2     4
## 3      1   78.5   67.0   F   69.0     4
## 4      1   78.5   67.0   F   69.0     4
## 5      2   75.5   66.5   M   73.5     4
## 6      2   75.5   66.5   M   72.5     4

Create a scatterplot of each person’s height against their father’s height

head(Galton)
##   family father mother sex height nkids
## 1      1   78.5   67.0   M   73.2     4
## 2      1   78.5   67.0   F   69.2     4
## 3      1   78.5   67.0   F   69.0     4
## 4      1   78.5   67.0   F   69.0     4
## 5      2   75.5   66.5   M   73.5     4
## 6      2   75.5   66.5   M   72.5     4
g <- ggplot(data = Galton, aes(y = father, x = height))
g + geom_point(size = 3)

g + geom_point(aes(color = height), size = 3)

g <- ggplot(data = Galton, aes(y = father, x = height))
g + geom_point(size = 3)

Separate your plot into facets by sex

g + geom_point(aes(color = height), size = 3)+
facet_wrap(~sex, nrow = 1)+ theme(legend.position = "top")

Add regression lines to all of your facets

g + geom_point(aes(color = sex), size = 3)+
facet_wrap(~sex, nrow = 1)+ theme(legend.position = "top")+ geom_smooth(method = "lm", se = 0) +
xlab("height") +
ylab("father's height")

Using the RailTrail data set from the mosaicData package:

library(mosaic)
head(RailTrail)
##   hightemp lowtemp avgtemp spring summer fall cloudcover precip volume
## 1       83      50    66.5      0      1    0        7.6   0.00    501
## 2       73      49    61.0      0      1    0        6.3   0.29    419
## 3       74      52    63.0      1      0    0        7.5   0.32    397
## 4       95      61    78.0      0      1    0        2.6   0.00    385
## 5       44      52    48.0      1      0    0       10.0   0.14    200
## 6       69      54    61.5      1      0    0        6.6   0.02    375
##   weekday
## 1       1
## 2       1
## 3       1
## 4       0
## 5       1
## 6       1

Create a scatterplot of the number of crossings per day volume against the high temperature that day

g <- ggplot(data = RailTrail, aes(y = hightemp, x = volume))
g + geom_point(size = 3)

Separate your plot into facets by weekday. Add regression lines to the two facets

g + geom_point(aes(color = weekday), size = 3)+
facet_wrap(~weekday, nrow = 1)+ theme(legend.position = "top")+ geom_smooth(method = "lm", se = 0) +
xlab("volume") +
ylab("high temperature")

library(mosaic)
head(Marriage, 2)
##   bookpageID  appdate ceremonydate delay     officialTitle person     dob
## 1   B230p539 10/29/96      11/9/96    11    CIRCUIT JUDGE   Groom 4/11/64
## 2   B230p677 11/12/96     11/12/96     0 MARRIAGE OFFICIAL  Groom  8/6/64
##        age  race prevcount prevconc hs college dayOfBirth  sign
## 1 32.60274 White         0     <NA> 12       7        102 Aries
## 2 32.29041 White         1  Divorce 12       0        219   Leo
g <- ggplot(data = Marriage, aes(y = delay, x = age))
g + geom_point(size = 3)

g + geom_point(aes(color = person), size = 3)+
facet_wrap(~person, nrow = 1)+ theme(legend.position = "top")+ geom_smooth(method = "lm", se = 0) +
xlab("age") +
ylab("delay")

library(mdsr)
head(MLB_teams, 4)
## # A tibble: 4 x 11
##   yearID teamID   lgID     W     L      WPct attendance normAttend
##    <int>  <chr> <fctr> <int> <int>     <dbl>      <int>      <dbl>
## 1   2008    ARI     NL    82    80 0.5061728    2509924  0.5838859
## 2   2008    ATL     NL    72    90 0.4444444    2532834  0.5892155
## 3   2008    BAL     AL    68    93 0.4223602    1950075  0.4536477
## 4   2008    BOS     AL    95    67 0.5864198    3048250  0.7091172
## # ... with 3 more variables: payroll <int>, metroPop <dbl>, name <chr>
str(MLB_teams)
## Classes 'tbl_df', 'tbl' and 'data.frame':    210 obs. of  11 variables:
##  $ yearID    : int  2008 2008 2008 2008 2008 2008 2008 2008 2008 2008 ...
##  $ teamID    : chr  "ARI" "ATL" "BAL" "BOS" ...
##  $ lgID      : Factor w/ 7 levels "AA","AL","FL",..: 5 5 2 2 2 5 5 2 5 2 ...
##  $ W         : int  82 72 68 95 89 97 74 81 74 74 ...
##  $ L         : int  80 90 93 67 74 64 88 81 88 88 ...
##  $ WPct      : num  0.506 0.444 0.422 0.586 0.546 ...
##  $ attendance: int  2509924 2532834 1950075 3048250 2500648 3300200 2058632 2169760 2650218 3202645 ...
##  $ normAttend: num  0.584 0.589 0.454 0.709 0.582 ...
##  $ payroll   : int  66202712 102365683 67196246 133390035 121189332 118345833 74117695 78970066 68655500 137685196 ...
##  $ metroPop  : num  4489109 5614323 2785874 4732161 9554598 ...
##  $ name      : chr  "Arizona Diamondbacks" "Atlanta Braves" "Baltimore Orioles" "Boston Red Sox" ...
p <- ggplot(
  data = MLB_teams,
  aes(x = reorder(teamID, payroll), y = WPct)) +
  geom_bar(fill = "green", stat = "identity") +
  ylab("winning percentage") + xlab("payroll") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1))
p

library(macleish)
## Loading required package: etl
head(whately_2015)
## # A tibble: 6 x 8
##                  when temperature wind_speed wind_dir rel_humidity
##                <dttm>       <dbl>      <dbl>    <dbl>        <dbl>
## 1 2015-01-01 00:00:00       -9.32      1.399    225.4        54.55
## 2 2015-01-01 00:10:00       -9.46      1.506    248.2        55.38
## 3 2015-01-01 00:20:00       -9.44      1.620    258.3        56.18
## 4 2015-01-01 00:30:00       -9.30      1.141    243.8        56.41
## 5 2015-01-01 00:40:00       -9.32      1.223    238.4        56.87
## 6 2015-01-01 00:50:00       -9.34      1.090    241.7        57.25
## # ... with 3 more variables: pressure <int>, solar_radiation <dbl>,
## #   rainfall <int>
str(whately_2015)
## Classes 'tbl_df', 'tbl' and 'data.frame':    52560 obs. of  8 variables:
##  $ when           : POSIXct, format: "2015-01-01 00:00:00" "2015-01-01 00:10:00" ...
##  $ temperature    : num  -9.32 -9.46 -9.44 -9.3 -9.32 -9.34 -9.3 -9.1 -9.07 -8.99 ...
##  $ wind_speed     : num  1.4 1.51 1.62 1.14 1.22 ...
##  $ wind_dir       : num  225 248 258 244 238 ...
##  $ rel_humidity   : num  54.5 55.4 56.2 56.4 56.9 ...
##  $ pressure       : int  985 985 985 985 984 984 984 984 984 984 ...
##  $ solar_radiation: num  0 0 0 0 0 0 0 0 0 0 ...
##  $ rainfall       : int  0 0 0 0 0 0 0 0 0 0 ...
summary(whately_2015)
##       when                      temperature         wind_speed   
##  Min.   :2015-01-01 00:00:00   Min.   :-22.2800   Min.   :0.000  
##  1st Qu.:2015-04-02 05:57:30   1st Qu.:  0.9187   1st Qu.:0.951  
##  Median :2015-07-02 11:55:00   Median : 10.1900   Median :1.453  
##  Mean   :2015-07-02 11:55:00   Mean   :  9.3543   Mean   :1.633  
##  3rd Qu.:2015-10-01 17:52:30   3rd Qu.: 18.6500   3rd Qu.:2.102  
##  Max.   :2015-12-31 23:50:00   Max.   : 33.0800   Max.   :8.020  
##     wind_dir      rel_humidity       pressure      solar_radiation   
##  Min.   :  0.0   Min.   : 14.26   Min.   : 958.0   Min.   :   0.000  
##  1st Qu.:150.4   1st Qu.: 56.60   1st Qu.: 980.0   1st Qu.:   0.000  
##  Median :217.3   Median : 76.28   Median : 985.0   Median :   2.884  
##  Mean   :211.8   Mean   : 74.30   Mean   : 985.2   Mean   : 164.494  
##  3rd Qu.:305.8   3rd Qu.: 99.90   3rd Qu.: 990.0   3rd Qu.: 259.500  
##  Max.   :360.0   Max.   :100.00   Max.   :1011.0   Max.   :1086.000  
##     rainfall       
##  Min.   : 0.00000  
##  1st Qu.: 0.00000  
##  Median : 0.00000  
##  Mean   : 0.01073  
##  3rd Qu.: 0.00000  
##  Max.   :16.00000
library(corrplot)
df.cor = cor(whately_2015[,c(2:8)])
df.cor
##                 temperature wind_speed    wind_dir rel_humidity
## temperature      1.00000000 -0.1904743 -0.07286716   0.17109035
## wind_speed      -0.19047428  1.0000000  0.15617499  -0.31791291
## wind_dir        -0.07286716  0.1561750  1.00000000  -0.18109717
## rel_humidity     0.17109035 -0.3179129 -0.18109717   1.00000000
## pressure        -0.09233977 -0.2139012 -0.18553935  -0.12903982
## solar_radiation  0.37066852  0.2379441 -0.09010549  -0.34074567
## rainfall         0.03461170  0.0101804 -0.01998011   0.05827162
##                    pressure solar_radiation    rainfall
## temperature     -0.09233977      0.37066852  0.03461170
## wind_speed      -0.21390123      0.23794406  0.01018040
## wind_dir        -0.18553935     -0.09010549 -0.01998011
## rel_humidity    -0.12903982     -0.34074567  0.05827162
## pressure         1.00000000      0.01934476 -0.03732375
## solar_radiation  0.01934476      1.00000000 -0.03142406
## rainfall        -0.03732375     -0.03142406  1.00000000
corrplot(df.cor, method="ellipse")

data ("BostonHousing", package="mlbench")
original <- BostonHousing

set.seed(123)
BostonHousing[sample(1:nrow(BostonHousing), 100), "ptratio"] <- NA
BostonHousing[sample(1:nrow(BostonHousing), 100), "b"] <- NA
library(Rcpp)
require(Amelia)
## Loading required package: Amelia
## ## 
## ## Amelia II: Multiple Imputation
## ## (Version 1.7.4, built: 2015-12-05)
## ## Copyright (C) 2005-2017 James Honaker, Gary King and Matthew Blackwell
## ## Refer to http://gking.harvard.edu/amelia/ for more information
## ##
missmap(BostonHousing, main="Missing Map")

#missing data proportions
sapply(BostonHousing, function(df) {
  + sum(is.na(df)==TRUE)/ length(df)
})
##      crim        zn     indus      chas       nox        rm       age 
## 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 
##       dis       rad       tax   ptratio         b     lstat      medv 
## 0.0000000 0.0000000 0.0000000 0.1976285 0.1976285 0.0000000 0.0000000
#missing data in numbers
sapply(BostonHousing, function(x) sum(is.na(x)))
##    crim      zn   indus    chas     nox      rm     age     dis     rad 
##       0       0       0       0       0       0       0       0       0 
##     tax ptratio       b   lstat    medv 
##       0     100     100       0       0
#missing data imputation
pMiss <- function(x){sum(is.na(x))/length(x)*100}
apply(BostonHousing,2,pMiss)
##     crim       zn    indus     chas      nox       rm      age      dis 
##  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000 
##      rad      tax  ptratio        b    lstat     medv 
##  0.00000  0.00000 19.76285 19.76285  0.00000  0.00000
apply(BostonHousing,1,pMiss)
##         1         2         3         4         5         6         7 
##  7.142857  0.000000  0.000000  0.000000  7.142857  0.000000  0.000000 
##         8         9        10        11        12        13        14 
##  0.000000  0.000000  0.000000  0.000000  7.142857  0.000000  0.000000 
##        15        16        17        18        19        20        21 
##  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000  7.142857 
##        22        23        24        25        26        27        28 
##  0.000000  7.142857  0.000000  0.000000  0.000000  0.000000  0.000000 
##        29        30        31        32        33        34        35 
##  0.000000  7.142857  0.000000  0.000000  0.000000  0.000000  0.000000 
##        36        37        38        39        40        41        42 
##  7.142857  0.000000  0.000000  7.142857  0.000000  0.000000  0.000000 
##        43        44        45        46        47        48        49 
##  7.142857 14.285714  0.000000  0.000000  0.000000  7.142857  0.000000 
##        50        51        52        53        54        55        56 
##  0.000000 14.285714  0.000000  0.000000  0.000000  7.142857  7.142857 
##        57        58        59        60        61        62        63 
##  0.000000  7.142857  0.000000  0.000000  0.000000  0.000000  7.142857 
##        64        65        66        67        68        69        70 
##  7.142857  0.000000  0.000000  7.142857  7.142857  0.000000  7.142857 
##        71        72        73        74        75        76        77 
##  7.142857  0.000000  7.142857  7.142857  7.142857  0.000000  0.000000 
##        78        79        80        81        82        83        84 
##  7.142857  0.000000  7.142857  0.000000  0.000000  0.000000  0.000000 
##        85        86        87        88        89        90        91 
##  0.000000  7.142857  0.000000  0.000000  0.000000  0.000000  0.000000 
##        92        93        94        95        96        97        98 
##  0.000000  0.000000  7.142857  7.142857  0.000000  0.000000  7.142857 
##        99       100       101       102       103       104       105 
##  0.000000  0.000000  0.000000  7.142857  0.000000  7.142857  0.000000 
##       106       107       108       109       110       111       112 
##  0.000000  7.142857  7.142857  7.142857  7.142857  0.000000  7.142857 
##       113       114       115       116       117       118       119 
##  7.142857  0.000000  7.142857  0.000000  7.142857  0.000000  0.000000 
##       120       121       122       123       124       125       126 
##  0.000000  7.142857  7.142857  0.000000  0.000000  0.000000  0.000000 
##       127       128       129       130       131       132       133 
##  0.000000  0.000000  0.000000  0.000000  0.000000  7.142857  7.142857 
##       134       135       136       137       138       139       140 
##  7.142857  0.000000  0.000000  0.000000  0.000000  7.142857  0.000000 
##       141       142       143       144       145       146       147 
##  0.000000  0.000000  7.142857  0.000000  0.000000 14.285714  0.000000 
##       148       149       150       151       152       153       154 
##  0.000000 14.285714  7.142857  7.142857  0.000000  0.000000  0.000000 
##       155       156       157       158       159       160       161 
##  0.000000  7.142857  0.000000  7.142857  0.000000  0.000000 14.285714 
##       162       163       164       165       166       167       168 
##  0.000000  0.000000  7.142857  0.000000  7.142857  7.142857  7.142857 
##       169       170       171       172       173       174       175 
##  7.142857  0.000000  7.142857  0.000000  0.000000  0.000000  0.000000 
##       176       177       178       179       180       181       182 
##  7.142857  7.142857  7.142857  7.142857  0.000000  7.142857  0.000000 
##       183       184       185       186       187       188       189 
##  0.000000  7.142857  0.000000  0.000000  0.000000  0.000000  0.000000 
##       190       191       192       193       194       195       196 
##  0.000000 14.285714 14.285714  7.142857  0.000000  0.000000  0.000000 
##       197       198       199       200       201       202       203 
##  7.142857  7.142857  0.000000  7.142857  0.000000  7.142857  7.142857 
##       204       205       206       207       208       209       210 
##  0.000000  7.142857 14.285714  7.142857  0.000000  7.142857  0.000000 
##       211       212       213       214       215       216       217 
##  0.000000  0.000000  0.000000  7.142857  0.000000  0.000000  0.000000 
##       218       219       220       221       222       223       224 
##  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000 
##       225       226       227       228       229       230       231 
## 14.285714  7.142857 14.285714  7.142857  0.000000  0.000000  0.000000 
##       232       233       234       235       236       237       238 
##  0.000000  0.000000  7.142857  0.000000  7.142857  7.142857  0.000000 
##       239       240       241       242       243       244       245 
##  0.000000  0.000000  0.000000  0.000000  7.142857  0.000000  0.000000 
##       246       247       248       249       250       251       252 
##  7.142857  7.142857  0.000000  7.142857  0.000000  7.142857  0.000000 
##       253       254       255       256       257       258       259 
##  0.000000  7.142857  0.000000  0.000000  7.142857  7.142857  0.000000 
##       260       261       262       263       264       265       266 
##  0.000000  0.000000  7.142857  7.142857  0.000000  7.142857  0.000000 
##       267       268       269       270       271       272       273 
##  7.142857  0.000000  0.000000  7.142857  0.000000  7.142857  0.000000 
##       274       275       276       277       278       279       280 
##  7.142857 14.285714  0.000000  0.000000  0.000000  0.000000  0.000000 
##       281       282       283       284       285       286       287 
##  0.000000  0.000000  7.142857  7.142857  7.142857  7.142857  0.000000 
##       288       289       290       291       292       293       294 
##  0.000000  7.142857  0.000000  0.000000  0.000000  0.000000  0.000000 
##       295       296       297       298       299       300       301 
##  7.142857  0.000000  7.142857  0.000000  0.000000  0.000000  7.142857 
##       302       303       304       305       306       307       308 
##  0.000000  0.000000  7.142857  0.000000  0.000000  0.000000  0.000000 
##       309       310       311       312       313       314       315 
##  7.142857  0.000000 14.285714  0.000000  0.000000  0.000000  7.142857 
##       316       317       318       319       320       321       322 
##  0.000000  7.142857  0.000000  0.000000  7.142857  7.142857  0.000000 
##       323       324       325       326       327       328       329 
##  0.000000  7.142857  0.000000  7.142857  0.000000  7.142857  7.142857 
##       330       331       332       333       334       335       336 
##  7.142857  0.000000  0.000000  0.000000  7.142857 14.285714  0.000000 
##       337       338       339       340       341       342       343 
##  7.142857  0.000000  7.142857  0.000000  7.142857  0.000000  0.000000 
##       344       345       346       347       348       349       350 
##  0.000000  0.000000  0.000000  0.000000  7.142857  7.142857  0.000000 
##       351       352       353       354       355       356       357 
##  0.000000  0.000000  0.000000  0.000000  7.142857  0.000000  7.142857 
##       358       359       360       361       362       363       364 
##  7.142857  0.000000  0.000000  7.142857  0.000000  7.142857  0.000000 
##       365       366       367       368       369       370       371 
##  0.000000  0.000000  0.000000  0.000000  7.142857  0.000000  7.142857 
##       372       373       374       375       376       377       378 
##  0.000000  0.000000  0.000000 14.285714  0.000000 14.285714  0.000000 
##       379       380       381       382       383       384       385 
##  0.000000  0.000000  0.000000  7.142857  0.000000  0.000000  0.000000 
##       386       387       388       389       390       391       392 
##  0.000000  7.142857  0.000000  0.000000  7.142857  0.000000  0.000000 
##       393       394       395       396       397       398       399 
##  7.142857  0.000000  0.000000  0.000000  0.000000  0.000000  7.142857 
##       400       401       402       403       404       405       406 
##  0.000000  7.142857  0.000000  0.000000  0.000000  0.000000  0.000000 
##       407       408       409       410       411       412       413 
##  0.000000  0.000000  7.142857  0.000000  0.000000  0.000000  0.000000 
##       414       415       416       417       418       419       420 
##  7.142857  7.142857  0.000000  0.000000  0.000000  0.000000  0.000000 
##       421       422       423       424       425       426       427 
##  0.000000  0.000000  0.000000  7.142857  0.000000  0.000000  0.000000 
##       428       429       430       431       432       433       434 
##  0.000000  7.142857  0.000000  0.000000  0.000000  7.142857  7.142857 
##       435       436       437       438       439       440       441 
##  0.000000  0.000000  0.000000  0.000000  0.000000  7.142857  0.000000 
##       442       443       444       445       446       447       448 
##  7.142857  0.000000  7.142857 14.285714  7.142857  7.142857  0.000000 
##       449       450       451       452       453       454       455 
##  7.142857  0.000000  0.000000  0.000000  7.142857  0.000000  0.000000 
##       456       457       458       459       460       461       462 
##  7.142857  0.000000 14.285714 14.285714  0.000000  0.000000  0.000000 
##       463       464       465       466       467       468       469 
##  7.142857  7.142857  7.142857  0.000000  7.142857  7.142857  0.000000 
##       470       471       472       473       474       475       476 
## 14.285714  0.000000  0.000000  7.142857  7.142857  7.142857  0.000000 
##       477       478       479       480       481       482       483 
##  7.142857  0.000000  0.000000  0.000000 14.285714  0.000000  7.142857 
##       484       485       486       487       488       489       490 
##  0.000000  0.000000  0.000000  7.142857  0.000000  7.142857  7.142857 
##       491       492       493       494       495       496       497 
##  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000 
##       498       499       500       501       502       503       504 
##  0.000000  0.000000  7.142857  7.142857  0.000000  0.000000  0.000000 
##       505       506 
##  0.000000  7.142857
library(mice)
md.pattern(BostonHousing)
##     crim zn indus chas nox rm age dis rad tax lstat medv ptratio   b    
## 326    1  1     1    1   1  1   1   1   1   1     1    1       1   1   0
##  80    1  1     1    1   1  1   1   1   1   1     1    1       0   1   1
##  80    1  1     1    1   1  1   1   1   1   1     1    1       1   0   1
##  20    1  1     1    1   1  1   1   1   1   1     1    1       0   0   2
##        0  0     0    0   0  0   0   0   0   0     0    0     100 100 200
library(VIM)
## Loading required package: colorspace
## Loading required package: grid
## Loading required package: data.table
## 
## Attaching package: 'data.table'
## The following objects are masked from 'package:dplyr':
## 
##     between, first, last
## VIM is ready to use. 
##  Since version 4.0.0 the GUI is in its own package VIMGUI.
## 
##           Please use the package to use the new (and old) GUI.
## Suggestions and bug-reports can be submitted at: https://github.com/alexkowa/VIM/issues
## 
## Attaching package: 'VIM'
## The following object is masked from 'package:datasets':
## 
##     sleep
aggr_plot <- aggr(BostonHousing, col=c('navyblue','red'), 
                  numbers=TRUE, 
                  sortVars=TRUE, 
                  labels=names(BostonHousing), 
                  cex.axis=.7, 
                  gap=3, 
                  ylab=c("Histogram of missing data","Pattern"))

## 
##  Variables sorted by number of missings: 
##  Variable     Count
##   ptratio 0.1976285
##         b 0.1976285
##      crim 0.0000000
##        zn 0.0000000
##     indus 0.0000000
##      chas 0.0000000
##       nox 0.0000000
##        rm 0.0000000
##       age 0.0000000
##       dis 0.0000000
##       rad 0.0000000
##       tax 0.0000000
##     lstat 0.0000000
##      medv 0.0000000
imputed <- mice(BostonHousing,m=5,maxit=50,meth='pmm',seed=500)
## 
##  iter imp variable
##   1   1  ptratio  b
##   1   2  ptratio  b
##   1   3  ptratio  b
##   1   4  ptratio  b
##   1   5  ptratio  b
##   2   1  ptratio  b
##   2   2  ptratio  b
##   2   3  ptratio  b
##   2   4  ptratio  b
##   2   5  ptratio  b
##   3   1  ptratio  b
##   3   2  ptratio  b
##   3   3  ptratio  b
##   3   4  ptratio  b
##   3   5  ptratio  b
##   4   1  ptratio  b
##   4   2  ptratio  b
##   4   3  ptratio  b
##   4   4  ptratio  b
##   4   5  ptratio  b
##   5   1  ptratio  b
##   5   2  ptratio  b
##   5   3  ptratio  b
##   5   4  ptratio  b
##   5   5  ptratio  b
##   6   1  ptratio  b
##   6   2  ptratio  b
##   6   3  ptratio  b
##   6   4  ptratio  b
##   6   5  ptratio  b
##   7   1  ptratio  b
##   7   2  ptratio  b
##   7   3  ptratio  b
##   7   4  ptratio  b
##   7   5  ptratio  b
##   8   1  ptratio  b
##   8   2  ptratio  b
##   8   3  ptratio  b
##   8   4  ptratio  b
##   8   5  ptratio  b
##   9   1  ptratio  b
##   9   2  ptratio  b
##   9   3  ptratio  b
##   9   4  ptratio  b
##   9   5  ptratio  b
##   10   1  ptratio  b
##   10   2  ptratio  b
##   10   3  ptratio  b
##   10   4  ptratio  b
##   10   5  ptratio  b
##   11   1  ptratio  b
##   11   2  ptratio  b
##   11   3  ptratio  b
##   11   4  ptratio  b
##   11   5  ptratio  b
##   12   1  ptratio  b
##   12   2  ptratio  b
##   12   3  ptratio  b
##   12   4  ptratio  b
##   12   5  ptratio  b
##   13   1  ptratio  b
##   13   2  ptratio  b
##   13   3  ptratio  b
##   13   4  ptratio  b
##   13   5  ptratio  b
##   14   1  ptratio  b
##   14   2  ptratio  b
##   14   3  ptratio  b
##   14   4  ptratio  b
##   14   5  ptratio  b
##   15   1  ptratio  b
##   15   2  ptratio  b
##   15   3  ptratio  b
##   15   4  ptratio  b
##   15   5  ptratio  b
##   16   1  ptratio  b
##   16   2  ptratio  b
##   16   3  ptratio  b
##   16   4  ptratio  b
##   16   5  ptratio  b
##   17   1  ptratio  b
##   17   2  ptratio  b
##   17   3  ptratio  b
##   17   4  ptratio  b
##   17   5  ptratio  b
##   18   1  ptratio  b
##   18   2  ptratio  b
##   18   3  ptratio  b
##   18   4  ptratio  b
##   18   5  ptratio  b
##   19   1  ptratio  b
##   19   2  ptratio  b
##   19   3  ptratio  b
##   19   4  ptratio  b
##   19   5  ptratio  b
##   20   1  ptratio  b
##   20   2  ptratio  b
##   20   3  ptratio  b
##   20   4  ptratio  b
##   20   5  ptratio  b
##   21   1  ptratio  b
##   21   2  ptratio  b
##   21   3  ptratio  b
##   21   4  ptratio  b
##   21   5  ptratio  b
##   22   1  ptratio  b
##   22   2  ptratio  b
##   22   3  ptratio  b
##   22   4  ptratio  b
##   22   5  ptratio  b
##   23   1  ptratio  b
##   23   2  ptratio  b
##   23   3  ptratio  b
##   23   4  ptratio  b
##   23   5  ptratio  b
##   24   1  ptratio  b
##   24   2  ptratio  b
##   24   3  ptratio  b
##   24   4  ptratio  b
##   24   5  ptratio  b
##   25   1  ptratio  b
##   25   2  ptratio  b
##   25   3  ptratio  b
##   25   4  ptratio  b
##   25   5  ptratio  b
##   26   1  ptratio  b
##   26   2  ptratio  b
##   26   3  ptratio  b
##   26   4  ptratio  b
##   26   5  ptratio  b
##   27   1  ptratio  b
##   27   2  ptratio  b
##   27   3  ptratio  b
##   27   4  ptratio  b
##   27   5  ptratio  b
##   28   1  ptratio  b
##   28   2  ptratio  b
##   28   3  ptratio  b
##   28   4  ptratio  b
##   28   5  ptratio  b
##   29   1  ptratio  b
##   29   2  ptratio  b
##   29   3  ptratio  b
##   29   4  ptratio  b
##   29   5  ptratio  b
##   30   1  ptratio  b
##   30   2  ptratio  b
##   30   3  ptratio  b
##   30   4  ptratio  b
##   30   5  ptratio  b
##   31   1  ptratio  b
##   31   2  ptratio  b
##   31   3  ptratio  b
##   31   4  ptratio  b
##   31   5  ptratio  b
##   32   1  ptratio  b
##   32   2  ptratio  b
##   32   3  ptratio  b
##   32   4  ptratio  b
##   32   5  ptratio  b
##   33   1  ptratio  b
##   33   2  ptratio  b
##   33   3  ptratio  b
##   33   4  ptratio  b
##   33   5  ptratio  b
##   34   1  ptratio  b
##   34   2  ptratio  b
##   34   3  ptratio  b
##   34   4  ptratio  b
##   34   5  ptratio  b
##   35   1  ptratio  b
##   35   2  ptratio  b
##   35   3  ptratio  b
##   35   4  ptratio  b
##   35   5  ptratio  b
##   36   1  ptratio  b
##   36   2  ptratio  b
##   36   3  ptratio  b
##   36   4  ptratio  b
##   36   5  ptratio  b
##   37   1  ptratio  b
##   37   2  ptratio  b
##   37   3  ptratio  b
##   37   4  ptratio  b
##   37   5  ptratio  b
##   38   1  ptratio  b
##   38   2  ptratio  b
##   38   3  ptratio  b
##   38   4  ptratio  b
##   38   5  ptratio  b
##   39   1  ptratio  b
##   39   2  ptratio  b
##   39   3  ptratio  b
##   39   4  ptratio  b
##   39   5  ptratio  b
##   40   1  ptratio  b
##   40   2  ptratio  b
##   40   3  ptratio  b
##   40   4  ptratio  b
##   40   5  ptratio  b
##   41   1  ptratio  b
##   41   2  ptratio  b
##   41   3  ptratio  b
##   41   4  ptratio  b
##   41   5  ptratio  b
##   42   1  ptratio  b
##   42   2  ptratio  b
##   42   3  ptratio  b
##   42   4  ptratio  b
##   42   5  ptratio  b
##   43   1  ptratio  b
##   43   2  ptratio  b
##   43   3  ptratio  b
##   43   4  ptratio  b
##   43   5  ptratio  b
##   44   1  ptratio  b
##   44   2  ptratio  b
##   44   3  ptratio  b
##   44   4  ptratio  b
##   44   5  ptratio  b
##   45   1  ptratio  b
##   45   2  ptratio  b
##   45   3  ptratio  b
##   45   4  ptratio  b
##   45   5  ptratio  b
##   46   1  ptratio  b
##   46   2  ptratio  b
##   46   3  ptratio  b
##   46   4  ptratio  b
##   46   5  ptratio  b
##   47   1  ptratio  b
##   47   2  ptratio  b
##   47   3  ptratio  b
##   47   4  ptratio  b
##   47   5  ptratio  b
##   48   1  ptratio  b
##   48   2  ptratio  b
##   48   3  ptratio  b
##   48   4  ptratio  b
##   48   5  ptratio  b
##   49   1  ptratio  b
##   49   2  ptratio  b
##   49   3  ptratio  b
##   49   4  ptratio  b
##   49   5  ptratio  b
##   50   1  ptratio  b
##   50   2  ptratio  b
##   50   3  ptratio  b
##   50   4  ptratio  b
##   50   5  ptratio  b
summary(imputed)
## Multiply imputed data set
## Call:
## mice(data = BostonHousing, m = 5, method = "pmm", maxit = 50, 
##     seed = 500)
## Number of multiple imputations:  5
## Missing cells per column:
##    crim      zn   indus    chas     nox      rm     age     dis     rad 
##       0       0       0       0       0       0       0       0       0 
##     tax ptratio       b   lstat    medv 
##       0     100     100       0       0 
## Imputation methods:
##    crim      zn   indus    chas     nox      rm     age     dis     rad 
##   "pmm"   "pmm"   "pmm"   "pmm"   "pmm"   "pmm"   "pmm"   "pmm"   "pmm" 
##     tax ptratio       b   lstat    medv 
##   "pmm"   "pmm"   "pmm"   "pmm"   "pmm" 
## VisitSequence:
## ptratio       b 
##      11      12 
## PredictorMatrix:
##         crim zn indus chas nox rm age dis rad tax ptratio b lstat medv
## crim       0  0     0    0   0  0   0   0   0   0       0 0     0    0
## zn         0  0     0    0   0  0   0   0   0   0       0 0     0    0
## indus      0  0     0    0   0  0   0   0   0   0       0 0     0    0
## chas       0  0     0    0   0  0   0   0   0   0       0 0     0    0
## nox        0  0     0    0   0  0   0   0   0   0       0 0     0    0
## rm         0  0     0    0   0  0   0   0   0   0       0 0     0    0
## age        0  0     0    0   0  0   0   0   0   0       0 0     0    0
## dis        0  0     0    0   0  0   0   0   0   0       0 0     0    0
## rad        0  0     0    0   0  0   0   0   0   0       0 0     0    0
## tax        0  0     0    0   0  0   0   0   0   0       0 0     0    0
## ptratio    1  1     1    1   1  1   1   1   1   1       0 1     1    1
## b          1  1     1    1   1  1   1   1   1   1       1 0     1    1
## lstat      0  0     0    0   0  0   0   0   0   0       0 0     0    0
## medv       0  0     0    0   0  0   0   0   0   0       0 0     0    0
## Random generator seed value:  500
completed <- complete(imputed,1)

library(lattice) 
xyplot(imputed, b ~ ptratio,pch=18,cex=1)