Basic Trend Line
Basic Trend Line
Basic Trend Line
R topics documented:
SSexp2P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
SSexp3P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1
2 SSexp2P
SSpower2P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
SSpower3P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
trendline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
trendline_summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Index 12
Description
This selfStart model evaluates the power regression function (formula as: y=a*exp(b*x)). It has an
initial attribute that will evaluate initial estimates of the parameters ’a’ and ’b’ for a given set of
data.
Usage
SSexp2P(predictor, a, b)
Arguments
predictor a numeric vector of values at which to evaluate the model.
a, b The numeric parameters responsing to the exp2P model.
Author(s)
Weiping Mei <meiweipingg@163.com>
See Also
trendline, SSexp3P, SSpower3P, nls, selfStart
Examples
library(basicTrendline)
x<-1:5
y<-c(2,4,8,20,25)
xy<-data.frame(x,y)
getInitial(y ~ SSexp2P(x,a,b), data = xy)
## Initial values are in fact the converged values
Description
This selfStart model evaluates the exponential regression function (formula as: y=a*exp(b*x)+c).
It has an initial attribute that will evaluate initial estimates of the parameters a, b, and c for a given
set of data.
Usage
SSexp3P(predictor, a, b, c)
Arguments
Author(s)
See Also
Examples
library(basicTrendline)
x<-1:5
y<-c(2,4,8,16,28)
xy<-data.frame(x,y)
getInitial(y ~ SSexp3P(x,a,b,c), data = xy)
## Initial values are in fact the converged values
Description
This selfStart model evaluates the power regression function (formula as: y=a*x^b). It has an initial
attribute that will evaluate initial estimates of the parameters ’a’ and ’b’ for a given set of data.
Usage
SSpower2P(predictor, a, b)
Arguments
Author(s)
See Also
Examples
library(basicTrendline)
x<-1:5
y<-c(2,4,8,20,25)
xy<-data.frame(x,y)
getInitial(y ~ SSpower2P(x,a,b), data = xy)
## Initial values are in fact the converged values
Description
This selfStart model evaluates the power regression function (formula as: y=a*x^b+c). It has an
initial attribute that will evaluate initial estimates of the parameters a, b, and c for a given set of
data.
Usage
SSpower3P(predictor, a, b, c)
Arguments
Author(s)
See Also
Examples
library(basicTrendline)
x<-1:5
y<-c(2,4,8,20,25)
xy<-data.frame(x,y)
getInitial(y ~ SSpower3P(x,a,b,c), data = xy)
## Initial values are in fact the converged values
Description
Plot, draw regression line and confidence interval, and show regression equation, R-square and P-
value, as simple as possible, by using different models built in the ’trendline()’ function. The func-
tion includes the following models in the latest version: "line2P" (formula as: y=a*x+b), "line3P"
(y=a*x^2+b*x+c), "log2P" (y=a*ln(x)+b), "exp2P" (y=a*exp(b*x)),"exp3P" (y=a*exp(b*x)+c), "power2P"
(y=a*x^b), and "power3P" (y=a*x^b+c). Besides, the summarized result of each fitted model is also
output by default.
Usage
trendline(
x,
y,
model = "line2P",
Pvalue.corrected = TRUE,
linecolor = "blue",
lty = 1,
lwd = 1,
show.equation = TRUE,
show.Rsquare = TRUE,
show.pvalue = TRUE,
Rname = 1,
Pname = 0,
xname = "x",
yname = "y",
yhat = FALSE,
summary = TRUE,
ePos.x = NULL,
ePos.y = NULL,
text.col = "black",
eDigit = 5,
eSize = 1,
CI.fill = TRUE,
CI.level = 0.95,
CI.color = "grey90",
CI.alpha = 1,
CI.lty = 1,
CI.lwd = 1,
las = 1,
xlab = NULL,
ylab = NULL,
...
)
trendline 7
Arguments
x, y the x and y arguments provide the x and y coordinates for the plot. Any reason-
able way of defining the coordinates is acceptable.
model select which model to fit. Default is "line2P". The "model" should be one of
c("line2P", "line3P", "log2P", "exp2P", "exp3P", "power2P", "power3P"), their
formulas are as follows:
"line2P": y=a*x+b
"line3P": y=a*x^2+b*x+c
"log2P": y=a*ln(x)+b
"exp2P": y=a*exp(b*x)
"exp3P": y=a*exp(b*x)+c
"power2P": y=a*x^b
"power3P": y=a*x^b+c
Pvalue.corrected
if P-value corrected or not, the value is one of c("TRUE", "FALSE").
linecolor color of regression line.
lty line type. lty can be specified using either text c("blank","solid","dashed","dotted","dotdash","longdash","
or number c(0, 1, 2, 3, 4, 5, 6). Note that lty = "solid" is identical to lty=1.
lwd line width. Default is 1.
show.equation whether to show the regression equation, the value is one of c("TRUE", "FALSE").
show.Rsquare whether to show the R-square, the value is one of c("TRUE", "FALSE").
show.pvalue whether to show the P-value, the value is one of c("TRUE", "FALSE").
Rname to specify the character of R-square, the value is one of c(0, 1), corresponding
to c(r^2, R^2).
Pname to specify the character of P-value, the value is one of c(0, 1), corresponding to
c(p, P).
xname to specify the character of "x" in equation, see Examples [case 5].
yname to specify the character of "y" in equation, see Examples [case 5].
yhat whether to add a hat symbol (^) on the top of "y" in equation. Default is FALSE.
summary summarizing the model fits. Default is TRUE.
ePos.x, ePos.y equation position. Default as ePos.x = "topleft". If no need to show equation,
set ePos.x = NA. It’s same as those in legend.
text.col the color used for the equation text.
eDigit the numbers of digits for equation parameters. Default is 5.
eSize font size in percentage of equation. Default is 1.
CI.fill fill the confidence interval? (TRUE by default, see ’CI.level’ to control)
CI.level level of confidence interval to use (0.95 by default)
CI.color line or fill color of confidence interval.
CI.alpha alpha value of fill color of confidence interval.
CI.lty line type of confidence interval.
CI.lwd line width of confidence interval.
8 trendline
las style of axis labels. (0=parallel, 1=all horizontal, 2=all perpendicular to axis,
3=all vertical)
xlab, ylab labels of x- and y-axis.
... additional parameters to plot, such as type, main, sub, pch, col.
Details
The linear models (line2P, line3P, log2P) in this package are estimated by lm function,
while the nonlinear models (exp2P, exp3P, power2P, power3P) are estimated by nls function (i.e.,
least-squares method).
If "Pvalue.corrected = TRUE", the P-value is calculated by using "Residual Sum of Squares" and
"Corrected Total Sum of Squares (i.e. sum((y-mean(y))^2))".
If "Pvalue.corrected = FALSE", the P-value is calculated by using "Residual Sum of Squares" and
"Uncorrected Total Sum of Squares (i.e. sum(y^2))".
Note
Confidence intervals for nonlinear regression (i.e., objects of class nls) are based on the linear
approximation described in Bates & Watts (2007) and Greenwell & Schubert-Kabban (2014).
Author(s)
Weiping Mei, Guangchuang Yu
References
Bates, D. M., and Watts, D. G. (2007) Nonlinear Regression Analysis and its Applications. Wiley.
Greenwell B. M., and Schubert-Kabban, C. M. (2014) investr: An R Package for Inverse Estimation.
The R Journal, 6(1), 90-100.
See Also
trendline, SSexp3P, SSpower3P, nls, selfStart, plotFit
Examples
library(basicTrendline)
x <- c(1, 3, 6, 9, 13, 17)
y <- c(5, 8, 11, 13, 13.2, 13.5)
trendline(x, y, "exp3P")
# dev.off()
trendline_summary 9
### [case 2] draw lines of confidence interval only (set CI.fill = FALSE)
trendline(x, y, model="line3P", CI.fill = FALSE, CI.color = "black", CI.lty = 2, linecolor = "blue")
### [case 6] change the digits, font size, and color of equation.
trendline(x, y, model="power2P", eDigit = 3, eSize = 1.4, text.col = "blue")
Description
Summarizing the results of each regression model which built in the ’trendline()’ function. The
function includes the following models in the latest version: "line2P" (formula as: y=a*x+b),
"line3P" (y=a*x^2+b*x+c), "log2P" (y=a*ln(x)+b), "exp2P" (y=a*exp(b*x)),"exp3P" (y=a*exp(b*x)+c),
"power2P" (y=a*x^b), and "power3P" (y=a*x^b+c).
Usage
trendline_summary(
x,
y,
model = "line2P",
Pvalue.corrected = TRUE,
summary = TRUE,
eDigit = 5
)
10 trendline_summary
Arguments
x, y the x and y arguments provide the x and y coordinates for the plot. Any reason-
able way of defining the coordinates is acceptable.
model select which model to fit. Default is "line2P". The "model" should be one of
c("line2P", "line3P", "log2P", "exp2P", "exp3P", "power2P", "power3P"), their
formulas are as follows:
"line2P": y=a*x+b
"line3P": y=a*x^2+b*x+c
"log2P": y=a*ln(x)+b
"exp2P": y=a*exp(b*x)
"exp3P": y=a*exp(b*x)+c
"power2P": y=a*x^b
"power3P": y=a*x^b+c
Pvalue.corrected
if P-value corrected or not, the vlaue is one of c("TRUE", "FALSE").
summary summarizing the model fits. Default is TRUE.
eDigit the numbers of digits for summarized results. Default is 5.
Details
The linear models (line2P, line3P, log2P) in this package are estimated by lm function,
while the nonlinear models (exp2P, exp3P, power2P, power3P) are estimated by nls function (i.e.,
least-squares method).
If "Pvalue.corrected = TRUE", the P-vlaue is calculated by using "Residual Sum of Squares" and
"Corrected Total Sum of Squares (i.e. sum((y-mean(y))^2))".
If "Pvalue.corrected = TRUE", the P-vlaue is calculated by using "Residual Sum of Squares" and
"Uncorrected Total Sum of Squares (i.e. sum(y^2))".
Value
R^2, indicates the R-Squared value of each regression model.
p, indicates the p-value of each regression model.
N, indicates the sample size.
AIC or BIC, indicate the Akaike’s Information Criterion or Bayesian Information Criterion for fitted
model. Click AIC for details. The smaller the AIC or BIC, the better the model.
RSS, indicate the value of "Residual Sum of Squares".
Author(s)
Weiping Mei, Guangchuang Yu
See Also
trendline, SSexp3P, SSpower3P, nls, selfStart
trendline_summary 11
Examples
library(basicTrendline)
x1<-1:5
x2<- -2:2
x3<- c(101,105,140,200,660)
x4<- -5:-1
x5<- c(1,30,90,180,360)
trendline_summary(x1,y1,model="line2P",summary=TRUE,eDigit=10)
trendline_summary(x2,y2,model="line3P",summary=FALSE)
trendline_summary(x3,y3,model="log2P")
trendline_summary(x4,y4,model="exp3P")
trendline_summary(x5,y5,model="power3P")
Index
AIC, 10
legend, 7
lm, 8, 10
nls, 2–5, 8, 10
plot, 8
plotFit, 8
selfStart, 2–5, 8, 10
SSexp2P, 2
SSexp3P, 2, 3, 3, 4, 5, 8, 10
SSpower2P, 4
SSpower3P, 2–5, 5, 8, 10
trendline, 2–5, 6, 8, 10
trendline_summary, 9
12