Details:
## Nonlinear model I want to fit to the data
const.PBMC.tcell.model <- function(B0, t, aL, aN, T0){
Tb0 = B0;
x = exp(-log(aL) + log(T0*aL+(-1+exp(t * aL))*Tb0 * aN) - t * aL);
return(x);
}
##Define selfStart routine
const.PBMC.tcell.selfStart<- function(mCall, LHS, data){
t0 = 0;
t1 = 24;
t2 = 48;
##Get B0 Value
B0 = data[1, "B0"];
T0 = mean(data[data$Time==t0, "Count"]);
T1 = mean(data[data$Time==t1, "Count"]);
T2 = mean(data[data$Time==t2, "Count"]);
if(T0 < T2){ ##increase -- doesn't work
stop(paste("Error in const.PBMC.tcell.start: T0 < T2 for data: ", data[1,
]));
}
##Estimate aL based on exponential decline from t=0 to t=24
aLVal = -(log(T1) - log(T0))/(t1-t0);
##Estimate aNVal based on final value
aNVal = aLVal*T2/B0;
values = list(aLVal, aNVal, T0);
names(values) <- mCall[c("aL", "aN", "T0")]; #mimic syntax used by P&B
return(values)
}
##Now create new model with selfStart attributes
const.PBMC.tcell.modelSS<- selfStart(model = const.PBMC.tcell.model,
initial=const.PBMC.tcell.selfStart)
##Test routines using getInitial -- This works
getInitial(Count ~ const.PBMC.tcell.modelSS(B0, Time,aL, aN, T0), data =
tissueData)
[1] 0.05720924
$aL
[1] 0.05720924
$aN
[1] 0.1981895
$T0
[1] 1360.292
##Now try to use the SS model -- this doesn't work
nls(Count ~ const.PBMC.tcell.modelSS(B0, Time,aL, aN, T0), data =
tissueData)
Error in numericDeriv(form[[3L]], names(ind), env) :
Missing value or an infinity produced when evaluating the model
In addition: Warning message:
In nls(Count ~ const.PBMC.tcell.modelSS(B0, Time, aL, aN, T0), data =
tissueData) :
No starting values specified for some parameters.
Intializing 'aL', 'aN', 'T0' to '1.'.
Consider specifying 'start' or using a selfStart model
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.