[R] How to write a package based on nlme

ctu at bigred.unl.edu ctu at bigred.unl.edu
Sun May 25 12:40:07 CEST 2008


Dear R Helpers,
I try to write a small package that based on nlme however my code does  
not work.
R always appears this message:
Error in eval(expr, envir, enclos) : object "y" not found
where y is the response variable. Please help me out!
This is my code:
require(nlme)
AMPmixed<-function(y, x, S1=c("asymptotic","logistic"), random,data,  
S2=c("asymptotic","logistic"), start)
      {
       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, na.action)
            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, na.action)
              list(nlme.out=summary(nlme.out))
            })
            (asymptotic.logistic<-function(y, x, data, start,random){
            xy<-sortedXyData(x,y,data=data)
            if(nrow(xy)<8){stop("Too few factor levels to fit an  
asymptotic.logistic")}
             
nlme.out<-nlme(y~asymp.logist(x,alpha,delta,psi.l,tau.l,lpsi.a,gamma,h),  
data=data, start=start, na.action)
                 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,
+          start=c(alpha= 0.7954, delta= 0.3231,  lpsi.a=-0.2738,  
gamma= 1.0366, h=0.8429))
Error in eval(expr, envir, enclos) : object "y" not found

Thank you very much~~
Chunhao



More information about the R-help mailing list