compare.lm {jgsbook} | R Documentation |
Compare Linear Models
Description
This function fits and compares several models (linear, quadratic, cubic, exponential, logarithmic, sigmoidal, power, logistic) to a given set of dependent and independent variables. It returns either a summary of the models with their R-squared values or predicted values based on the models.
Usage
compare.lm(dep, ind, predict = FALSE, steps = 0.01)
Arguments
dep |
A numeric vector representing the dependent variable. |
ind |
A numeric vector representing the independent variable. |
predict |
Logical. If TRUE, the function returns predicted values for each model. Defaults to FALSE. |
steps |
Numeric. The step size for generating x-values for predictions. Only used if predict is TRUE. Defaults to 0.01. |
Value
A data frame. If predict is FALSE, returns a data frame with the R-squared values for each model. If predict is TRUE, returns a data frame with the original data and predicted values for each model.
Examples
x <- c(6, 9, 12, 14, 30, 35, 40, 47, 51, 55, 60)
y <- c(14, 28, 50, 70, 89, 94, 90, 75, 59, 44, 27)
compare.lm(y, x)
compare.lm(y, x, predict=TRUE)