make_possible_data: Make data for multi-step strategy

Description Usage Arguments Value Examples

View source: R/make_possible_data.R

Description

Creates a database of possible data from a data strategy. Users can gather additional data on variables specified via vars for any possible cases in the model ("any"). Or they can gather data in all cases within a given dataset ("within"). Or they can specify the subset of cases for which within-case data should be collected (e.g. "Y == 1").

Usage

1
2
make_possible_data(model, given = NULL, N = list(1), within = FALSE,
  condition = list(TRUE), vars = list(NULL))

Arguments

model

A causal model object generated by make_model.

given

A data.frame with observations.

N

An integer. Number of variables to seek.

within

Logical. Whether to seek variables within existing data.

condition

A list of character strings indicating for which cases data should be gathered. Options are: (i) to gather additional data on variables specified via vars for any possible cases in the model ("any"), (ii) to gather data in all cases within a given dataset ("within"), or (iii) to specify the subset of cases for which within-case data should be collected (e.g. "Y == 1").

vars

A character vector. Variables to be sought or NA. If NA make_possible_data gathers data on all variables containing NA for the specified data strategy.

Value

A dataset

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
library(dplyr)
model <- make_model("X->M->Y")  %>%
   set_restrictions(causal_type_restrict = "Y[M=1]<Y[M=0] | M[X=1]<M[X=0] ") %>%
   set_parameter_matrix()
df <- data.frame(X = c(0,0,0,1,1,1), M = NA, Y = c(0,0,1,0,1,1))
given <- summarize_data(model, df)[, -2]

# Look for data on M for all possible cases in the given data
make_possible_data(model, N = 2)
make_possible_data(model, given, vars = list("M"), within = TRUE, N = 2)

# Not possible:
make_possible_data(model, given, vars = "M", within = TRUE, N = 7)

# Within conditions
make_possible_data(model, given, within = TRUE, N = 2, condition = "X==1 & Y==1", vars = "M")
make_possible_data(model, given, within = TRUE, N = 3, condition = "Y==1", vars = "M")
make_possible_data(model, given, within = TRUE, condition = "X == 1 | Y == 1", vars = "M")

# Look for data on K but not M
model <- make_model("X->M->Y <-K")   %>%
   set_parameter_matrix()
df <- data.frame(X = c(0,0,1,1,1), K = NA, M = NA, Y = c(0,0,0,1,1))
given <- summarize_data(model, df)[, -2]
make_possible_data(model, given, within = TRUE, N = 1, vars = "K")

# Look for data on M when X = 1 and Y = 0
make_possible_data(model,
                   given,
                   condition =  "X == 1 & Y == 0",
                   vars ="M")

model <- make_model("X->M->Y")   %>%
   set_parameter_matrix()
make_possible_data(model,
                   given = NULL,
                   N = list(3,1),
                   within = FALSE,
                   condition =  list(TRUE, "X == 1 & Y == 0"),
                   vars = list(c("X", "Y"), "M"))

lilymedina/gbiqqtools documentation built on Nov. 4, 2019, 4:32 p.m.