[R] Need help for nlme
ctu at bigred.unl.edu
ctu at bigred.unl.edu
Sun May 25 20:36:49 CEST 2008
Hi everyone,
I try to write a module based on nlme however R always shows me the
error message
Error in eval(expr, envir, enclos) : object "y" not found. Does anyone
know how to solve this? There is no problem in nls at all.
require(nlme)
AMPmixed<-function(y, x, S1=c("asymptotic","logistic"),
S2=c("asymptotic","logistic"), data, start,random)
{
logist.logist<-function(x,alpha,delta,psi.l,tau.l,gamma,h){
delta+(alpha-delta+gamma*(x-(h-1))/exp(x))/(1+exp(-(x-tau.l)/psi.l))}
logist.asymp<-function(x,alpha,delta,psi.l,tau.l,lpsi.a,gamma,h){
delta+(alpha-delta)/(1+exp(-(x-tau.l)/psi.l))+(gamma*(x-(h-1))/exp(x))*exp(-exp(1/lpsi.a)*x)}
asymp.asymp<-function(x,alpha,delta,lpsi.a,gamma,h){
delta+(alpha-delta)*exp(-exp(1/lpsi.a)*x)+(gamma*(x-(h-1))/exp(x))*exp(-exp(1/lpsi.a)*x)}
asymp.logist<-function(x,alpha,delta,psi.l,tau.l,lpsi.a,gamma,h){
delta+(alpha-delta)*exp(-exp(1/lpsi.a)*x)+(gamma*(x-(h-1))/exp(x))/(1+exp(-(x-tau.l)/psi.l))}
(logistic.logistic<-function(y, x, data, start, random){
nlme.out<-nlme(y~logist.logist(x,alpha,delta,psi.l,tau.l,gamma,h),
data=data, start=start,
fixed=alpha+delta+psi.l+tau.l+gamma+h~1,
random=random)
list(nlme.out=summary(nlme.out))
})
(logistic.asymptotic<-function(y, x, data, start, random){
nlme.out<-nlme(y~logist.asymp(x,alpha,delta,psi.l,tau.l,lpsi.a,gamma,h),
data=data, start=start,
fixed=alpha+delta+psi.l+tau.l+lpsi.a+gamma+h~1, random=random)
list(nlme.out=summary(nlme.out))
})
(asymptotic.logistic<-function(y, x, data, start,random){
nlme.out<-nlme(y~asymp.logist(x,alpha,delta,psi.l,tau.l,lpsi.a,gamma,h),
data=data, start=start,
fixed=alpha+delta+psi.l+tau.l+lpsi.a+gamma+h~1, random=random)
list(nlme.out=summary(nlme.out))
})
(asymptotic.asymptotic<-function(y, x, data, start, random){
nlme.out<-nlme(y~asymp.asymp(x,alpha,delta,lpsi.a,gamma,h), data=data,
start=start,
fixed=alpha+delta+lpsi.a+gamma+h~1,random=random)
list(nlme.out=summary(nlme.out))
})
if(S1=="logistic" && S2=="logistic")
{(AMPmixed=logistic.logistic(y, x, data, start, random))}
else if(S1=="logistic" &&
S2=="asymptotic"){(AMPmixed=logistic.asymptotic(y, x, data, start,
random))}
else if(S1=="asymptotic" &&
S2=="logistic"){(AMPmixed=asymptotic.logistic(y, x, data, start,
random))}
else if(S1=="asymptotic" &&
S2=="asymptotic"){(AMPmixed=asymptotic.asymptotic(y, x, data, start,
random))}
}
#########################################################################
con rep biomass
1 0.00 1 1.126
2 0.32 1 1.096
3 1.00 1 1.163
4 3.20 1 0.985
5 10.00 1 0.716
6 32.00 1 0.560
7 100.00 1 0.375
8 0.00 2 0.833
9 0.32 2 1.106
10 1.00 2 1.336
11 3.20 2 0.754
12 10.00 2 0.683
13 32.00 2 0.488
14 100.00 2 0.344
iso<-read.table(file="E:\\Hormesis\\data\\isobutanol.txt", header=T)
aa<-groupedData(biomass~con|rep, data=iso)
van2<-AMPmixed(y=biomass, x=con, S1="asymptotic", S2="asymptotic", data=aa,
random=pdDiag(alpha+delta+lpsi.a+gamma+h~1),
start=c(alpha= 0.7954, delta= 0.3231, lpsi.a=-0.2738,
gamma= 1.0366, h=0.8429))
van2
Thank you very much in advance.
Chunhao
More information about the R-help
mailing list