Individual AUC after multiple imputation using MICE









up vote
2
down vote

favorite












I have a question about calculating an AUC for every individual in a dataset, after imputation using MICE.



I know how I can do it in a complete cases dataset. I have done it as follows:



id <- c(1,2,3,4,5,6,7,8,9,10)
measure_1 <- c(60,80,90,55,60,61,77,67,88,90)
measure_2 <- c(55,88,88,55,70,61,80,66,65,92)
measure_3 <- c(62,88,85,56,68,62,89,62,70,99)
measure_4 <- c(62,90,83,54,65,62,91,59,67,96)
dat <- data.frame(id, measure_1, measure_2, measure_3, measure_4)
dat
x <- c(0,7,14,21) # number of days

library(Bolstad2)
f <- function(a)
Patient <- dat[a,]
vector_patient <- c(Patient[2:5])
AUCpatient <- sintegral(x,vector_patient)$int
return(AUCpatient)


vector <- c(1:10)
listAUC <- lapply(vector, f)
vector_AUC <- unlist(listAUC, use.names=FALSE)
vector_AUC


This gave me a vector with all the AUCs for all patients. This vector can be added to my dataset if I want to.



But now I have a problem: I have missings in my dataset. My dataset can be obtained using the following code:



id <- c(1,2,3,4,5,6,7,8,9,10)
measure1 <- c(60,NA,90,55,60,61,77,67,88,90)
measure2 <- c(55,NA,NA,55,70,NA,80,66,65,92)
measure3 <- c(62,88,85,NA,68,62,89,62,70,99)
measure4 <- c(62,90,83,54,NA,62,NA,59,67,96)
datmis <- data.frame(id, measure1, measure2, measure3, measure4)
datmis


I want to impute this dataset using MICE.



library(mice)
imp <- mice(datmis, maxit = 0)
meth <- imp$method
pred <- imp$predictorMatrix
imp <- mice(datmis, method = meth, predictorMatrix = pred, seed = 2018, maxit = 10, m = 5)


So now I have everything imputed. I want to create the AUCs for every individual, in every imputed dataset. Then I want to pool the results, resulting in one single AUC for every individual. However, using the formula create in the previous example does not work anymore. Is there someone who can help me out?










share|improve this question



























    up vote
    2
    down vote

    favorite












    I have a question about calculating an AUC for every individual in a dataset, after imputation using MICE.



    I know how I can do it in a complete cases dataset. I have done it as follows:



    id <- c(1,2,3,4,5,6,7,8,9,10)
    measure_1 <- c(60,80,90,55,60,61,77,67,88,90)
    measure_2 <- c(55,88,88,55,70,61,80,66,65,92)
    measure_3 <- c(62,88,85,56,68,62,89,62,70,99)
    measure_4 <- c(62,90,83,54,65,62,91,59,67,96)
    dat <- data.frame(id, measure_1, measure_2, measure_3, measure_4)
    dat
    x <- c(0,7,14,21) # number of days

    library(Bolstad2)
    f <- function(a)
    Patient <- dat[a,]
    vector_patient <- c(Patient[2:5])
    AUCpatient <- sintegral(x,vector_patient)$int
    return(AUCpatient)


    vector <- c(1:10)
    listAUC <- lapply(vector, f)
    vector_AUC <- unlist(listAUC, use.names=FALSE)
    vector_AUC


    This gave me a vector with all the AUCs for all patients. This vector can be added to my dataset if I want to.



    But now I have a problem: I have missings in my dataset. My dataset can be obtained using the following code:



    id <- c(1,2,3,4,5,6,7,8,9,10)
    measure1 <- c(60,NA,90,55,60,61,77,67,88,90)
    measure2 <- c(55,NA,NA,55,70,NA,80,66,65,92)
    measure3 <- c(62,88,85,NA,68,62,89,62,70,99)
    measure4 <- c(62,90,83,54,NA,62,NA,59,67,96)
    datmis <- data.frame(id, measure1, measure2, measure3, measure4)
    datmis


    I want to impute this dataset using MICE.



    library(mice)
    imp <- mice(datmis, maxit = 0)
    meth <- imp$method
    pred <- imp$predictorMatrix
    imp <- mice(datmis, method = meth, predictorMatrix = pred, seed = 2018, maxit = 10, m = 5)


    So now I have everything imputed. I want to create the AUCs for every individual, in every imputed dataset. Then I want to pool the results, resulting in one single AUC for every individual. However, using the formula create in the previous example does not work anymore. Is there someone who can help me out?










    share|improve this question

























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I have a question about calculating an AUC for every individual in a dataset, after imputation using MICE.



      I know how I can do it in a complete cases dataset. I have done it as follows:



      id <- c(1,2,3,4,5,6,7,8,9,10)
      measure_1 <- c(60,80,90,55,60,61,77,67,88,90)
      measure_2 <- c(55,88,88,55,70,61,80,66,65,92)
      measure_3 <- c(62,88,85,56,68,62,89,62,70,99)
      measure_4 <- c(62,90,83,54,65,62,91,59,67,96)
      dat <- data.frame(id, measure_1, measure_2, measure_3, measure_4)
      dat
      x <- c(0,7,14,21) # number of days

      library(Bolstad2)
      f <- function(a)
      Patient <- dat[a,]
      vector_patient <- c(Patient[2:5])
      AUCpatient <- sintegral(x,vector_patient)$int
      return(AUCpatient)


      vector <- c(1:10)
      listAUC <- lapply(vector, f)
      vector_AUC <- unlist(listAUC, use.names=FALSE)
      vector_AUC


      This gave me a vector with all the AUCs for all patients. This vector can be added to my dataset if I want to.



      But now I have a problem: I have missings in my dataset. My dataset can be obtained using the following code:



      id <- c(1,2,3,4,5,6,7,8,9,10)
      measure1 <- c(60,NA,90,55,60,61,77,67,88,90)
      measure2 <- c(55,NA,NA,55,70,NA,80,66,65,92)
      measure3 <- c(62,88,85,NA,68,62,89,62,70,99)
      measure4 <- c(62,90,83,54,NA,62,NA,59,67,96)
      datmis <- data.frame(id, measure1, measure2, measure3, measure4)
      datmis


      I want to impute this dataset using MICE.



      library(mice)
      imp <- mice(datmis, maxit = 0)
      meth <- imp$method
      pred <- imp$predictorMatrix
      imp <- mice(datmis, method = meth, predictorMatrix = pred, seed = 2018, maxit = 10, m = 5)


      So now I have everything imputed. I want to create the AUCs for every individual, in every imputed dataset. Then I want to pool the results, resulting in one single AUC for every individual. However, using the formula create in the previous example does not work anymore. Is there someone who can help me out?










      share|improve this question















      I have a question about calculating an AUC for every individual in a dataset, after imputation using MICE.



      I know how I can do it in a complete cases dataset. I have done it as follows:



      id <- c(1,2,3,4,5,6,7,8,9,10)
      measure_1 <- c(60,80,90,55,60,61,77,67,88,90)
      measure_2 <- c(55,88,88,55,70,61,80,66,65,92)
      measure_3 <- c(62,88,85,56,68,62,89,62,70,99)
      measure_4 <- c(62,90,83,54,65,62,91,59,67,96)
      dat <- data.frame(id, measure_1, measure_2, measure_3, measure_4)
      dat
      x <- c(0,7,14,21) # number of days

      library(Bolstad2)
      f <- function(a)
      Patient <- dat[a,]
      vector_patient <- c(Patient[2:5])
      AUCpatient <- sintegral(x,vector_patient)$int
      return(AUCpatient)


      vector <- c(1:10)
      listAUC <- lapply(vector, f)
      vector_AUC <- unlist(listAUC, use.names=FALSE)
      vector_AUC


      This gave me a vector with all the AUCs for all patients. This vector can be added to my dataset if I want to.



      But now I have a problem: I have missings in my dataset. My dataset can be obtained using the following code:



      id <- c(1,2,3,4,5,6,7,8,9,10)
      measure1 <- c(60,NA,90,55,60,61,77,67,88,90)
      measure2 <- c(55,NA,NA,55,70,NA,80,66,65,92)
      measure3 <- c(62,88,85,NA,68,62,89,62,70,99)
      measure4 <- c(62,90,83,54,NA,62,NA,59,67,96)
      datmis <- data.frame(id, measure1, measure2, measure3, measure4)
      datmis


      I want to impute this dataset using MICE.



      library(mice)
      imp <- mice(datmis, maxit = 0)
      meth <- imp$method
      pred <- imp$predictorMatrix
      imp <- mice(datmis, method = meth, predictorMatrix = pred, seed = 2018, maxit = 10, m = 5)


      So now I have everything imputed. I want to create the AUCs for every individual, in every imputed dataset. Then I want to pool the results, resulting in one single AUC for every individual. However, using the formula create in the previous example does not work anymore. Is there someone who can help me out?







      r auc






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 16:37









      quant

      1,58611526




      1,58611526










      asked Nov 9 at 10:09









      Anna_70

      112




      112






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Here's one way to do it. After you run your imputation you can



          1. Run through each imputed dataset

          2. Compute the AUC with the impuated data

          3. Pool estimates together using Rubin's rule

          The first 2 points are covered with the code below



          x <- c(0,7,14,21) # number of days
          library("tidyverse")
          library("MESS")
          res <- lapply(1:5, function(i)
          complete(imp, i) %>%
          group_by(id) %>%
          mutate(AUC=MESS::auc(x, c(measure1, measure2, measure3, measure4))))


          I'm using the auc function from the MESS since that is rather fast and flexible but you could replace it with your version.



          This produces a list of 5 data frames that can be used for pooling the estimates (part 3 from the list above).



          library("mitools")
          with(imputationList(res), lm(AUC ~ 1)) %>% pool() %>% summary()


          This produces



           estimate std.error statistic df p.value
          (Intercept) 1512.77 81.62359 18.53349 7.389246 1.829668e-07


          One more comment regarding the imputation: Are you sure you want to predict the measures using id as a numeric variable. That produces a regression-like predictor for the missing variables which seems rather unrealistic.






          share|improve this answer




















          • Thank you for your answer! First, you are right about the imputation. I was just creating a reproducible example and did not spend to much attention to the validity of the imputation, because it was not really the point in my question. Furthermore: the first part of your question really helps, it does create five dataframes, with individual AUC's. But in the pooling, you only generate one outcome. But I would like to have pooled AUC's for every individual seperately. You know how I can get to that?
            – Anna_70
            Nov 12 at 7:45











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53223698%2findividual-auc-after-multiple-imputation-using-mice%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          Here's one way to do it. After you run your imputation you can



          1. Run through each imputed dataset

          2. Compute the AUC with the impuated data

          3. Pool estimates together using Rubin's rule

          The first 2 points are covered with the code below



          x <- c(0,7,14,21) # number of days
          library("tidyverse")
          library("MESS")
          res <- lapply(1:5, function(i)
          complete(imp, i) %>%
          group_by(id) %>%
          mutate(AUC=MESS::auc(x, c(measure1, measure2, measure3, measure4))))


          I'm using the auc function from the MESS since that is rather fast and flexible but you could replace it with your version.



          This produces a list of 5 data frames that can be used for pooling the estimates (part 3 from the list above).



          library("mitools")
          with(imputationList(res), lm(AUC ~ 1)) %>% pool() %>% summary()


          This produces



           estimate std.error statistic df p.value
          (Intercept) 1512.77 81.62359 18.53349 7.389246 1.829668e-07


          One more comment regarding the imputation: Are you sure you want to predict the measures using id as a numeric variable. That produces a regression-like predictor for the missing variables which seems rather unrealistic.






          share|improve this answer




















          • Thank you for your answer! First, you are right about the imputation. I was just creating a reproducible example and did not spend to much attention to the validity of the imputation, because it was not really the point in my question. Furthermore: the first part of your question really helps, it does create five dataframes, with individual AUC's. But in the pooling, you only generate one outcome. But I would like to have pooled AUC's for every individual seperately. You know how I can get to that?
            – Anna_70
            Nov 12 at 7:45















          up vote
          0
          down vote













          Here's one way to do it. After you run your imputation you can



          1. Run through each imputed dataset

          2. Compute the AUC with the impuated data

          3. Pool estimates together using Rubin's rule

          The first 2 points are covered with the code below



          x <- c(0,7,14,21) # number of days
          library("tidyverse")
          library("MESS")
          res <- lapply(1:5, function(i)
          complete(imp, i) %>%
          group_by(id) %>%
          mutate(AUC=MESS::auc(x, c(measure1, measure2, measure3, measure4))))


          I'm using the auc function from the MESS since that is rather fast and flexible but you could replace it with your version.



          This produces a list of 5 data frames that can be used for pooling the estimates (part 3 from the list above).



          library("mitools")
          with(imputationList(res), lm(AUC ~ 1)) %>% pool() %>% summary()


          This produces



           estimate std.error statistic df p.value
          (Intercept) 1512.77 81.62359 18.53349 7.389246 1.829668e-07


          One more comment regarding the imputation: Are you sure you want to predict the measures using id as a numeric variable. That produces a regression-like predictor for the missing variables which seems rather unrealistic.






          share|improve this answer




















          • Thank you for your answer! First, you are right about the imputation. I was just creating a reproducible example and did not spend to much attention to the validity of the imputation, because it was not really the point in my question. Furthermore: the first part of your question really helps, it does create five dataframes, with individual AUC's. But in the pooling, you only generate one outcome. But I would like to have pooled AUC's for every individual seperately. You know how I can get to that?
            – Anna_70
            Nov 12 at 7:45













          up vote
          0
          down vote










          up vote
          0
          down vote









          Here's one way to do it. After you run your imputation you can



          1. Run through each imputed dataset

          2. Compute the AUC with the impuated data

          3. Pool estimates together using Rubin's rule

          The first 2 points are covered with the code below



          x <- c(0,7,14,21) # number of days
          library("tidyverse")
          library("MESS")
          res <- lapply(1:5, function(i)
          complete(imp, i) %>%
          group_by(id) %>%
          mutate(AUC=MESS::auc(x, c(measure1, measure2, measure3, measure4))))


          I'm using the auc function from the MESS since that is rather fast and flexible but you could replace it with your version.



          This produces a list of 5 data frames that can be used for pooling the estimates (part 3 from the list above).



          library("mitools")
          with(imputationList(res), lm(AUC ~ 1)) %>% pool() %>% summary()


          This produces



           estimate std.error statistic df p.value
          (Intercept) 1512.77 81.62359 18.53349 7.389246 1.829668e-07


          One more comment regarding the imputation: Are you sure you want to predict the measures using id as a numeric variable. That produces a regression-like predictor for the missing variables which seems rather unrealistic.






          share|improve this answer












          Here's one way to do it. After you run your imputation you can



          1. Run through each imputed dataset

          2. Compute the AUC with the impuated data

          3. Pool estimates together using Rubin's rule

          The first 2 points are covered with the code below



          x <- c(0,7,14,21) # number of days
          library("tidyverse")
          library("MESS")
          res <- lapply(1:5, function(i)
          complete(imp, i) %>%
          group_by(id) %>%
          mutate(AUC=MESS::auc(x, c(measure1, measure2, measure3, measure4))))


          I'm using the auc function from the MESS since that is rather fast and flexible but you could replace it with your version.



          This produces a list of 5 data frames that can be used for pooling the estimates (part 3 from the list above).



          library("mitools")
          with(imputationList(res), lm(AUC ~ 1)) %>% pool() %>% summary()


          This produces



           estimate std.error statistic df p.value
          (Intercept) 1512.77 81.62359 18.53349 7.389246 1.829668e-07


          One more comment regarding the imputation: Are you sure you want to predict the measures using id as a numeric variable. That produces a regression-like predictor for the missing variables which seems rather unrealistic.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 at 20:23









          ekstroem

          3,52021230




          3,52021230











          • Thank you for your answer! First, you are right about the imputation. I was just creating a reproducible example and did not spend to much attention to the validity of the imputation, because it was not really the point in my question. Furthermore: the first part of your question really helps, it does create five dataframes, with individual AUC's. But in the pooling, you only generate one outcome. But I would like to have pooled AUC's for every individual seperately. You know how I can get to that?
            – Anna_70
            Nov 12 at 7:45

















          • Thank you for your answer! First, you are right about the imputation. I was just creating a reproducible example and did not spend to much attention to the validity of the imputation, because it was not really the point in my question. Furthermore: the first part of your question really helps, it does create five dataframes, with individual AUC's. But in the pooling, you only generate one outcome. But I would like to have pooled AUC's for every individual seperately. You know how I can get to that?
            – Anna_70
            Nov 12 at 7:45
















          Thank you for your answer! First, you are right about the imputation. I was just creating a reproducible example and did not spend to much attention to the validity of the imputation, because it was not really the point in my question. Furthermore: the first part of your question really helps, it does create five dataframes, with individual AUC's. But in the pooling, you only generate one outcome. But I would like to have pooled AUC's for every individual seperately. You know how I can get to that?
          – Anna_70
          Nov 12 at 7:45





          Thank you for your answer! First, you are right about the imputation. I was just creating a reproducible example and did not spend to much attention to the validity of the imputation, because it was not really the point in my question. Furthermore: the first part of your question really helps, it does create five dataframes, with individual AUC's. But in the pooling, you only generate one outcome. But I would like to have pooled AUC's for every individual seperately. You know how I can get to that?
          – Anna_70
          Nov 12 at 7:45


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53223698%2findividual-auc-after-multiple-imputation-using-mice%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

          Crossroads (UK TV series)

          ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế