Find best transformations of the parameters for Linear Regression.

bestfit(formula, data, subset, transf = c("rsqrt", "log", "sqrt"))

Arguments

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

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.

Examples

dados <- st_drop_geometry(centro_2015)
#> Error in st_drop_geometry(centro_2015): could not find function "st_drop_geometry"
best_fit <- bestfit(valor ~ ., data = dados)
#> Error in as.data.frame(data): object 'dados' not found
print(best_fit, n = 20)
#> Error in print(best_fit, n = 20): object 'best_fit' not found
s <- summary(best_fit)
#> Error in summary(best_fit): object 'best_fit' not found
#There still may be outliers: out <- car::outlierTest(s$fit)
#> Error in car::outlierTest(s$fit): object 's' not found
outliers <- match(names(out$p), rownames(dados))
#> Error in match(names(out$p), rownames(dados)): object 'out' not found
# There are two ways to handle with them: # Recalling bestfit with a subset argument ... best_fit <- bestfit(valor ~ ., data = dados, subset = -outliers)
#> Error in as.data.frame(data): object 'dados' not found
# Or assigning a subset argument directly into summary.bestfit s <- summary(best_fit, fit = 1, subset = -outliers)
#> Error in summary(best_fit, fit = 1, subset = -outliers): object 'best_fit' not found
# 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.