-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f0138f1
Showing
28 changed files
with
1,992 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
^.*\.Rproj$ | ||
^\.Rproj\.user$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Package: basicTrendline | ||
Version: 2.0.3 | ||
Date: 2018-07-26 | ||
Title: Add Trendline and Confidence Interval of Basic Regression Models to Plot | ||
Authors@R: c( | ||
person("Weiping", "Mei", email = "[email protected]", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0001-6400-9862")), | ||
person("Guangchuang", "Yu", email = "[email protected]", role = c("aut"), comment = c(ORCID = "0000-0002-6485-8781")), | ||
person("Jiangshan", "Lai", role = c("ctb")), | ||
person("Qiang", "Rao", role = "ctb"), | ||
person("Yu", "Umezawa", role = "ctb") | ||
) | ||
Maintainer: Weiping Mei <[email protected]> | ||
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 ("line2P", "line3P", "log2P", "exp2P", "exp3P", "power2P", "power3P") built in the 'trendline()' function. | ||
Depends: R (>= 2.1.0) | ||
Imports: | ||
graphics, | ||
stats, | ||
scales, | ||
investr | ||
BugReports: https://github.com/PhDMeiwp/basicTrendline/issues | ||
License: GPL-3 | ||
URL: https://github.com/PhDMeiwp/basicTrendline | ||
LazyData: true | ||
RoxygenNote: 6.0.1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(SSexp2P) | ||
export(SSexp3P) | ||
export(SSpower2P) | ||
export(SSpower3P) | ||
export(trendline) | ||
export(trendline_summary) | ||
import(graphics) | ||
import(investr) | ||
import(scales) | ||
import(stats) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Changes in version 2.0.3 | ||
------------------------------------------------------------------------------ | ||
Date: 2018-07-26 | ||
* add several arguments to `trendline()` function, including show.equation, show.Rpvalue, Rname, Pname, xname, yname, yhat, CI.fill, CI.level, CI.alpha, CI.color, CI.lty, CI.lwd, ePos.x, ePos.y, las. | ||
* enable to draw confidence interval for regression models (arguments CI.fill, CI.level, etc.) | ||
* add 'show.equation' and show.Rpvale' arguments to enable to choose which parameter to show | ||
* add 'Rname' and 'Pname' arguments to specify the character of R-square and P-vlaue (i.e. R^2 or r^2; P or p) | ||
* add 'xname' and 'ynameto' arguments to specify the character of 'x' and 'y' in the equation | ||
* add 'yhat' argument to enable to add a hat symbol on the top of 'y' in the equation | ||
* add 'ePos.x' and 'ePos.y' arguments to specify the x and y co-ordinates of equation's position | ||
* deleted the 'ePos' argument | ||
* add "Residual Sum of Squares" to the output of 'trendline_summary()' function | ||
|
||
|
||
Changes in version 1.2.0 | ||
------------------------------------------------------------------------------ | ||
Date: 2018-07-13 | ||
* change the expression for `model` of `exp3P` using a supscript | ||
* add `trendline_summary()` function | ||
* add `SSexp2P()` function | ||
* add `SSpower2P` function | ||
* add `Pvalue.corrected` argument in `trendline()` and `trendline_summary()` , for P-vlaue calculation for non-linear regression. | ||
* add `Details` in `trendline()` and `trendline_summary()` | ||
* add `...` argument in `trendline()` as same as those in `plot()` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#' Self-Starting Nls 'exp2P' Regression Model | ||
#' | ||
#' 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) | ||
#' @param predictor a numeric vector of values at which to evaluate the model. | ||
#' @param a,b The numeric parameters responsing to the exp2P model. | ||
#' @export | ||
#' @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 | ||
#' | ||
#' fitexp2P <- nls(y~SSexp2P(x,a,b), data=xy) | ||
#' summary(fitexp2P) | ||
#' | ||
#' @author Weiping Mei \email{[email protected]} | ||
#' @seealso \code{\link{trendline}}, \code{\link{SSexp3P}}, \code{\link{SSpower3P}}, \code{\link[stats]{nls}}, \code{\link[stats]{selfStart}} | ||
|
||
|
||
# selfStart method for exp2P model (formula as y = a *exp(b*x)) | ||
SSexp2P<-selfStart( | ||
function(predictor,a,b){a*exp(b*predictor)}, | ||
function(mCall,LHS, data) | ||
{ | ||
xy <- sortedXyData(mCall[["predictor"]],LHS, data) | ||
|
||
if (min(y)>0){ | ||
lmFit <- lm(log(xy[,"y"]) ~ xy[,"x"]) | ||
coefs <- coef(lmFit) | ||
a <- exp(coefs[1]) #intercept | ||
b <- coefs[2] #slope | ||
value <- c(a, b) | ||
names(value) <- mCall[c("a","b")] | ||
value | ||
}else{stop(" | ||
>>Try to use other selfStart functions. | ||
Because the 'SSexp2P' function need ALL x values greater than 0.") | ||
} | ||
},c("a","b")) | ||
|
||
# getInitial(y~SSexp2P(x,a,b),data = xy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#' Self-Starting Nls 'exp3P' Regression Model | ||
#' | ||
#' 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) | ||
#' @param predictor a numeric vector of values at which to evaluate the model. | ||
#' @param a,b,c Three numeric parameters responsing to the exp3P model. | ||
#' @export | ||
#' @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 | ||
#' | ||
#' fitexp3P <- nls(y~SSexp3P(x,a,b,c), data=xy) | ||
#' summary(fitexp3P) | ||
#' | ||
#' @author Weiping Mei \email{[email protected]} | ||
#' @seealso \code{\link{trendline}}, \code{\link{SSexp3P}}, \code{\link{SSpower3P}}, \code{\link[stats]{nls}}, \code{\link[stats]{selfStart}} | ||
|
||
# selfStart method for exp3P model (formula as y = a *exp(b*x)+ c) | ||
SSexp3P<-selfStart( | ||
function(predictor,a,b,c){a*exp(b*predictor)+c}, | ||
function(mCall,LHS, data) | ||
{ | ||
xy <- sortedXyData(mCall[["predictor"]],LHS, data) | ||
y=xy[,"y"] | ||
x=xy[,"x"] | ||
adjy=y-min(y)+1 | ||
xadjy=data.frame(x,adjy) | ||
|
||
lmFit <- lm(log(adjy) ~ x) | ||
coefs <- coef(lmFit) | ||
get.b <- coefs[2] #slope | ||
|
||
nlsFit<-nls(adjy~cbind(1+exp(b*x),exp(b*x)), | ||
start = list(b=get.b),data = xadjy,algorithm = "plinear", | ||
nls.control(maxiter = 5000000,minFactor = 10^(-10))) | ||
|
||
coef<-coef(nlsFit) | ||
b<-coef[1] | ||
c<-coef[2]+min(y)-1 | ||
a<-coef[3]+coef[2] | ||
|
||
value <- c(a,b,c) | ||
names(value) <- mCall[c("a","b","c")] | ||
value | ||
},c("a","b","c")) | ||
|
||
# getInitial(y~SSexp3P(x,a,b,c),data = z) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#' Self-Starting Nls 'power2P' Regression Model | ||
#' | ||
#' 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) | ||
#' @param predictor a numeric vector of values at which to evaluate the model. | ||
#' @param a,b The numeric parameters responsing to the exp2P model. | ||
#' @export | ||
#' @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 | ||
#' | ||
#' fitpower2P <- nls(y~SSpower2P(x,a,b), data=xy) | ||
#' summary(fitpower2P) | ||
#' | ||
#' @author Weiping Mei \email{[email protected]} | ||
#' @seealso \code{\link{trendline}}, \code{\link{SSexp3P}}, \code{\link{SSpower3P}}, \code{\link[stats]{nls}}, \code{\link[stats]{selfStart}} | ||
|
||
|
||
# selfStart method for power2P model (formula as y = a *x^b) | ||
SSpower2P<-selfStart( | ||
function(predictor,a,b){a*predictor^b}, | ||
function(mCall,LHS, data) | ||
{ | ||
xy <- sortedXyData(mCall[["predictor"]],LHS, data) | ||
|
||
if (min(x)>0){ | ||
lmFit <- lm(log(xy[,"y"]) ~ log(xy[,"x"])) # both x and adjy values should be greater than 0. | ||
coefs <- coef(lmFit) | ||
a <- exp(coefs[1]) #intercept | ||
b <- coefs[2] #slope | ||
|
||
value <- c(a,b) | ||
names(value) <- mCall[c("a","b")] | ||
value | ||
|
||
}else{stop(" | ||
>>Try to use other selfStart functions. | ||
Because the 'SSpower2P' function need ALL x values greater than 0.") | ||
} | ||
},c("a","b")) | ||
|
||
# getInitial(y~SSpower2P(x,a,b),data = xy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#' Self-Starting Nls 'power3P' Regression Model | ||
#' | ||
#' 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) | ||
#' @param predictor a numeric vector of values at which to evaluate the model. | ||
#' @param a,b,c Three numeric parameters responsing to the exp3P model. | ||
#' @export | ||
#' @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 | ||
#' | ||
#' fitpower3P <- nls(y~SSpower3P(x,a,b,c), data=xy) | ||
#' summary(fitpower3P) | ||
#' | ||
#' @author Weiping Mei \email{[email protected]} | ||
#' @seealso \code{\link{trendline}}, \code{\link{SSexp3P}}, \code{\link{SSpower3P}}, \code{\link[stats]{nls}}, \code{\link[stats]{selfStart}} | ||
|
||
# selfStart method for power3P model (formula as y = a *x^b+ c) | ||
SSpower3P<-selfStart( | ||
function(predictor,a,b,c){a*predictor^b+c}, | ||
function(mCall,LHS, data) | ||
{ | ||
xy <- sortedXyData(mCall[["predictor"]],LHS, data) | ||
y=xy[,"y"] | ||
x=xy[,"x"] | ||
|
||
if (min(x)>0){ | ||
|
||
adjy=y-min(y)+1 | ||
xadjy=data.frame(x,adjy) | ||
|
||
lmFit <- lm(log(adjy) ~ log(x)) # both x and adjy values should be greater than 0. | ||
coefs <- coef(lmFit) | ||
get.b <- coefs[2] #slope | ||
|
||
nlsFit<-nls(adjy~cbind(1+x^b,x^b), | ||
start = list(b=get.b),data = xadjy,algorithm = "plinear", | ||
nls.control(maxiter = 5000000,minFactor = 10^(-10))) | ||
|
||
coef<-coef(nlsFit) | ||
b<-coef[1] | ||
c<-coef[2]+min(y)-1 | ||
a<-coef[3]+coef[2] | ||
|
||
value <- c(a,b,c) | ||
names(value) <- mCall[c("a","b","c")] | ||
value | ||
|
||
}else{stop(" | ||
>>Try to use other selfStart functions. | ||
Because the 'SSpower3P' function need ALL x values greater than 0.") | ||
} | ||
},c("a","b","c")) | ||
|
||
# getInitial(y~SSpower3P(x,a,b,c),data = xy) |
Oops, something went wrong.