[R] Error in eval(expr, envir, enclos) : object 'N' not found

0 views
Skip to first unread message

hansoffate

unread,
Dec 5, 2009, 10:47:31 PM12/5/09
to r-h...@r-project.org

I'm running an LSODA to generate some graphs, but I need to stop at a certain
point and use those values to generate another LSODA output. This is
working fine, but when I try to run the second LSODA, I get the "Error in
eval(expr, envir, enclos) : object 'N' not found". Any ideas what can be
causing this? I have no object 'N' anywhere in the script. I made an
identical version of models states, parameters, and everything just by
adding 2 after each one, and I'm still getting this error.

Thanks,
-Hans

::CODE::
require(odesolve);
###Params for running script ##
iniT=1E3; iniN=10; iniM=0; iniC=1E3;
num_days = 30; interval_size = .1; OF_prcnt = .10;

model <- function(t, state, pars)
{
with (as.list(c(state, pars)), {
dT=(a*T-a*T*b*T) - (c1*N*T) - (Kt*M*T)
dN=a1 - (f*N) + g * (T/(h+T)) * N - (p * N * T) - (Kn * M * N)
dC=a2 - (beta * C) - (Kc * M * C)
dM= -(gamma) * M + Vm

return(list(c(dT,dN,dC,dM)))
})
}

model2 <- function(t, state2, pars2)
{
with (as.list(c(state2, pars2)), {
dT=(a*T-a*T*b*T) - (c1*N*T) - (Kt*M*T)
dN=a1 - (f*N) + g * (T/(h+T)) * N - (p * N * T) - (Kn * M * N)
dC=a2 - (beta * C) - (Kc * M * C)
dM= -(gamma) * M + Vm

return(list(c(dT,dN,dC,dM)))
})
}

### First Half - Tumor growth to 10%
pars <- list( Tini=iniT, Nini=iniN, Mini=iniM, Cini=iniC,
a=4.31E-3, b=1.02E-14, c1=3.41E-10, Kt=8E-1,
f=4.12E-2, g=1.5E-2, h=2.02E1, beta=1.20E-2, gamma=9E-1,
Kc=6E-1, Kn=6E-1, p=2E-11, a1=1.2E4, a2=7.5E8, Vm=0 )

tout <- seq(0, num_days, by=interval_size)
state <- c(T = pars$Tini, N = pars$Nini, C = pars$Cini, M = pars$Mini)
out <- lsoda(state, tout, model, pars)

## Finding position at which OF function is reached
final_matrix = out;
loopsize = (num_days / interval_size) + 1
OF_tumor_size = iniT + (OF_prcnt * iniT)

## Sentinel Value to find at which row in the matrix reaches OF_tumor_size
OF_row=-1;
for(i in 1:loopsize) {
if( out[i,2] >= OF_tumor_size) {
OF_row=i;
break;
}
}

if(OF_row != -1) {
##Params setup
OF_iniT=out[OF_row,2]; OF_iniN=out[OF_row,3]; OF_iniC=out[OF_row,4];
OF_iniM=out[OF_row,5];
pars2 <- list( Tini=OF_iniT, Nini=OF_iniN, Mini=OF_iniM, Cini=OF_iniC,
a=4.31E-3, b=1.02E-14, c1=3.41E-10, Kt=8E-1,
f=4.12E-2, g=1.5E-2, h=2.02E1, beta=1.20E-2, gamma=9E-1,
Kc=6E-1, Kn=6E-1, p=2E-11, a1=1.2E4, a2=7.5E8, Vm=0 )
state2 <- c(T = pars2$Tini, N = pars2$Nini, C = pars2$Cini, M =
pars2$Mini)
out2 <- lsoda(state2, tout, model2, pars2)
}
--
View this message in context: http://n4.nabble.com/Error-in-eval-expr-envir-enclos-object-N-not-found-tp949512p949512.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-h...@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.

hansoffate

unread,
Dec 5, 2009, 9:18:31 PM12/5/09
to r-h...@r-project.org

Thanks,
-Hans

--
View this message in context: http://n4.nabble.com/Error-in-eval-expr-envir-enclos-object-N-not-found-tp949499p949499.html

Uwe Ligges

unread,
Dec 6, 2009, 9:56:34 AM12/6/09
to hansoffate, r-h...@r-project.org

hansoffate wrote:
> I'm running an LSODA to generate some graphs, but I need to stop at a certain
> point and use those values to generate another LSODA output. This is
> working fine, but when I try to run the second LSODA, I get the "Error in
> eval(expr, envir, enclos) : object 'N' not found". Any ideas what can be
> causing this? I have no object 'N' anywhere in the script.

At least I see capital N in both model and model2 - roughly 10 times ...

Uwe Ligges

______________________________________________

hansoffate

unread,
Dec 6, 2009, 1:12:35 PM12/6/09
to r-h...@r-project.org

Oh yes, that's true, but I don't understand why the same exact model works
fine the first time I run LSODA, then running the model again with different
PARMS causes it to error with this error. I've been trying to debug or
find other relevant posts with this same error, but so far I have had no
lucky.

Any help would be appreciated.
-Hans

--
View this message in context: http://n4.nabble.com/Error-in-eval-expr-envir-enclos-object-N-not-found-tp949516p949701.html


Sent from the R help mailing list archive at Nabble.com.

______________________________________________

Peter Dalgaard

unread,
Dec 6, 2009, 1:49:46 PM12/6/09
to hansoffate, r-h...@r-project.org
hansoffate wrote:
> Oh yes, that's true, but I don't understand why the same exact model works
> fine the first time I run LSODA, then running the model again with different
> PARMS causes it to error with this error. I've been trying to debug or
> find other relevant posts with this same error, but so far I have had no
> lucky.
>
> Any help would be appreciated.
> -Hans

Just print out state and state2, and you'll see that you are being done
in by naming rules:

> state2
T.T N.N C.C M.M
1.100422e+03 2.027655e+05 1.473149e+10 0.000000e+00
> state
T N C M
1000 10 1000 0
> pars2$Tini
T
1100.422
> pars$Tini
[1] 1000

I.e., the problem is that using the naming forms of c() with vectors
that already have names tries to combine the names into new names.

> c(a=c(a=2))
a.a
2

In your case, it looks like it works just to avoid the extra layer of
naming:
> state2 <- c(pars2$Tini, pars2$Nini, pars2$Cini, pars2$Mini)


> out2 <- lsoda(state2, tout, model2, pars2)

> out2
time T N C M
[1,] 0.0 1100.422 202765.5 14731494538 0
[2,] 0.1 1100.888 203427.9 14788782468 0
[3,] 0.2 1101.355 204088.5 14846001846 0
[4,] 0.3 1101.823 204747.4 14903152673 0
[5,] 0.4 1102.290 205404.6 14960234948 0
....


--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dal...@biostat.ku.dk) FAX: (+45) 35327907

Reply all
Reply to author
Forward
0 new messages