curve_fitter: Fitting any curve you like, really.

Description Usage Arguments Value Examples

Description

Fitting any curve you like, really.

Usage

1
curve_fitter(dataFrame = "dataframe", expr = "", columns = "c(x, y)")

Arguments

dataFrame

A dataframe

columns

Column with variable to be sorted

Value

A least squares solution for the given curve

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
coef <- curve_fitter(mtcars, "x", columns=c(4, 6))
plot(mtcars[[4]], mtcars[[6]])
curve(coef[1] + coef[2]*x, add = TRUE)

coef <- curve_fitter(mtcars, "x, x^2", columns=c(1, 3))
plot(mtcars[[1]], mtcars[[3]])
curve(coef[1] + coef[2]*x + coef[3]*x^2, add = TRUE)

# Everything below should run together.
x <- -10:10
y <- jitter(-(-10:10)*10 + (-10:10)^2 + (-10:10)^3, 500)
xy <- data.frame("x" = x, "y" = y)

plot(x, y)
coeff <- curve_fitter(dataFrame = xy, "x, x^2, x^3", c(1, 2))
# coeff[[1]] is the constant value. Everything else corresponds to the order in which it was inputted.
curve(coeff[[1]] + coeff[[2]]*x + coeff[[3]]*x^2 + coeff[[4]]*x^3, add = TRUE)

fdrennan/fdRenn documentation built on May 16, 2019, 12:12 p.m.