Obtaining Complete Dataset with Imputed Values

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Obtaining Complete Dataset with Imputed Values

PaulJr
Dear friends, hope all is well with you,

I am working with package mi for data inputation. Currently working with R
version 3.5.0 (64-bit).

Say my data is  defined as dat, and I do the following:

datimputations <- mi(dat[2:5], n.iter=50)
completedat <- complete(datimputations)

After using the complete function, I get the following error message:

Error in complete(datimputations, m = 1) : 'data' not of class 'mids'

How can I retrieve the processed dataframe (along with the imputed values)?

Here is my dput() for you to see

> dput(head(dat,100))
structure(list(TransitDate = structure(c(496990800, 499669200,
502261200, 504939600, 507618000, 510037200, 512715600, 515307600,
517986000, 520578000, 523256400, 525934800, 528526800, 531205200,
533797200, 536475600, 539154000, 541573200, 544251600, 546843600,
549522000, 552114000, 554792400, 557470800, 560062800, 562741200,
565333200, 568011600, 570690000, 573195600, 575874000, 578466000,
581144400, 583736400, 586414800, 589093200, 591685200, 594363600,
596955600, 599634000, 602312400, 604731600, 607410000, 610002000,
612680400, 615272400, 617950800, 620629200, 623221200, 625899600,
628491600, 631170000, 633848400, 636267600, 638946000, 641538000,
644216400, 646808400, 649486800, 652165200, 654757200, 657435600,
660027600, 662706000, 665384400, 667803600, 670482000, 673074000,
675752400, 678344400, 681022800, 683701200, 686293200, 688971600,
691563600, 694242000, 696920400, 699426000, 702104400, 704696400,
707371200, 709963200, 712641600, 715320000, 717912000, 720590400,
723182400, 725860800, 728539200, 730958400, 733636800, 736232400,
738910800, 741502800, 744181200, 746859600, 749451600, 752130000,
754722000, 757400400), class = c("POSIXct", "POSIXt"), tzone = ""),
    Transits = c(14L, 14L, 13L, 10L, 11L, 14L, 14L, 14L, 16L,
    6L, 8L, 6L, 6L, 7L, 7L, 9L, 7L, 9L, 3L, 12L, 7L, 8L, 10L,
    9L, 10L, 11L, 9L, 9L, 5L, 11L, 12L, 7L, 12L, 10L, 9L, 13L,
    7L, 7L, 8L, 4L, 4L, 7L, 5L, 7L, 7L, 6L, 9L, 4L, 7L, 9L, 5L,
    5L, 10L, 6L, 6L, 13L, 6L, 7L, 10L, 7L, 8L, 5L, 6L, 7L, 6L,
    9L, 8L, 10L, 9L, 9L, 12L, 5L, 9L, 6L, 7L, 10L, 10L, 9L, 14L,
    14L, 15L, 14L, 16L, 17L, 18L, 11L, 15L, 14L, 8L, 13L, 10L,
    9L, 12L, 8L, 12L, 10L, 11L, 10L, 9L, 10L), CargoTons = c(154973L,
    129636L, 136884L, 86348L, 109907L, 154506L, 144083L, 152794L,
    124861L, 60330L, 65221L, 61718L, 53997L, 83536L, 63218L,
    98222L, 54719L, 98470L, 18263L, 104255L, 62869L, 62523L,
    75344L, 81476L, 92818L, 87457L, 85231L, 77897L, 57699L, 96989L,
    109361L, 59799L, 91116L, 82241L, 74251L, 124361L, 68751L,
    61719L, 68017L, 37760L, 32513L, 56359L, 51333L, 80859L, 75852L,
    65760L, 96043L, 38820L, 63202L, 102647L, 49104L, 53482L,
    121305L, 71795L, 76704L, 146097L, 73047L, 68557L, 110642L,
    77616L, 97767L, 52059L, 58658L, 66350L, 69303L, 76013L, 91909L,
    108445L, 94454L, 101249L, 112131L, 56290L, 118342L, 70618L,
    64783L, 112839L, 120506L, 94243L, 130768L, 133643L, 146321L,
    140736L, 147234L, 158953L, 189888L, 93819L, 130021L, 130124L,
    55088L, 114783L, 95184L, 82205L, 80321L, 65422L, 98933L,
    93713L, 98417L, 97210L, 88464L, 94659L), RcnstPCUMS = c(229914L,
    214547L, 215890L, 158695L, 173125L, 222533L, 212490L, 222125L,
    266913L, 94268L, 112967L, 95480L, 87654L, 108996L, 97973L,
    139247L, 93817L, 133197L, 40020L, 169749L, 102590L, 112121L,
    140241L, 122989L, 144592L, 144979L, 123748L, 123249L, 70081L,
    155218L, 168096L, 104743L, 163384L, 142648L, 129188L, 183170L,
    99299L, 99873L, 111648L, 55890L, 59183L, 95568L, 72550L,
    104562L, 100478L, 92665L, 130625L, 54786L, 105900L, 135833L,
    70932L, 73247L, 149632L, 94317L, 87926L, 181989L, 92778L,
    107097L, 153246L, 105175L, 126393L, 81976L, 95518L, 109019L,
    95370L, 140492L, 125795L, 157978L, 138424L, 138160L, 180320L,
    78757L, 135860L, 85921L, 114847L, 151965L, 152561L, 132841L,
    204839L, 209567L, 224436L, 210209L, 227143L, 245968L, 264969L,
    158648L, 222251L, 194335L, 111618L, 189643L, 137438L, 124953L,
    163155L, 107633L, 164525L, 135102L, 152072L, 126636L, 121008L,
    137824L), TotalToll = c(420742L, 392621L, 395078L, 290411L,
    316818L, 407235L, 388856L, 406488L, 482774L, 172510L, 206729L,
    174728L, 160406L, 199462L, 179290L, 254822L, 171685L, 243750L,
    73236L, 310640L, 187739L, 205181L, 249438L, 225069L, 264603L,
    265311L, 226458L, 225545L, 128248L, 284048L, 296023L, 184934L,
    298992L, 261045L, 236414L, 335201L, 181717L, 182767L, 204315L,
    102278L, 108304L, 174889L, 132766L, 191348L, 183874L, 169576L,
    239043L, 100258L, 212859L, 273024L, 142573L, 147226L, 300760L,
    189577L, 176731L, 365797L, 186483L, 215264L, 308024L, 211401L,
    254049L, 164771L, 191991L, 219128L, 191693L, 282388L, 252847L,
    317535L, 278232L, 277701L, 356022L, 158301L, 273078L, 172701L,
    230842L, 305449L, 306647L, 267010L, 406202L, 421229L, 451116L,
    422520L, 456557L, 494395L, 582202L, 350612L, 491174L, 429480L,
    239858L, 419111L, 303737L, 276146L, 360572L, 237868L, 358627L,
    298575L, 336079L, 279865L, 267427L, 304591L)), row.names = c(NA,
100L), class = "data.frame")

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Obtaining Complete Dataset with Imputed Values

Bill Poling
Good morning Paul.

I am unfamiliar with the package you are using but I have been working through the tutorial for this purpose using finalfit, if that is any help.

Cheers

WHP

http://www.datasurg.net/2018/08/29/five-steps-for-missing-data-with-finalfit/


From: R-help <[hidden email]> On Behalf Of Paul Bernal
Sent: Friday, August 24, 2018 2:57 PM
To: [hidden email]
Subject: [R] Obtaining Complete Dataset with Imputed Values

Dear friends, hope all is well with you,

I am working with package mi for data inputation. Currently working with R
version 3.5.0 (64-bit).

Say my data is defined as dat, and I do the following:

datimputations <- mi(dat[2:5], n.iter=50)
completedat <- complete(datimputations)

After using the complete function, I get the following error message:

Error in complete(datimputations, m = 1) : 'data' not of class 'mids'

How can I retrieve the processed dataframe (along with the imputed values)?

Here is my dput() for you to see

> dput(head(dat,100))
structure(list(TransitDate = structure(c(496990800, 499669200,
502261200, 504939600, 507618000, 510037200, 512715600, 515307600,
517986000, 520578000, 523256400, 525934800, 528526800, 531205200,
533797200, 536475600, 539154000, 541573200, 544251600, 546843600,
549522000, 552114000, 554792400, 557470800, 560062800, 562741200,
565333200, 568011600, 570690000, 573195600, 575874000, 578466000,
581144400, 583736400, 586414800, 589093200, 591685200, 594363600,
596955600, 599634000, 602312400, 604731600, 607410000, 610002000,
612680400, 615272400, 617950800, 620629200, 623221200, 625899600,
628491600, 631170000, 633848400, 636267600, 638946000, 641538000,
644216400, 646808400, 649486800, 652165200, 654757200, 657435600,
660027600, 662706000, 665384400, 667803600, 670482000, 673074000,
675752400, 678344400, 681022800, 683701200, 686293200, 688971600,
691563600, 694242000, 696920400, 699426000, 702104400, 704696400,
707371200, 709963200, 712641600, 715320000, 717912000, 720590400,
723182400, 725860800, 728539200, 730958400, 733636800, 736232400,
738910800, 741502800, 744181200, 746859600, 749451600, 752130000,
754722000, 757400400), class = c("POSIXct", "POSIXt"), tzone = ""),
Transits = c(14L, 14L, 13L, 10L, 11L, 14L, 14L, 14L, 16L,
6L, 8L, 6L, 6L, 7L, 7L, 9L, 7L, 9L, 3L, 12L, 7L, 8L, 10L,
9L, 10L, 11L, 9L, 9L, 5L, 11L, 12L, 7L, 12L, 10L, 9L, 13L,
7L, 7L, 8L, 4L, 4L, 7L, 5L, 7L, 7L, 6L, 9L, 4L, 7L, 9L, 5L,
5L, 10L, 6L, 6L, 13L, 6L, 7L, 10L, 7L, 8L, 5L, 6L, 7L, 6L,
9L, 8L, 10L, 9L, 9L, 12L, 5L, 9L, 6L, 7L, 10L, 10L, 9L, 14L,
14L, 15L, 14L, 16L, 17L, 18L, 11L, 15L, 14L, 8L, 13L, 10L,
9L, 12L, 8L, 12L, 10L, 11L, 10L, 9L, 10L), CargoTons = c(154973L,
129636L, 136884L, 86348L, 109907L, 154506L, 144083L, 152794L,
124861L, 60330L, 65221L, 61718L, 53997L, 83536L, 63218L,
98222L, 54719L, 98470L, 18263L, 104255L, 62869L, 62523L,
75344L, 81476L, 92818L, 87457L, 85231L, 77897L, 57699L, 96989L,
109361L, 59799L, 91116L, 82241L, 74251L, 124361L, 68751L,
61719L, 68017L, 37760L, 32513L, 56359L, 51333L, 80859L, 75852L,
65760L, 96043L, 38820L, 63202L, 102647L, 49104L, 53482L,
121305L, 71795L, 76704L, 146097L, 73047L, 68557L, 110642L,
77616L, 97767L, 52059L, 58658L, 66350L, 69303L, 76013L, 91909L,
108445L, 94454L, 101249L, 112131L, 56290L, 118342L, 70618L,
64783L, 112839L, 120506L, 94243L, 130768L, 133643L, 146321L,
140736L, 147234L, 158953L, 189888L, 93819L, 130021L, 130124L,
55088L, 114783L, 95184L, 82205L, 80321L, 65422L, 98933L,
93713L, 98417L, 97210L, 88464L, 94659L), RcnstPCUMS = c(229914L,
214547L, 215890L, 158695L, 173125L, 222533L, 212490L, 222125L,
266913L, 94268L, 112967L, 95480L, 87654L, 108996L, 97973L,
139247L, 93817L, 133197L, 40020L, 169749L, 102590L, 112121L,
140241L, 122989L, 144592L, 144979L, 123748L, 123249L, 70081L,
155218L, 168096L, 104743L, 163384L, 142648L, 129188L, 183170L,
99299L, 99873L, 111648L, 55890L, 59183L, 95568L, 72550L,
104562L, 100478L, 92665L, 130625L, 54786L, 105900L, 135833L,
70932L, 73247L, 149632L, 94317L, 87926L, 181989L, 92778L,
107097L, 153246L, 105175L, 126393L, 81976L, 95518L, 109019L,
95370L, 140492L, 125795L, 157978L, 138424L, 138160L, 180320L,
78757L, 135860L, 85921L, 114847L, 151965L, 152561L, 132841L,
204839L, 209567L, 224436L, 210209L, 227143L, 245968L, 264969L,
158648L, 222251L, 194335L, 111618L, 189643L, 137438L, 124953L,
163155L, 107633L, 164525L, 135102L, 152072L, 126636L, 121008L,
137824L), TotalToll = c(420742L, 392621L, 395078L, 290411L,
316818L, 407235L, 388856L, 406488L, 482774L, 172510L, 206729L,
174728L, 160406L, 199462L, 179290L, 254822L, 171685L, 243750L,
73236L, 310640L, 187739L, 205181L, 249438L, 225069L, 264603L,
265311L, 226458L, 225545L, 128248L, 284048L, 296023L, 184934L,
298992L, 261045L, 236414L, 335201L, 181717L, 182767L, 204315L,
102278L, 108304L, 174889L, 132766L, 191348L, 183874L, 169576L,
239043L, 100258L, 212859L, 273024L, 142573L, 147226L, 300760L,
189577L, 176731L, 365797L, 186483L, 215264L, 308024L, 211401L,
254049L, 164771L, 191991L, 219128L, 191693L, 282388L, 252847L,
317535L, 278232L, 277701L, 356022L, 158301L, 273078L, 172701L,
230842L, 305449L, 306647L, 267010L, 406202L, 421229L, 451116L,
422520L, 456557L, 494395L, 582202L, 350612L, 491174L, 429480L,
239858L, 419111L, 303737L, 276146L, 360572L, 237868L, 358627L,
298575L, 336079L, 279865L, 267427L, 304591L)), row.names = c(NA,
100L), class = "data.frame")

[[alternative HTML version deleted]]

______________________________________________
[hidden email]<mailto:[hidden email]> mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html<http://www.R-project.org/posting-guide.html>
and provide commented, minimal, self-contained, reproducible code.

Confidentiality Notice This message is sent from Zelis. ...{{dropped:15}}

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Obtaining Complete Dataset with Imputed Values

Fox, John
In reply to this post by PaulJr
Dear Paul and WHP,

My guess: Paul apparently has loaded the mice package after the mi package. Both packages have complete() functions, but for objects of different classes -- "mids" in the case of mice. Consquently, complete() in the mice package is shadowing complete() in the mi package.

The solution is not to load both packages unless you actually need to, load mi after mice (though then other similar problems might surface), or invoke mi::complete()  explicitly.

I hope this helps,
 John

-----------------------------------------------------------------
John Fox
Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
Web: https://socialsciences.mcmaster.ca/jfox/




> -----Original Message-----
> From: R-help [mailto:[hidden email]] On Behalf Of Bill Poling
> Sent: Thursday, August 30, 2018 8:42 AM
> To: Paul Bernal <[hidden email]>; [hidden email]
> Subject: Re: [R] Obtaining Complete Dataset with Imputed Values
>
> Good morning Paul.
>
> I am unfamiliar with the package you are using but I have been working
> through the tutorial for this purpose using finalfit, if that is any help.
>
> Cheers
>
> WHP
>
> http://www.datasurg.net/2018/08/29/five-steps-for-missing-data-with-
> finalfit/
>
>
> From: R-help <[hidden email]> On Behalf Of Paul Bernal
> Sent: Friday, August 24, 2018 2:57 PM
> To: [hidden email]
> Subject: [R] Obtaining Complete Dataset with Imputed Values
>
> Dear friends, hope all is well with you,
>
> I am working with package mi for data inputation. Currently working with R
> version 3.5.0 (64-bit).
>
> Say my data is defined as dat, and I do the following:
>
> datimputations <- mi(dat[2:5], n.iter=50) completedat <-
> complete(datimputations)
>
> After using the complete function, I get the following error message:
>
> Error in complete(datimputations, m = 1) : 'data' not of class 'mids'
>
> How can I retrieve the processed dataframe (along with the imputed values)?
>
> Here is my dput() for you to see
>
> > dput(head(dat,100))
> structure(list(TransitDate = structure(c(496990800, 499669200, 502261200,
> 504939600, 507618000, 510037200, 512715600, 515307600, 517986000,
> 520578000, 523256400, 525934800, 528526800, 531205200, 533797200,
> 536475600, 539154000, 541573200, 544251600, 546843600, 549522000,
> 552114000, 554792400, 557470800, 560062800, 562741200, 565333200,
> 568011600, 570690000, 573195600, 575874000, 578466000, 581144400,
> 583736400, 586414800, 589093200, 591685200, 594363600, 596955600,
> 599634000, 602312400, 604731600, 607410000, 610002000, 612680400,
> 615272400, 617950800, 620629200, 623221200, 625899600, 628491600,
> 631170000, 633848400, 636267600, 638946000, 641538000, 644216400,
> 646808400, 649486800, 652165200, 654757200, 657435600, 660027600,
> 662706000, 665384400, 667803600, 670482000, 673074000, 675752400,
> 678344400, 681022800, 683701200, 686293200, 688971600, 691563600,
> 694242000, 696920400, 699426000, 702104400, 704696400, 707371200,
> 709963200, 712641600, 715320000, 717912000, 720590400, 723182400,
> 725860800, 728539200, 730958400, 733636800, 736232400, 738910800,
> 741502800, 744181200, 746859600, 749451600, 752130000, 754722000,
> 757400400), class = c("POSIXct", "POSIXt"), tzone = ""), Transits = c(14L, 14L,
> 13L, 10L, 11L, 14L, 14L, 14L, 16L, 6L, 8L, 6L, 6L, 7L, 7L, 9L, 7L, 9L, 3L, 12L, 7L,
> 8L, 10L, 9L, 10L, 11L, 9L, 9L, 5L, 11L, 12L, 7L, 12L, 10L, 9L, 13L, 7L, 7L, 8L, 4L,
> 4L, 7L, 5L, 7L, 7L, 6L, 9L, 4L, 7L, 9L, 5L, 5L, 10L, 6L, 6L, 13L, 6L, 7L, 10L, 7L, 8L,
> 5L, 6L, 7L, 6L, 9L, 8L, 10L, 9L, 9L, 12L, 5L, 9L, 6L, 7L, 10L, 10L, 9L, 14L, 14L, 15L,
> 14L, 16L, 17L, 18L, 11L, 15L, 14L, 8L, 13L, 10L, 9L, 12L, 8L, 12L, 10L, 11L, 10L,
> 9L, 10L), CargoTons = c(154973L, 129636L, 136884L, 86348L, 109907L,
> 154506L, 144083L, 152794L, 124861L, 60330L, 65221L, 61718L, 53997L,
> 83536L, 63218L, 98222L, 54719L, 98470L, 18263L, 104255L, 62869L, 62523L,
> 75344L, 81476L, 92818L, 87457L, 85231L, 77897L, 57699L, 96989L, 109361L,
> 59799L, 91116L, 82241L, 74251L, 124361L, 68751L, 61719L, 68017L, 37760L,
> 32513L, 56359L, 51333L, 80859L, 75852L, 65760L, 96043L, 38820L, 63202L,
> 102647L, 49104L, 53482L, 121305L, 71795L, 76704L, 146097L, 73047L,
> 68557L, 110642L, 77616L, 97767L, 52059L, 58658L, 66350L, 69303L, 76013L,
> 91909L, 108445L, 94454L, 101249L, 112131L, 56290L, 118342L, 70618L,
> 64783L, 112839L, 120506L, 94243L, 130768L, 133643L, 146321L, 140736L,
> 147234L, 158953L, 189888L, 93819L, 130021L, 130124L, 55088L, 114783L,
> 95184L, 82205L, 80321L, 65422L, 98933L, 93713L, 98417L, 97210L, 88464L,
> 94659L), RcnstPCUMS = c(229914L, 214547L, 215890L, 158695L, 173125L,
> 222533L, 212490L, 222125L, 266913L, 94268L, 112967L, 95480L, 87654L,
> 108996L, 97973L, 139247L, 93817L, 133197L, 40020L, 169749L, 102590L,
> 112121L, 140241L, 122989L, 144592L, 144979L, 123748L, 123249L, 70081L,
> 155218L, 168096L, 104743L, 163384L, 142648L, 129188L, 183170L, 99299L,
> 99873L, 111648L, 55890L, 59183L, 95568L, 72550L, 104562L, 100478L,
> 92665L, 130625L, 54786L, 105900L, 135833L, 70932L, 73247L, 149632L,
> 94317L, 87926L, 181989L, 92778L, 107097L, 153246L, 105175L, 126393L,
> 81976L, 95518L, 109019L, 95370L, 140492L, 125795L, 157978L, 138424L,
> 138160L, 180320L, 78757L, 135860L, 85921L, 114847L, 151965L, 152561L,
> 132841L, 204839L, 209567L, 224436L, 210209L, 227143L, 245968L, 264969L,
> 158648L, 222251L, 194335L, 111618L, 189643L, 137438L, 124953L, 163155L,
> 107633L, 164525L, 135102L, 152072L, 126636L, 121008L, 137824L), TotalToll
> = c(420742L, 392621L, 395078L, 290411L, 316818L, 407235L, 388856L,
> 406488L, 482774L, 172510L, 206729L, 174728L, 160406L, 199462L, 179290L,
> 254822L, 171685L, 243750L, 73236L, 310640L, 187739L, 205181L, 249438L,
> 225069L, 264603L, 265311L, 226458L, 225545L, 128248L, 284048L, 296023L,
> 184934L, 298992L, 261045L, 236414L, 335201L, 181717L, 182767L, 204315L,
> 102278L, 108304L, 174889L, 132766L, 191348L, 183874L, 169576L, 239043L,
> 100258L, 212859L, 273024L, 142573L, 147226L, 300760L, 189577L, 176731L,
> 365797L, 186483L, 215264L, 308024L, 211401L, 254049L, 164771L, 191991L,
> 219128L, 191693L, 282388L, 252847L, 317535L, 278232L, 277701L, 356022L,
> 158301L, 273078L, 172701L, 230842L, 305449L, 306647L, 267010L, 406202L,
> 421229L, 451116L, 422520L, 456557L, 494395L, 582202L, 350612L, 491174L,
> 429480L, 239858L, 419111L, 303737L, 276146L, 360572L, 237868L, 358627L,
> 298575L, 336079L, 279865L, 267427L, 304591L)), row.names = c(NA, 100L),
> class = "data.frame")
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email]<mailto:[hidden email]> mailing list -- To
> UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-
> help<https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html<http://www.R-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
> Confidentiality Notice This message is sent from Zelis. ...{{dropped:15}}
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.