specify()
is used to specify which columns in the supplied data frame are
the relevant response (and, if applicable, explanatory) variables. Note that
character variables are converted to factor
s.
Learn more in vignette("infer")
.
specify(x, formula, response = NULL, explanatory = NULL, success = NULL)
x | A data frame that can be coerced into a tibble. |
---|---|
formula | A formula with the response variable on the left and the
explanatory on the right. Alternatively, a |
response | The variable name in |
explanatory | The variable name in |
success | The level of |
A tibble containing the response (and explanatory, if specified) variable data.
# specifying for a point estimate on one variable gss %>% specify(response = age)#> Warning: Removed 12 rows containing missing values.#> Response: age (numeric) #> # A tibble: 2,988 x 1 #> age #> <dbl> #> 1 37 #> 2 29 #> 3 58 #> 4 40 #> 5 39 #> 6 37 #> 7 53 #> 8 41 #> 9 55 #> 10 47 #> # … with 2,978 more rows# specify a relationship between variables as a formula... gss %>% specify(age ~ partyid)#> Warning: Removed 37 rows containing missing values.#> Response: age (numeric) #> Explanatory: partyid (factor) #> # A tibble: 2,963 x 2 #> age partyid #> <dbl> <fct> #> 1 37 dem #> 2 29 dem #> 3 58 ind #> 4 40 rep #> 5 39 dem #> 6 37 dem #> 7 53 dem #> 8 41 rep #> 9 55 ind #> 10 47 rep #> # … with 2,953 more rows# ...or with named arguments! gss %>% specify(response = age, explanatory = partyid)#> Warning: Removed 37 rows containing missing values.#> Response: age (numeric) #> Explanatory: partyid (factor) #> # A tibble: 2,963 x 2 #> age partyid #> <dbl> <fct> #> 1 37 dem #> 2 29 dem #> 3 58 ind #> 4 40 rep #> 5 39 dem #> 6 37 dem #> 7 53 dem #> 8 41 rep #> 9 55 ind #> 10 47 rep #> # … with 2,953 more rows#> Warning: vignette ‘infer’ not found