spicer_nbrs: Neighbor's spices

Description Usage Arguments Value Examples

View source: R/spice.R

Description

If you use Rstudio, the masher and spicer functions can help remind you which parameters go along with which ipa_brew flavor. The basic idea is to write spice(brew, with = spicer_<flavor>()) and mash(brew, with = masher_<flavor>()). Hitting the tab key with your curser inside the parentheses of masher_flavor()will create a drop-down menu that shows a list of the arguments that go along with your brew's flavor.

If you have no trouble remembering the parameters that go along with your brew's flavor, or if you just want your code to be more concise, you don't have to use the with argument. Instead, you can just specify parameter values directly using the ... argument in the mash and spice functions. In the examples below, both approaches are shown.

Usage

1
spicer_nbrs(k_neighbors = seq(10), aggregate = TRUE)

Arguments

k_neighbors

a numeric vector indicating how many neighbors should be used to impute missing values.

aggregate

a logical value. If TRUE, then neighbors will be aggregated to generate imputations. If FALSE, then one neighbor will be sampled at random to generate a missing value. Using aggregate = FALSE can be helpful if you are conducting multiple imputation.

Value

a list with input values that can be passed directly into spice, e.g spice(brew, with = spicer_nbrs()) for a neighbors brew or spice(brew, with = spicer_soft()) for a soft brew.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
data <- data.frame(
  x1 = 1:10,
  x2 = 10:1,
  x3 = rnorm(10),
  outcome = 11 + runif(10)
)

data[1:2, 1:2] = NA

knn_brew <- brew(data, outcome = outcome, flavor = 'kneighbors')
sft_brew <- brew(data, outcome = outcome, flavor = 'softImpute')

# these two calls are equivalent
spicy_knn <- spice(knn_brew, with = spicer_nbrs(k_neighbors = c(3, 5)))
spicy_knn <- spice(knn_brew, k_neighbors = c(3, 5))

# these two calls are equivalent
spicy_sft <- spice(sft_brew, with = spicer_soft(grid = TRUE))
spicy_sft <- spice(sft_brew, grid = TRUE)

bcjaeger/ipa documentation built on May 7, 2020, 9:45 a.m.