new_data.Rd
Create a data frame for the "newdata"-argument that contains
all combinations of values from the terms in questions. Similar to
expand.grid
. The terms
-argument accepts all shortcuts
for representative values as in ggpredict()
.
new_data(model, terms, typical = "mean", condition = NULL)
model | A fitted model object. |
---|---|
terms | Character vector with the names of those terms from
|
typical | Character vector, naming the function to be applied to the
covariates over which the effect is "averaged". The default is "mean".
See |
condition | Named character vector, which indicates covariates that
should be held constant at specific values. Unlike |
A data frame containing one row for each combination of values of the supplied variables.
data(efc) fit <- lm(barthtot ~ c12hour + neg_c_7 + c161sex + c172code, data = efc) new_data(fit, c("c12hour [meansd]", "c161sex"))#> c12hour c161sex neg_c_7 c172code #> 1 -8.3 1 11.83804 1.970552 #> 2 42.2 1 11.83804 1.970552 #> 3 92.7 1 11.83804 1.970552 #> 4 -8.3 2 11.83804 1.970552 #> 5 42.2 2 11.83804 1.970552 #> 6 92.7 2 11.83804 1.970552nd <- new_data(fit, c("c12hour [meansd]", "c161sex")) pr <- predict(fit, type = "response", newdata = nd) nd$predicted <- pr nd#> c12hour c161sex neg_c_7 c172code predicted #> 1 -8.3 1 11.83804 1.970552 76.75375 #> 2 42.2 1 11.83804 1.970552 63.96204 #> 3 92.7 1 11.83804 1.970552 51.17033 #> 4 -8.3 2 11.83804 1.970552 77.79518 #> 5 42.2 2 11.83804 1.970552 65.00347 #> 6 92.7 2 11.83804 1.970552 52.21175#> #> # Predicted values of Total score BARTHEL INDEX #> # x = average number of hours of care per week #> #> # c161sex = Male #> #> x | Predicted | SE | 95% CI #> ----------------------------------------- #> -8.30 | 76.75 | 1.90 | [73.02, 80.49] #> 42.20 | 63.96 | 1.73 | [60.57, 67.35] #> 92.70 | 51.17 | 1.97 | [47.31, 55.03] #> #> # c161sex = Female #> #> x | Predicted | SE | 95% CI #> ----------------------------------------- #> -8.30 | 77.80 | 1.32 | [75.21, 80.38] #> 42.20 | 65.00 | 0.97 | [63.11, 66.90] #> 92.70 | 52.21 | 1.29 | [49.69, 54.74] #> #> Adjusted for: #> * neg_c_7 = 11.84 #> * c172code = 1.97 #>