expReg: Exponential regression with plotting

View source: R/expReg.R

expRegR Documentation

Exponential regression with plotting

Description

uses lm; plots data if add=FALSE, draws the regression line with abline and confidence interval with polygon and writes the formula with legend

Usage

expReg(
  x,
  y = NULL,
  data = NULL,
  logy = TRUE,
  predictnew = NULL,
  interval = "confidence",
  plot = TRUE,
  digits = 2,
  inset = 0,
  xpd = par("xpd"),
  pos1 = "top",
  pos2 = NULL,
  add = FALSE,
  pch = 16,
  col = rgb(0, 0, 0, 0.5),
  modcol = 2,
  lwd = 1,
  xlab = deparse(substitute(x)),
  ylab = deparse(substitute(y)),
  main = "exponential regression",
  xlim = range(x),
  ylim = range(y),
  ...
)

Arguments

x

Numeric or formula (see examples). Vector with values of explanatory variable

y

Numeric. Vector with values of dependent variable. DEFAULT: NULL

data

Dataframe. If x is a formula, the according columns from data are used as x and y. DEFAULT: NULL

logy

Plot with a logarithmic y axis? Calls logAxis. DEFAULT: TRUE

predictnew

Vector with values to predict outcome for. Passed as newdata to predict.lm. DEFAULT: NULL

interval

Interval for prediction. DEFAULT: "confidence"

plot

Plot things at all? If FALSE, predictnew will still be returned. DEFAULT: TRUE

digits

Numeric vector of length \ge 1. Specifies number of digits a,b,r,e are rounded to in the formula "y=a*log(x)+b, R^2, RMSE=e", respectively. If values are not specified, they are set equal to the first. DEFAULT: 2

inset

Numeric vector of length \le 2. inset distance(s) from the margins as a fraction of the plot region when formula is placed by keyword. DEFAULT: 0

xpd

Logical, specifying whether formula can be written only inside the plot region (when FALSE) or inside the figure region including mar (when TRUE) or in the entire device region including oma (when NA). DEFAULT: par("xpd")

pos1

xy.coords-acceptable position of the formula. DEFAULT: "top"

pos2

For numerical coordinates, this is the y-position. DEFAULT: NULL, as in legend

add

Logical. If TRUE, line and text are added to the existing graphic. DEFAULT: FALSE (plots datapoints first and then the line.)

pch

Point Character, see par. DEFAULT: 16

col

Color of points, see par. DEFAULT: rgb(0,0,0, 0.5)

modcol

color of model line. DEFAULT: 2

lwd

Numeric. Linewidth, see par. DEFAULT: 1

xlab, ylab, main

Character / Expression. axis label and graph title if add=FALSE. DEFAULT: internal from names

xlim, ylim

graphic range. DEFAULT: range(x)

...

Further arguments passed to plot and abline.

Value

predict.lm result.

Author(s)

Berry Boessenkool, berry-b@gmx.de, Dec. 2014

See Also

lm, mReg, linReg.

Examples


x <- runif(100, 1, 10)
y <- 10^(0.3*x+rnorm(100, sd=0.3)+4)
plot(x,y)
expReg(x,y)
expReg(x,y, logy=FALSE)
expReg(x,y, predictnew=6, plot=FALSE)
expReg(x,y, predictnew=3:6, interval="none", plot=FALSE)


berryFunctions documentation built on May 29, 2024, 4:01 a.m.