curvefit {REAT} | R Documentation |
Curve fitting
Description
Curve fitting (similar to SPSS and Excel)
Usage
curvefit(x, y, y.max = NULL, extrapol = NULL,
plot.curves = TRUE, pcol = "black", ptype = 19, psize = 1,
lin.col = "blue", pow.col = "green", exp.col = "orange", logi.col = "red",
plot.title = "Curve fitting", plot.legend = TRUE,
xlab = "x", ylab = "y", y.min = NULL, ..., print.results = TRUE)
Arguments
x |
a numeric vector containing the explanatory variable |
y |
a numeric vector containing the dependent variable |
y.max |
Optional: given maximum for the logistic regression function |
extrapol |
a single numeric value for how many x units the dependent variable y shall be extrapolated |
plot.curves |
Logical argument that indicates whether the curves shall be plotted or not |
pcol |
If |
ptype |
If |
psize |
If |
lin.col |
If |
pow.col |
If |
exp.col |
If |
logi.col |
If |
plot.title |
If |
plot.legend |
If |
xlab |
If |
ylab |
If |
y.min |
Optional: Y axis minimum |
... |
Optional: other plot parameters |
print.results |
Logical argument that indicates whether the model results are shown or not |
Details
Curve fitting for a given independent and dependent variable (y = f(x)
). Similar to curve fitting in SPSS or Excel. Fitting of nonlinear regression models (power, exponential, logistic) via intrinsically linear models (Rawlings et al. 1998).
Value
A data frame
containing the regression results (Parameters a and b, std. errors, t values, ...)
Author(s)
Thomas Wieland
References
Rawlings, J. O./Pantula, S. G./Dickey, D. A. (1998): “Applied Regression Analysis”. Springer. 2nd edition.
Examples
x <- 1:20
y <- 3-2*x
curvefit(x, y, plot.curves = TRUE)
# fit with plot
curvefit(x, y, extrapol=10, plot.curves = TRUE)
# fit and extrapolation with plot
x <- runif(20, min = 0, max = 100)
# some random data
# linear
y_resid <- runif(20, min = 0, max = 10)
# random residuals
y <- 3+(-0.112*x)+y_resid
curvefit(x, y)
# power
y_resid <- runif(20, min = 0.1, max = 0.2)
# random residuals
y <- 3*(x^-0.112)*y_resid
curvefit(x, y)
# exponential
y_resid <- runif(20, min = 0.1, max = 0.2)
# random residuals
y <- 3*exp(-0.112*x)*y_resid
curvefit(x, y)
# logistic
y_resid <- runif(20, min = 0.1, max = 0.2)
# random residuals
y <- 100/(1+exp(3+(-0.112*x)))*y_resid
curvefit(x, y)