linReg | R Documentation |
uses lm
; plots data if add=FALSE, draws the regression line
with abline
and writes the formula with legend
linReg(
x,
y = NULL,
data = NULL,
add = FALSE,
digits = 2,
quiet = FALSE,
pch = 16,
col = "black",
colline = "red",
colband = addAlpha(colline),
level = 0.95,
plotrange = par("usr")[1:2],
lwd = 1,
xlab = deparse(substitute(x)),
ylab = deparse(substitute(y)),
main = "linear regression",
pos1 = "top",
pos2 = NULL,
inset = 0,
legargs = NULL,
...
)
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 |
add |
Logical. If TRUE, line and text are added to the existing graphic. DEFAULT: FALSE (plots datapoints first and then the line.) |
digits |
Numeric vector of length |
quiet |
Silence NA-removal warnings in |
pch |
Point Character of datapoints, see |
col |
Color of points. DEFAULT: "black" |
colline |
Color of the regression line, see |
colband |
Color of the confidence region band. DEFAULT: addAlpha(col) |
level |
Confidence level, see |
plotrange |
x range for which regression line and uncertainty band should
be plotted. Is passed to |
lwd |
Numeric. Linewidth, see |
xlab |
Axis label if add=FALSE. DEFAULT: deparse(substitute(x)) |
ylab |
Axis label if add=FALSE. DEFAULT: deparse(substitute(y)) |
main |
Title if add=FALSE. Changed (if not specified) for x=formula with data. DEFAULT: "linear regression" |
pos1 |
|
pos2 |
For numerical coordinates, this is the y-position. DEFAULT: NULL, as in |
inset |
Numeric vector of length |
legargs |
list of arguments passed to legend, like list(cex=0.8, xpd=TRUE, bg="white"), ... xpd specifies 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: NULL |
... |
Further arguments passed to |
None, used for plotting and drawing.
Berry Boessenkool, berry-b@gmx.de, 2011-2012, 2015
lm
, mReg
, expReg
, legend
, par
, abline
.
a <- 1:30
b <- a/2.345+rnorm(30,0,3)
linReg(a,b)
linReg(a,b, ylab="Hallo", pch=1, colline=3, main="Regression by Berry")
linReg(a, b, pos1=15, pos2=0) # position of topleft corner of legend
linReg(a, b, pos1=NA) # to suppress legend
linReg(a, b, plotrange=5:20) # only for plotting, all data points are used!
linReg(a,b, digits=c(2,3,2,-1) ) # Do not write RMSE into legend
# Formula specification:
linReg(b~a)
linReg(Fertility~Education, data=swiss, col="blue", colline="green")
# col is for points, colline + colband for regression line + conf.int.
# For more flexibility with the datapoints, plot first, then use linReg with add=TRUE:
plot(a,b, xlim=c(-5,45))
linReg(a, b, pos1="bottomright", add=TRUE, inset=.1) # inset: distance from plot border
linReg(a, b, digits=c(7,4,3), add=TRUE, colline=3, lty=2, lwd=4, level=0.8)
linReg(a, b, pos1="topleft", inset=c(-0.1, 0.3), legargs=list(xpd=TRUE), add=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.