Description Usage Arguments Note Examples
This function takes a dataframe and formula, calculates a linear regression, then predicts new Y values from the linear regression. It returns those Y values as a vector. You can provide a "new x" value directly in "newX", or tell the function where a column is that contains your predictive value(s) in "newCol."
1 | predictYfromLin(x, formula, newX = NULL, newCol = "minAge")
|
x |
The dataframe to use for prediction. |
formula |
The formula for the linear regression, in the format "y ~ x" |
newX |
Optional. The value you want to predict, given X. If left blank,
it assumes that there is a column in the dataframe called "minAge" that is
populated with the values you want to predict for. It takes the unique() of
x$minAge and uses that as the newX. This ensures that if you're wrapping in
|
newCol |
What you want your new column to be named. |
This function does not police your use. If you predict from an X that is outside of your range of original x's, that is on you.
1 2 | data <- data.frame(x=runif(30, min=0, max=25), y=runif(30, min=0, max=100), newVal=30)
predictYfromLin(data, "y~x", newCol="newVal")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.