[R] fitting nlme model inside a function

Roger Peng rpeng at stat.ucla.edu
Thu Aug 29 02:38:55 CEST 2002


I'm not an experienced user of the 'nlme' package but I ran into a curious
problem recently that I couldn't find on the mailing list anywhere.

I have simple function which calls 'groupedData' and 'nlme':

g <- function(dataset) {
    unig <- groupedData(logfv ~ Vs+v1+v2+v3+PHA| EQ, data=dataset)
    
    modelfv <- nlme(logfv~a + c*log(Vs/a1)+ b1*( v1 +
         v2*(Vs-300)^2/(300-120)^2 )*log(PHA/0.1)   
         + b2*( v3 + v2 + (-1*v2)*(Vs-300)^2 /(300-120)^2)*log(PHA/0.1),
                    data=unig, fixed=a1+c+b1+b2~1, random=a~1|EQ ,
                    start=c(a1=0.05, b1=0.1, b2=0.1, c=0.1))
}

and the following data frame:

"test.uni" <-
structure(list(Fv = c(0.719674506, 1.76086339, 1.235763846, 0.592482033, 
0.536563657, 0.935437428, 1.030349018, 1.10411289, 1.192487905, 
0.398788849), Eqs = c(131, 122, 122, 122, 122, 122, 122, 54, 
122, 131), Vs = c(1309.116, 1303.02, 1240.536, 1219.2, 1136.998, 
1018.032, 893.064, 893.064, 874.776, 853.44), PHA = c(0.1608982, 
0.048490234, 0.052890618, 0.057810549, 0.24927051, 0.06389893, 
0.055244608, 0.15433018, 0.054221601, 0.13537748), Site = c(5, 
5, 5, 5, 5, 5, 5, 5, 5, 5), EQ = structure(c(27, 24, 24, 24, 
24, 24, 24, 13, 24, 27), class = "factor", .Label = c("6", "12", 
"25", "28", "29", "30", "33", "34", "45", "48", "50", "53", "54", 
"73", "76", "77", "80", "90", "100", "103", "117", "118", "120", 
"122", "127", "129", "131", "142", "147", "148", "151", "153"
)), logfv = c(-0.328956244188746, 0.565804251263614, 0.211689277673822, 
-0.523434730483267, -0.622570071573506, -0.0667410216621068, 
0.0298975972712109, 0.0990421980619555, 0.176041801171271,
-0.919323202669533
)), .Names = c("Fv", "Eqs", "Vs", "PHA", "Site", "EQ", "logfv"
), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", 
"10"), class = "data.frame")


But when I run the 'g' function in R, I get the following error:

> g(test.uni)
Error in inherits(data, "data.frame") : Object "dataset" not found
> traceback()
5: inherits(data, "data.frame")
4: nfGroupedData(formula = logfv ~ Vs + v1 + v2 + v3 + PHA | EQ, 
       data = dataset)
3: do.call("nfGroupedData", mCall)
2: groupedData(logfv ~ Vs + v1 + v2 + v3 + PHA | EQ, data = dataset)
1: g(test.uni)


Any hints?




> version
         _                           
platform i686-pc-linux-gnu           
arch     i686                        
os       linux-gnu                   
system   i686, linux-gnu             
status   Under development (unstable)
major    1                           
minor    6.0                         
year     2002                        
month    08                          
day      28                          
language R                           

Package: nlme
Version: 3.1-29
Date: 2002/08/10

-roger
_______________________________
UCLA Department of Statistics
rpeng at stat.ucla.edu
http://www.stat.ucla.edu/~rpeng


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list