fit2newdata | R Documentation |

Make a new data set for prediction

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

`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. |

```
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"))
## Not run:
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"))
## End(Not run)
require(moonBook)
fit=lm(log(NTAV)~I(age^2)*sex,data=radial)
fit2newdata(fit,predictors=c("I(age^2)","sex"))
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.