######################################################
## 19. Nonlinear Regression
## 비선형 회귀 분석에 사용한다.
## 말그대로 데이터가 선형관계가 아닌 비선형 관계일 경우 사용한다.
######################################################
## (1) One-Compartment Model
## 하나의 exp 만 가지고 증가하는 모델
## 데이터 로딩
setwd(“D:/DEVSource/CSV_DATA/”)
data = read.csv(“one_comp.csv”)
print(data)
## 비선형 분석
## nls 함수 사용
## C0, K 등 초기값 사용
## 결과 = a X
## exp : e^x (e = 20172882)
out = nls(conc~C0*exp(-K*time), start=list(C0=41.3, K=0.64), data=data)
summary(out)
## Grapth 로 표현
install.packages(“NRAIA”)
library(NRAIA)
plotfit(out)
## (2) Tow-Compartment Model
## 두개의 exp 를 가지고 더 급하게 증가하는 모델
data2 = read.csv(“two_comp.csv”)
print(data2)
out2 = nls(conc~SSbiexp(time, A1, lrcl, A2, lrc2), data=data2)
summary(out2)
plotfit(out2)
## (3) One-Compartment Model – 급속증가 – 증가둔화 – 감소
data3 = read.csv(“oral_dose.csv”)
print(data3)
out3 = nls(conc~SSfol(Dose=4.4, time, lKe, lKa, LCl), data=data3)
summary(out3)
plotfit(out3)
## (4)Michaelis-Menten model
data4 = read.csv(“MM.csv”)
out4 = nls(rate~SSmicmen(conc, Vm, K), data=data4)
summary(out4)
plotfit(out4)
## 초기 변수가 필요없는 self-starting function
1. SSasymp()
Description
This selfStart model evaluates the asymptotic regression function and its gradient. It has an initial attribute that will evaluate initial estimates of the parameters Asym, R0, and lrc for a given set of data.
Usage
SSasymp(input, Asym, R0, lrc)
Arguments
input a numeric vector of values at which to evaluate the model.
Asym a numeric parameter representing the horizontal asymptote on the right side (very large values of input).
R0 a numeric parameter representing the response when input is zero.
lrc a numeric parameter representing the natural logarithm of the rate constant.
Value
a numeric vector of the same length as input. It is the value of the expression Asym+(R0-Asym)*exp(-exp(lrc)*input). If all of the arguments Asym, R0, and lrc are names of objects, the gradient matrix with respect to these names is attached as an attribute named gradient.
Author(s)
José Pinheiro and Douglas Bates
See Also
nls, selfStart
Examples
Lob.329 <- Loblolly[ Loblolly$Seed == “329”, ]
SSasymp( Lob.329$age, 100, -8.5, -3.2 ) # response only
Asym <- 100
resp0 <- -8.5
lrc <- -3.2
SSasymp( Lob.329$age, Asym, resp0, lrc ) # response and gradient
getInitial(height ~ SSasymp( age, Asym, resp0, lrc), data = Lob.329)
## Initial values are in fact the converged values
fm1 <- nls(height ~ SSasymp( age, Asym, resp0, lrc), data = Lob.329)
summary(fm1)
2. SSasympOff()
Description
This selfStart model evaluates an alternative parametrization of the asymptotic regression function and the gradient with respect to those parameters. It has an initial attribute that creates initial estimates of the parameters Asym, lrc, and c0.
Usage
SSasympOff(input, Asym, lrc, c0)
Arguments
input a numeric vector of values at which to evaluate the model.
Asym a numeric parameter representing the horizontal asymptote on the right side (very large values of input).
lrc a numeric parameter representing the natural logarithm of the rate constant.
c0 a numeric parameter representing the input for which the response is zero.
Value
a numeric vector of the same length as input. It is the value of the expression Asym*(1 – exp(-exp(lrc)*(input – c0))). If all of the arguments Asym, lrc, and c0 are names of objects, the gradient matrix with respect to these names is attached as an attribute named gradient.
Author(s)
José Pinheiro and Douglas Bates
See Also
nls, selfStart; example(SSasympOff) gives graph showing the SSasympOff parametrization, where phi_1 is Asymp, phi_3 is c0.
Examples
CO2.Qn1 <- CO2[CO2$Plant == “Qn1”, ]
SSasympOff(CO2.Qn1$conc, 32, -4, 43) # response only
Asym <- 32; lrc <- -4; c0 <- 43
SSasympOff(CO2.Qn1$conc, Asym, lrc, c0) # response and gradient
getInitial(uptake ~ SSasympOff(conc, Asym, lrc, c0), data = CO2.Qn1)
## Initial values are in fact the converged values
fm1 <- nls(uptake ~ SSasympOff(conc, Asym, lrc, c0), data = CO2.Qn1)
summary(fm1)
3. SSasympOrig()
Description
This selfStart model evaluates the asymptotic regression function through the origin and its gradient. It has an initial attribute that will evaluate initial estimates of the parameters Asym and lrc for a given set of data.
Usage
SSasympOrig(input, Asym, lrc)
Arguments
input a numeric vector of values at which to evaluate the model.
Asym a numeric parameter representing the horizontal asymptote.
lrc a numeric parameter representing the natural logarithm of the rate constant.
Value
a numeric vector of the same length as input. It is the value of the expression Asym*(1 – exp(-exp(lrc)*input)). If all of the arguments Asym and lrc are names of objects, the gradient matrix with respect to these names is attached as an attribute named gradient.
Author(s)
José Pinheiro and Douglas Bates
See Also
nls, selfStart
Examples
Lob.329 <- Loblolly[ Loblolly$Seed == “329”, ]
SSasympOrig(Lob.329$age, 100, -3.2) # response only
Asym <- 100; lrc <- -3.2
SSasympOrig(Lob.329$age, Asym, lrc) # response and gradient
getInitial(height ~ SSasympOrig(age, Asym, lrc), data = Lob.329)
## Initial values are in fact the converged values
fm1 <- nls(height ~ SSasympOrig(age, Asym, lrc), data = Lob.329)
summary(fm1)
4. SSbiexp()
Description
This selfStart model evaluates the biexponential model function and its gradient. It has an initial attribute that creates initial estimates of the parameters A1, lrc1, A2, and lrc2.
Usage
SSbiexp(input, A1, lrc1, A2, lrc2)
Arguments
input a numeric vector of values at which to evaluate the model.
A1 a numeric parameter representing the multiplier of the first exponential.
lrc1 a numeric parameter representing the natural logarithm of the rate constant of the first exponential.
A2 a numeric parameter representing the multiplier of the second exponential.
lrc2 a numeric parameter representing the natural logarithm of the rate constant of the second exponential.
Value
a numeric vector of the same length as input. It is the value of the expression A1*exp(-exp(lrc1)*input)+A2*exp(-exp(lrc2)*input). If all of the arguments A1, lrc1, A2, and lrc2 are names of objects, the gradient matrix with respect to these names is attached as an attribute named gradient.
Author(s)
José Pinheiro and Douglas Bates
See Also
nls, selfStart
Examples
Indo.1 <- Indometh[Indometh$Subject == 1, ]
SSbiexp( Indo.1$time, 3, 1, 0.6, -1.3 ) # response only
A1 <- 3; lrc1 <- 1; A2 <- 0.6; lrc2 <- -1.3
SSbiexp( Indo.1$time, A1, lrc1, A2, lrc2 ) # response and gradient
print(getInitial(conc ~ SSbiexp(time, A1, lrc1, A2, lrc2), data = Indo.1),
digits = 5)
## Initial values are in fact the converged values
fm1 <- nls(conc ~ SSbiexp(time, A1, lrc1, A2, lrc2), data = Indo.1)
summary(fm1)
5. SSfol()
Description
This selfStart model evaluates the first-order compartment function and its gradient. It has an initial attribute that creates initial estimates of the parameters lKe, lKa, and lCl.
Usage
SSfol(Dose, input, lKe, lKa, lCl)
Arguments
Dose a numeric value representing the initial dose.
input a numeric vector at which to evaluate the model.
lKe a numeric parameter representing the natural logarithm of the elimination rate constant.
lKa a numeric parameter representing the natural logarithm of the absorption rate constant.
lCl a numeric parameter representing the natural logarithm of the clearance.
Value
a numeric vector of the same length as input, which is the value of the expression
Dose * exp(lKe+lKa-lCl) * (exp(-exp(lKe)*input) – exp(-exp(lKa)*input))
/ (exp(lKa) – exp(lKe))
If all of the arguments lKe, lKa, and lCl are names of objects, the gradient matrix with respect to these names is attached as an attribute named gradient.
Author(s)
José Pinheiro and Douglas Bates
See Also
nls, selfStart
Examples
Theoph.1 <- Theoph[ Theoph$Subject == 1, ]
SSfol(Theoph.1$Dose, Theoph.1$Time, -2.5, 0.5, -3) # response only
lKe <- -2.5; lKa <- 0.5; lCl <- -3
SSfol(Theoph.1$Dose, Theoph.1$Time, lKe, lKa, lCl) # response and gradient
getInitial(conc ~ SSfol(Dose, Time, lKe, lKa, lCl), data = Theoph.1)
## Initial values are in fact the converged values
fm1 <- nls(conc ~ SSfol(Dose, Time, lKe, lKa, lCl), data = Theoph.1)
summary(fm1)
6. SSfpl()
Description
This selfStart model evaluates the four-parameter logistic function and its gradient. It has an initial attribute that will evaluate initial estimates of the parameters A, B, xmid, and scal for a given set of data.
Usage
SSfpl(input, A, B, xmid, scal)
Arguments
input a numeric vector of values at which to evaluate the model.
A a numeric parameter representing the horizontal asymptote on the left side (very small values of input).
B a numeric parameter representing the horizontal asymptote on the right side (very large values of input).
xmid a numeric parameter representing the input value at the inflection point of the curve. The value of SSfpl will be midway between A and B at xmid.
scal a numeric scale parameter on the input axis.
Value
a numeric vector of the same length as input. It is the value of the expression A+(B-A)/(1+exp((xmid-input)/scal)). If all of the arguments A, B, xmid, and scal are names of objects, the gradient matrix with respect to these names is attached as an attribute named gradient.
Author(s)
José Pinheiro and Douglas Bates
See Also
nls, selfStart
Examples
Chick.1 <- ChickWeight[ChickWeight$Chick == 1, ]
SSfpl(Chick.1$Time, 13, 368, 14, 6) # response only
A <- 13; B <- 368; xmid <- 14; scal <- 6
SSfpl(Chick.1$Time, A, B, xmid, scal) # response and gradient
print(getInitial(weight ~ SSfpl(Time, A, B, xmid, scal), data = Chick.1),
digits = 5)
## Initial values are in fact the converged values
fm1 <- nls(weight ~ SSfpl(Time, A, B, xmid, scal), data = Chick.1)
summary(fm1)
7. SSgompertz()
Description
This selfStart model evaluates the Gompertz growth model and its gradient. It has an initial attribute that creates initial estimates of the parameters Asym, b2, and b3.
Usage
SSgompertz(x, Asym, b2, b3)
Arguments
x a numeric vector of values at which to evaluate the model.
Asym a numeric parameter representing the asymptote.
b2 a numeric parameter related to the value of the function at x = 0
b3 a numeric parameter related to the scale the x axis.
Value
a numeric vector of the same length as input. It is the value of the expression Asym*exp(-b2*b3^x). If all of the arguments Asym, b2, and b3 are names of objects the gradient matrix with respect to these names is attached as an attribute named gradient.
Author(s)
Douglas Bates
See Also
nls, selfStart
Examples
DNase.1 <- subset(DNase, Run == 1)
SSgompertz(log(DNase.1$conc), 4.5, 2.3, 0.7) # response only
Asym <- 4.5; b2 <- 2.3; b3 <- 0.7
SSgompertz(log(DNase.1$conc), Asym, b2, b3) # response and gradient
print(getInitial(density ~ SSgompertz(log(conc), Asym, b2, b3),
data = DNase.1), digits = 5)
## Initial values are in fact the converged values
fm1 <- nls(density ~ SSgompertz(log(conc), Asym, b2, b3),
data = DNase.1)
summary(fm1)
8. SSlogis()
Description
This selfStart model evaluates the logistic function and its gradient. It has an initial attribute that creates initial estimates of the parameters Asym, xmid, and scal.
Usage
SSlogis(input, Asym, xmid, scal)
Arguments
input a numeric vector of values at which to evaluate the model.
Asym a numeric parameter representing the asymptote.
xmid a numeric parameter representing the x value at the inflection point of the curve. The value of SSlogis will be Asym/2 at xmid.
scal a numeric scale parameter on the input axis.
Value
a numeric vector of the same length as input. It is the value of the expression Asym/(1+exp((xmid-input)/scal)). If all of the arguments Asym, xmid, and scal are names of objects the gradient matrix with respect to these names is attached as an attribute named gradient.
Author(s)
José Pinheiro and Douglas Bates
See Also
nls, selfStart
Examples
Chick.1 <- ChickWeight[ChickWeight$Chick == 1, ]
SSlogis(Chick.1$Time, 368, 14, 6) # response only
Asym <- 368; xmid <- 14; scal <- 6
SSlogis(Chick.1$Time, Asym, xmid, scal) # response and gradient
getInitial(weight ~ SSlogis(Time, Asym, xmid, scal), data = Chick.1)
## Initial values are in fact the converged values
fm1 <- nls(weight ~ SSlogis(Time, Asym, xmid, scal), data = Chick.1)
summary(fm1)
9. SSmicmen()
Description
This selfStart model evaluates the Michaelis-Menten model and its gradient. It has an initial attribute that will evaluate initial estimates of the parameters Vm and K
Usage
SSmicmen(input, Vm, K)
Arguments
input a numeric vector of values at which to evaluate the model.
Vm a numeric parameter representing the maximum value of the response.
K a numeric parameter representing the input value at which half the maximum response is attained. In the field of enzyme kinetics this is called the Michaelis parameter.
Value
a numeric vector of the same length as input. It is the value of the expression Vm*input/(K+input). If both the arguments Vm and K are names of objects, the gradient matrix with respect to these names is attached as an attribute named gradient.
Author(s)
José Pinheiro and Douglas Bates
See Also
nls, selfStart
Examples
PurTrt <- Puromycin[ Puromycin$state == “treated”, ]
SSmicmen(PurTrt$conc, 200, 0.05) # response only
Vm <- 200; K <- 0.05
SSmicmen(PurTrt$conc, Vm, K) # response and gradient
print(getInitial(rate ~ SSmicmen(conc, Vm, K), data = PurTrt), digits = 3)
## Initial values are in fact the converged values
fm1 <- nls(rate ~ SSmicmen(conc, Vm, K), data = PurTrt)
summary(fm1)
## Alternative call using the subset argument
fm2 <- nls(rate ~ SSmicmen(conc, Vm, K), data = Puromycin,
subset = state == “treated”)
summary(fm2)
10. SSweibull()
Description
This selfStart model evaluates the Weibull model for growth curve data and its gradient. It has an initial attribute that will evaluate initial estimates of the parameters Asym, Drop, lrc, and pwr for a given set of data.
Usage
SSweibull(x, Asym, Drop, lrc, pwr)
Arguments
x a numeric vector of values at which to evaluate the model.
Asym a numeric parameter representing the horizontal asymptote on the right side (very small values of x).
Drop a numeric parameter representing the change from Asym to the y intercept.
lrc a numeric parameter representing the natural logarithm of the rate constant.
pwr a numeric parameter representing the power to which x is raised.
Details
This model is a generalization of the SSasymp model in that it reduces to SSasymp when pwr is unity.
Value
a numeric vector of the same length as x. It is the value of the expression Asym-Drop*exp(-exp(lrc)*x^pwr). If all of the arguments Asym, Drop, lrc, and pwr are names of objects, the gradient matrix with respect to these names is attached as an attribute named gradient.
Author(s)
Douglas Bates
References
Ratkowsky, David A. (1983), Nonlinear Regression Modeling, Dekker. (section 4.4.5)
See Also
nls, selfStart, SSasymp
Examples
Chick.6 <- subset(ChickWeight, (Chick == 6) & (Time > 0))
SSweibull(Chick.6$Time, 160, 115, -5.5, 2.5) # response only
Asym <- 160; Drop <- 115; lrc <- -5.5; pwr <- 2.5
SSweibull(Chick.6$Time, Asym, Drop, lrc, pwr) # response and gradient
getInitial(weight ~ SSweibull(Time, Asym, Drop, lrc, pwr), data = Chick.6)
## Initial values are in fact the converged values
fm1 <- nls(weight ~ SSweibull(Time, Asym, Drop, lrc, pwr), data = Chick.6)
summary(fm1)