curvefit: Curve fitting

Description Usage Arguments Details Value Author(s) References Examples

Description

Curve fitting (similar to SPSS and Excel)

Usage

1
2
3
4
5
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

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)

Example output

Curve fitting 

             a  b Std. Error a Std. Error b    t value a     t value b
Linear       3 -2 2.289454e-15 1.911199e-16 1.310356e+15 -1.046463e+16
Power       NA NA           NA           NA           NA            NA
Exponential NA NA           NA           NA           NA            NA
Logistic    NA NA           NA           NA           NA            NA
              Pr(>|t|) a   Pr(>|t|) b R squared Adj. R squared      F value
Linear      2.83609e-262 1.62441e-278         1              1 1.095085e+32
Power                 NA           NA        NA             NA           NA
Exponential           NA           NA        NA             NA           NA
Logistic              NA           NA        NA             NA           NA
                  Pr(>F)
Linear      1.62441e-278
Power                 NA
Exponential           NA
Logistic              NA
Warning message:
In summary.lm(modlin) : essentially perfect fit: summary may be unreliable
Curve fitting 

             a  b Std. Error a Std. Error b    t value a     t value b
Linear       3 -2 2.289454e-15 1.911199e-16 1.310356e+15 -1.046463e+16
Power       NA NA           NA           NA           NA            NA
Exponential NA NA           NA           NA           NA            NA
Logistic    NA NA           NA           NA           NA            NA
              Pr(>|t|) a   Pr(>|t|) b R squared Adj. R squared      F value
Linear      2.83609e-262 1.62441e-278         1              1 1.095085e+32
Power                 NA           NA        NA             NA           NA
Exponential           NA           NA        NA             NA           NA
Logistic              NA           NA        NA             NA           NA
                  Pr(>F)
Linear      1.62441e-278
Power                 NA
Exponential           NA
Logistic              NA
Warning message:
In summary.lm(modlin) : essentially perfect fit: summary may be unreliable
Curve fitting 

                   a          b Std. Error a Std. Error b t value a t value b
Linear      9.509779 -0.1309513     1.591616   0.02589046   5.97492 -5.057899
Power             NA         NA           NA           NA        NA        NA
Exponential       NA         NA           NA           NA        NA        NA
Logistic          NA         NA           NA           NA        NA        NA
              Pr(>|t|) a  Pr(>|t|) b R squared Adj. R squared  F value
Linear      1.186446e-05 8.19206e-05 0.5869887      0.5640436 25.58234
Power                 NA          NA        NA             NA       NA
Exponential           NA          NA        NA             NA       NA
Logistic              NA          NA        NA             NA       NA
                 Pr(>F)
Linear      8.19206e-05
Power                NA
Exponential          NA
Logistic             NA
Curve fitting 

                     a             b Std. Error a Std. Error b  t value a
Linear       0.3576842 -0.0009183456    0.0286013 0.0004652508  12.505872
Power        0.5713157 -0.1659966580    0.1343102 0.0793191856  -1.810166
Exponential  0.3515556 -0.0028305433    0.0997319 0.0016223161 -10.481977
Logistic    -2.8680982  0.0250978809    0.6874205 0.0111821125  -4.172262
            t value b   Pr(>|t|) a Pr(>|t|) b R squared Adj. R squared  F value
Linear      -1.973872 2.588618e-10 0.06394683 0.1779384     0.13226836 3.896171
Power       -2.092768 8.699750e-02 0.05080466 0.1956989     0.15101549 4.379678
Exponential -1.744754 4.307278e-09 0.09807728 0.1446561     0.09713703 3.044168
Logistic     2.244467 5.724344e-04 0.03761070 0.2186697     0.17526244 5.037631
                Pr(>F)
Linear      0.06394683
Power       0.05080466
Exponential 0.09807728
Logistic    0.03761070
Curve fitting 

                        a           b Std. Error a Std. Error b t value a
Linear       3.345317e-02 -0.00041549  0.005772462 9.389933e-05  5.795304
Power        1.674240e+06 -5.51931314  0.488827015 2.886852e-01 12.732147
Exponential  4.327088e-01 -0.11193633  0.095298642 1.550201e-03 -8.790160
Logistic    -4.705883e+00  0.14427698  0.766397259 1.246681e-02 -6.140266
             t value b   Pr(>|t|) a   Pr(>|t|) b R squared Adj. R squared
Linear       -4.424845 1.718516e-05 3.269983e-04 0.5210123      0.4944019
Power       -19.118798 1.933847e-10 2.093747e-13 0.9530674      0.9504600
Exponential -72.207611 6.248707e-08 1.254402e-23 0.9965596      0.9963685
Logistic     11.572887 8.466784e-06 9.023981e-10 0.8815257      0.8749438
               F value       Pr(>F)
Linear        19.57925 3.269983e-04
Power        365.52843 2.093747e-13
Exponential 5213.93913 1.254402e-23
Logistic     133.93172 9.023981e-10
Curve fitting 

                    a           b Std. Error a Std. Error b t value a t value b
Linear      4.2961034  0.14068942    1.5136474  0.024622157  2.838246  5.713935
Power       0.5595153  0.76652654    0.1939492  0.114540048 -1.300278  6.692214
Exponential 5.0742138  0.01375305    0.1682757  0.002737303  9.651846  5.024305
Logistic    1.8799623 -0.04857271    0.6430932  0.010461050  2.923312 -4.643197
              Pr(>|t|) a   Pr(>|t|) b R squared Adj. R squared  F value
Linear      1.090392e-02 2.035297e-05 0.6446133      0.6248696 32.64906
Power       2.099091e-01 2.818216e-06 0.7133107      0.6973835 44.78573
Exponential 1.536412e-08 8.808646e-05 0.5837539      0.5606291 25.24364
Logistic    9.076301e-03 2.021262e-04 0.5449866      0.5197081 21.55928
                  Pr(>F)
Linear      2.035297e-05
Power       2.818216e-06
Exponential 8.808646e-05
Logistic    2.021262e-04

REAT documentation built on Sept. 5, 2021, 5:18 p.m.