upSample2: Restore model of down-sampled to original dimension.

Description Usage Arguments Examples

Description

Restore model of down-sampled to original dimension.

Usage

1
upSample2(orig.data, model, up_sample = TRUE)

Arguments

orig.data

a data.frame containing the original data (not downsampled) with the batch labels stored with colname batch_orig and the median-summarized data stored in column medians

model

model fit to the down-sampled data

up_sample

logical. If TRUE, model is restored to the original dimension.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 library(tidyverse)
 library(dplyr)
 set.seed(123)
 k <- 3
 nbatch <- 3
 means <- matrix(c(-1.2, -1, -0.8, -0.2, 0, 0.2, 0.8, 1, 1.2),
     nbatch, k, byrow = FALSE)
 sds <- matrix(0.1, nbatch, k)
 N <- 1500
 truth <- simulateBatchData(N = N,
                            batch = rep(letters[1:3],
                                        length.out = N),
                            theta = means,
                            sds = sds,
                            p = c(1/5, 1/3, 1 - 1/3 - 1/5))

 ##
 ## Make a tibble:  required plate, plate.index, batch_orig
 ##
 full.data <- tibble(medians=y(truth),
                     plate=batch(truth),
                     batch_orig=as.character(batch(truth))) %>%
   mutate(plate.index=as.integer(factor(plate, levels=unique(plate))))


 ## Below, we down-sample to 500 observations
 ## Required:  batch_orig, batch_index
 partial.data <- downSample(full.data, size=500)

 ##
 ## Required:  a mapping from plate to batch
 ##
 select <- dplyr::select
 summarize <- dplyr::summarize
 plate.mapping <- partial.data %>%
   select(c(plate, batch_index)) %>%
   group_by(plate) %>%
   summarize(batch_index=unique(batch_index))

 ## Fit a model as per usual to the down-sampled data
 mp <- McmcParams(iter=200, burnin=10)
 hp <- HyperparametersMultiBatch(k=3)
 model <- MultiBatchModel2(dat=partial.data$medians,
                           batches=partial.data$batch_index,
                           mp=mp,
                           hp=hp)
 model <- posteriorSimulation(model)
 ##
 ## Add the batching used for the down-sampled data to the full data
 ##
 full.data2 <- left_join(full.data, plate.mapping, by="plate")
 ##
 ## Estimate probabilities for each individual in the full data
 ##
 model.full <- upSample2(full.data2, model)

CNPBayes documentation built on May 6, 2019, 4:06 a.m.