bestfit | R Documentation |
Find best transformations of the parameters for Linear Regression.
bestfit(formula, data, subset, transf = c("rsqrt", "log", "sqrt"))
formula |
A standard linear regression formula, with no transformation in the parameters. |
data |
A data frame containing the variables in the model. |
subset |
a specification of the rows to be used: defaults to all rows.
This can be any valid indexing vector (see [.data.frame) for the
rows of data or if that is not supplied, a data frame made up of the
variables used in |
transf |
A family of functions to be used to transform the variables in the data frame, in order to find the best combination of transformation to be applied to the data - usually functions of the box-cox family. |
library(sf)
data(centro_2015)
dados <- st_drop_geometry(centro_2015)
best_fit <- bestfit(valor ~ ., data = dados)
print(best_fit, n = 20)
s <- summary(best_fit)
#There still may be outliers:
out <- car::outlierTest(s$fit) #31
outliers <- 31
# There are two ways to handle with them:
# Recalling bestfit with a subset argument ...
best_fit2 <- bestfit(valor ~ ., data = dados, subset = -outliers)
# Or assigning a subset argument directly into summary.bestfit
s <- summary(best_fit, fit = 1, subset = -outliers)
# The latter takes less computational effort, since it only updates the
# lm call of the chosen fit. The former is more precise, since it runs
# bestfit again without the outliers.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.