search for: sortedxydata

Displaying 20 results from an estimated 21 matches for "sortedxydata".

2005 Sep 01
1
making self-starting function for nls
...Init, see below), I assume that the error is coming from within the mCall function but I can't figure out where or how. Would someone who has successfully done this be willing to look at my code and see where the problem arises? > NRhyperbolaInit function(mCall,LHS,data) { xy<-sortedXyData(mCall[["x"]],LHS,data) if(nrow(xy)<3){ stop("Too few unique irradiance values") } theta<-0.75 Rd<-min(xy[,"y"]) Am<-max(xy[,"y"]) + abs(Rd) if(sum(xy[,"x"]<50)>3)alpha<-coef(lm(y~x,data=xy,subset=x<50))[2] if(sum(xy[...
2006 May 24
1
problem-nlme
...#vonBertlalanffy vonBert<- function(x, Linf, K, t0) Linf*(1-exp(-K*(x-t0))) size ~ vonBert(age, Linf, K,t0) vonBert <-deriv(~ Linf*(1-exp(-K*(x-t0))), c("Linf","K","t0"),function(x,Linf,K,t0){}) vonBertInit <- function(mCall, LHS, data) { xy <- sortedXyData(mCall[["x"]], LHS, data) Linf <- 900 if (Linf != max(xy[,"y"])) Linf <- -Linf K <- 0.3 t0<-0 value <- c(Linf, K, t0) names(value) <- mCall[c("Linf", "K","t0")] value } vonBert <- selfStart(vonBert,...
2008 Aug 29
1
nls() fails on a simple exponential fit, when lm() gets it right?
...5.2,15.5) height=c(5.770089,5.154794,4.888847,6.356770,14.849109,14.973146,15.423816,14.865038,21.335985,20.477624,20.915823,21.886004,23.714724,24.182210,23.954929,23.784659,25.334360,25.411320,26.218614,25.612478) #&#&#height=5*exp(0.03*dbh) logarithmicInit=function(mCall,LHS,data) { xy=sortedXyData(mCall[["x"]],LHS,data) aaa=0.01 #Just guess aaa=0.01 to start the fit bbb=min(xy$y) #Use the minimum y value as an initial guess for bbb value=c(aaa,bbb) names(value)=mCall[c("aaa","bbb")] return(value) } fmla=as.formula("~(aaa*log(x)+bbb)") SSlogarit...
2005 Sep 07
1
summary of problem with mCall function.
Last week I posted a question concerning the mCall function, which is used to create self-starting functions and is described in the book by Pinheiro, J.C. and Bates, D.M. (Mixed-effects models in S and S-PLUS). On page 345 one finds the following call: xy<-sortedXyData(mCall[["x"]], LHS,data) It is necessary to replace the "x" in the call to mCall by the actual variable name for the dependent variable. The error message that I was getting was due to the fact that I had called by dependent variable in the data frame (data) by another name...
2008 Aug 04
0
Unexpected nls behaviour: Solved
...ers' argument to selfStart. Making this change to SSbatch gives the same (successful) result from the two calls to nls. SSbatch<-selfStart( model=function(Batch, Coeffs) { Coeffs[Batch] } ,initial=function(mCall, data, LHS) { # Estimate coefficients as mean of each batch xy <- sortedXyData(mCall[["Batch"]], LHS, data) Batch <- data[[as.character(mCall[["Batch"]])]] # check Batch is successive integers starting at 1 if ((min(xy$x) !=1) | (any(diff(xy$x)!=1))) stop( "Batch is not a successive integers sequence") Lval <- list(xy$y) names(Lval)...
2009 Oct 14
0
Problem with NLSstClosestX; and suggested fix
...ar data set returns NA, which is a bit silly! -------------- sXY <- structure(list(x = c(0, 24, 27, 48, 51, 72, 75, 96, 99), y = c(4.98227, 6.38021, 6.90309, 7.77815, 7.64345, 7.23045, 7.27875, 7.11394, 6.95424)), .Names = c("x", "y"), row.names = c(NA, 9L), class = c("sortedXyData", "data.frame")) a <- NLSstLfAsymptote(sXY) d <- NLSstRtAsymptote(sXY) NLSstClosestX(sXY, (a+d)/2) ------------------------ I think the problem arises when the target y value is exactly equal to one of the y values in sXY and can be fixed by trapping that situation thus: -----...
2005 Oct 26
0
self starting function for nonlinear least squares.
...hetic rate # Rd is the dark resiration rate (positive value) # theta is the shape parameter # alpha is the initial quantum yeild # (1/(2*theta))* (alpha*Irr + Am - sqrt((alpha*Irr + Am)^2 -4*alpha*theta*Am*Irr))- Rd } attr(,"initial") function (mCall, LHS, data) { xy <- sortedXyData(mCall[["Irr"]], LHS, data) if (nrow(xy) < 3) stop("Too few unique irradiance values") fit <- smooth.spline(xy[, "x"], xy[, "y"]) alpha <- predict(fit, x = 0, deriv = 1)$y if(min(xy[,"x"],na.rm=T)>0)delta.for.z...
2010 Apr 15
0
nlsList {nlme} - control arguments problem
...ing optim to optimize the parameters prior to each fit. This worked well for me as I had a customized selfStart function that then optimized the parameters for each individual separately. if you rewrote your selfStart function as: powrDpltInit <- function(mCall, LHS, data) { xy <- sortedXyData(mCall[["x"]],LHS,data) min.s <- min(y) dif.s <- max(y)-min(y) dplt.s <- 0.5 p.s <- -.20 value <- c(min.s, dplt.s, dif.s, p.s) #function to optimize func1 <- function(value) { min.s <- value[1] dif.s <- value[2] dplt.s <- value...
2007 Apr 20
1
nlme trouble
...ll,LHS,data) { model=as.character(mCall[[1]]) #I don't know what this does a <- tan(pi/4) # 45 degree angle (rising slope) b <- -tan(pi/4) # 45 degree angle (desending slope) c <- 0 # intercept nu <- 0.434 xy <- sortedXyData(mCall[["x"]], LHS, data) x <- xy[["x"]] x0 <- (min(x)+max(x))/2 + nu*((log(a, exp(1)) - log(b, exp(1))))/(a+b) #log defaults to base e value = c(nu,a,b,c,x0) names(value)=mCall[c("nu","a","b","c","x0")] value }...
2008 Aug 01
0
Unexpected nls behaviour
...ial(Aform, DF)) but in this example that is not the case in R (although it is in S-plus V6.2) ------------------------------ SSbatch<-selfStart( model=function(Batch, Coeffs) { Coeffs[Batch] } ,initial=function(mCall, data, LHS) { # Estimate coefficients as mean of each batch xy <- sortedXyData(mCall[["Batch"]], LHS, data) Batch <- data[[as.character(mCall[["Batch"]])]] # check Batch is successive integers starting at 1 if ((min(xy$x) !=1) | (any(diff(xy$x)!=1))) stop( "Batch is not a successive integers sequence") Lval <- list(xy$y) names(Lval)...
2010 Apr 12
0
How to derive function for parameters in Self start model in nls
...* .expr2) .grad[, "b3"] <- -Asym * (.expr4 * (b2 * (b3^(x - 1) * x))) dimnames(.grad) <- list(NULL, .actualArgs) attr(.value, "gradient") <- .grad } .value attr(,"initial") function (mCall, data, LHS) { xy <- sortedXyData(mCall[["x"]], LHS, data) if (nrow(xy) < 4) { stop("too few distinct input values to fit the Gompertz model") } xyL <- xy xyL$y <- log(abs(xyL$y)) pars <- NLSstAsymptotic(xyL) pars <- coef(nls(y ~ exp(-b2 * b3^x), data = xy, algorith...
2009 Jun 29
0
nlsList {nlme} - control arguments problem
...minFactor: num 0.000977 ?.. ..$ printEval: logi FALSE ?.. ..$ warnOnly : logi FALSE ?.. ..$ algorithm: chr "port" ?.. ..$ lower ? ?: num [1:4] 0 0 0 -10 If it helps, here's the selfStart function that I'm using.... powrDpltInit <- function(mCall, LHS, data) { ? xy ? ? <- sortedXyData(mCall[["x"]],LHS,data) ? min.s ?<- min(y) ? dif.s ?<- max(y)-min(y) ? dplt.s <- 0.5 ? p.s ? ?<- -.20 ? value ?<- c(min.s, dplt.s, dif.s, p.s) ? names(value) <- mCall[c("min","dplt","dif","p")] ? value } SSpowrDplt<-selfStart(~m...
2007 Oct 17
2
nmle: gnls freezes on difficult case
...<-data.frame(conc=c(0.00203,0.0061,0.0183,0.0549,0.165,0.494,1.48,4.44,13.3,40), response=c(12,-4,19,11,-5,-3,1,6,0,-8)) #### Self start function SSllogis <- selfStart(~ A + (B-A)/(1 + exp(scal*(log(x)-log(xmid)))), function(mCall, data, LHS) { #browser() xy <- sortedXyData(mCall[["x"]], LHS, data) if (nrow(xy) < 5) { stop("too few distinct input values to fit a four-parameter logistic") } rng <- range(xy$y) drng <- diff(rng) B <- rng[2] + 0.001 A <- rng[1] - 0.001 xy$prop <- log((B-xy...
2009 Nov 12
0
writing selfStart models that can deal with treatment effects
...<- function(Tb0, time, aL, aN, T0){ exp(-time*aL)*(T0*aL+(-1+exp(time * aL))*Tb0 * aN)/aL } expDecayAndConstantInflowModelInit <- function(mCall, LHS, data){ print(paste("SelfStart mCall:", mCall)); print(attributes(mCall)); print(mCall[["aN"]]); xy <- sortedXyData(mCall[["time"]], LHS, data); lmFit <- lm(log(xy[, "y"]) ~ xy[, "x"]); coefs <- coef(lmFit); T0 <- exp(coefs[1]); aL <- -coefs[2]*0.99; aN <- 0.0001; value <- c(aL, aN, T0); names(value) <- mCall[c("aL", "aN"...
2008 Sep 26
0
The 'data' argument and scoping in nls
...rame with y and x, so I can't use (for example) model.frame(y ~ SSfunc(x, Coeff, A), data=... ) I've found one solution by noticing that (in nls, lm, ...) 'data' can be a list, so I can store objects of different lengths. That leads to my first question(s): Q1) ?getInitial and ?sortedXyData suggest that 'data' must be "a data frame". I think this limitation isn't real. Can I safely use a list (or an environment or ??) for 'data'? Or is this going to "break" something (e.g. if I end up passing this data onto selfStart functions provided with R...
2002 Jul 19
1
selfStart function problem
Hello, list, I am making a self-starting nonlinear function to model the relation of tree height (H) and diameter (D) in a forest stand. The function I am trying is H=a*exp[b*(D+5.8)^(-c)]. To calculate the initial estimates of the parameters, I linearized the formula by taking logarithms and fixing the parameter c=1. Then I calculated the initial estimates of a and b using lm() on the
2008 May 25
1
How to write a package based on nlme
...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))...
2001 May 01
0
SSfpl self-start sometimes fails... workaround proposed
....grad[, "scal"] <- (.expr1 * (.expr4 * (.expr2/(scal^2))))/.expr13 dimnames(.grad) <- list(NULL, .actualArgs) attr(.value, "gradient") <- .grad } .value } # Self-starting function for fpl fpl.ival <- function (mCall, data, LHS) { xy <- sortedXyData(mCall[["input"]], LHS, data) if (nrow(xy) < 5) { stop("Too few distinct input values to fit a four-parameter logistic") } xydata <- c(as.list(xy), xmid = NLSstClosestX(xy, mean(range(xy[["y"]])))) xydata <- as.list(xydata) options(s...
2008 Aug 05
0
P values in non linear regression and singular gradients using nls
...ers' argument to selfStart. Making this change to SSbatch gives the same (successful) result from the two calls to nls. SSbatch<-selfStart( model=function(Batch, Coeffs) { Coeffs[Batch] } ,initial=function(mCall, data, LHS) { # Estimate coefficients as mean of each batch xy <- sortedXyData(mCall[["Batch"]], LHS, data) Batch <- data[[as.character(mCall[["Batch"]])]] # check Batch is successive integers starting at 1 if ((min(xy$x) !=1) | (any(diff(xy$x)!=1))) stop( "Batch is not a successive integers sequence") Lval <- list(xy$y) names(Lval)...
2000 Feb 17
2
Installation of rpm file on Suse Linux 6.2 (PR#449)
...rt.R action: create D: file: /usr/local/lib/R/library/nls/R-ex/selfStart.default.R action: create D: file: /usr/local/lib/R/library/nls/R-ex/selfStart.formula.R action: create D: file: /usr/local/lib/R/library/nls/R-ex/setNames.R action: create D: file: /usr/local/lib/R/library/nls/R-ex/sortedXyData.R action: create D: file: /usr/local/lib/R/library/nls/R/nls action: create D: file: /usr/local/lib/R/library/nls/TITLE action: create D: file: /usr/local/lib/R/library/nls/data action: create D: file: /usr/local/lib/R/library/nls/data/00Index action: create D: file: /usr/local/lib/R...