fit2newdata: Make a new data set for prediction

Description Usage Arguments Examples

View source: R/ggPredict.R

Description

Make a new data set for prediction

Usage

1
2
3
fit2newdata(fit, predictors, mode = 1, pred.values = NULL,
  modx.values = NULL, mod2.values = NULL, colorn = 3, maxylev = 6,
  summarymode = 1)

Arguments

fit

An object of class "lm", "glm" or "loess"

predictors

Names of predictor variables in string

mode

A numeric. Useful when the variables are numeric. If 1, c(-1,0,1)*sd + mean is used. If 2, the 16th, 50th, 84th percentile values used. If 3 sequence over a the range of a vector used

pred.values

For which values of the predictors should be used? Default is NULL. If NULL, 20 seq_range is used.

modx.values

For which values of the moderator should lines be plotted? Default is NULL. If NULL, then the customary +/- 1 standard deviation from the mean as well as the mean itself are used for continuous moderators. If the moderator is a factor variable and modx.values is NULL, each level of the factor is included.

mod2.values

For which values of the second moderator should lines be plotted? Default is NULL. If NULL, then the customary +/- 1 standard deviation from the mean as well as the mean itself are used for continuous moderators. If the moderator is a factor variable and modx.values is NULL, each level of the factor is included.

colorn

The number of regression lines when the modifier variable(s) are numeric.

maxylev

An integer indicating the maximum number of levels of numeric variable be treated as a categorical variable

summarymode

An integer indicating method of extracting typical value of variables. If 1, typical() is used.If 2, mean() is used.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
fit=lm(mpg~hp*wt*cyl+carb+am,data=mtcars)
fit2newdata(fit,predictors=c("hp","wt","am"))
fit2newdata(fit,predictors=c("hp","wt","cyl"))
fit2newdata(fit,predictors=c("hp"))
fit2newdata(fit,predictors=c("hp","wt"))
fit=loess(mpg~hp*wt*am,data=mtcars)
fit2newdata(fit,predictors=c("hp"))

mtcars$engine=ifelse(mtcars$vs==0,"V-shaped","straight")
fit=lm(mpg~wt*engine,data=mtcars)
fit2newdata(fit,predictors=c("wt","engine"))
fit=lm(mpg~wt*factor(vs),data=mtcars)
fit2newdata(fit,predictors=c("wt","vs"))
fit2newdata(lm(mpg~hp*wt,data=mtcars),predictors=c("hp","wt"),mode=3,colorn=30)
fit=lm(mpg~hp*log(wt),data=mtcars)
fit2newdata(fit,predictors=c("hp","log(wt)"))
fit=lm(mpg~hp*wt*factor(vs),data=mtcars)
fit2newdata(fit,predictors=c("hp"))
require(moonBook)
fit=lm(log(NTAV)~I(age^2)*sex,data=radial)
fit2newdata(fit,predictors=c("I(age^2)","sex"))

predict3d documentation built on Sept. 3, 2019, 5:06 p.m.