Learn R Programming

REAT (version 3.0.2)

curvefit: 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 plot.curves = TRUE: Point color

ptype

If plot.curves = TRUE: Point type (pch)

psize

If plot.curves = TRUE: Point size

lin.col

If plot.curves = TRUE: Color of linear regression line

pow.col

If plot.curves = TRUE: Color of power function regression line

exp.col

If plot.curves = TRUE: Color of exponential function regression line

logi.col

If plot.curves = TRUE: Color of logistic function regression line

plot.title

If plot.curves = TRUE: Plot title

plot.legend

If plot.curves = TRUE: Logical argument that indicates whether a legend is added to the plot or not

xlab

If plot.curves = TRUE: X axis label

ylab

If plot.curves = TRUE: Y axis label

y.min

Optional: Y axis minimum

Optional: other plot parameters

print.results

Logical argument that indicates whether the model results are shown or not

Value

A data frame containing the regression results (Parameters a and b, std. errors, t values, ...)

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

References

Rawlings, J. O./Pantula, S. G./Dickey, D. A. (1998): “Applied Regression Analysis”. Springer. 2nd edition.

Examples

Run this code
# NOT RUN {
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)
# }

Run the code above in your browser using DataLab