Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NonlinearModelFit and ParameterTable

175 views
Skip to first unread message

Ktota

unread,
Jan 10, 2010, 3:30:19 AM1/10/10
to
mtest1[t_,ltime_]:=If [var1*(t+var2-qtime)>8000,Sum[If [var1*(tsum
+var2-qtime)>8000,8000*(1-P),var1*(tsum+var2- qtime)*(1-P)],{tsum,t-
ltime+1, t,1}],Max[{Sum[{var1*(tsum+var2- qtime)*(1-P)},{tsum,t-ltime
+1, t,1}]},0]]/156000


i optimize the model above with:

parameter2=
NonlinearModelFit[ExpData, mtest1[t, ltime], {ltime},
t]


which is perfectly fine...

but as soon i want to see the ParameterTable or the
ConfidenceIntervals by doing this:

parameter2["ParameterTable"]

I get the following error message:

and this only happens if i want to fit for ltime.. parameters P and
var1 are perfectly fine....

In[374]:= parameter2["ParameterTable"]
During evaluation of In[374]:= General::ivar: 9.125191604503259` is
not a valid variable. >>
During evaluation of In[374]:= General::ivar: 9.125191604503259` is
not a valid variable. >>
During evaluation of In[374]:= General::ivar: 9.125191604503259` is
not a valid variable. >>
During evaluation of In[374]:= General::stop: Further output of
General::ivar will be suppressed during this calculation. >>
Out[374]= $Aborted

if i only want to see the result it gives me no error:
In[370]:= parameter2["BestFitParameters"]
Out[370]= {ltime->9.12519}

hope somebody can help...as this drives me mad...

thank you very much

NuKtoBi

dh

unread,
Jan 11, 2010, 5:29:58 AM1/11/10
to

Hi,

it looks like ltime already has a value. Try clearing ltime. Anyway, you

should give a simple working example.

Daniel

Bob Hanlon

unread,
Jan 11, 2010, 5:32:00 AM1/11/10
to

For the following, eliminate the extraneous list brackets and use the symbolic Sum

{Sum[{var1*(tsum + var2 - qtime)*(1 - P)},
{tsum, t - ltime + 1, t, 1}]} // FullSimplify

{{(1/2)*ltime*(P - 1)*var1*(ltime + 2*qtime - 2*t - 2*var2 - 1)}}

Instead of

If[var1*(tsum + var2 - qtime) > 8000,
8000*(1 - P),
var1*(tsum + var2 - qtime)*(1 - P)]

Use

Min[8000*(1 - P), var1*(tsum + var2 - qtime)*(1 - P)]

Then use Piecewise instead of the outer If.

If is primarily a programming construct; whereas, Piecewise is intended as a mathematical construct.

mtest1[t_, ltime_] :=
Piecewise[{{
Sum[
Min[
8000*(1 - P),
var1*(tsum + var2 - qtime)*(1 - P)],
{tsum, t - ltime + 1, t, 1}],
var1*(t + var2 - qtime) > 8000}},
Max[
ltime*(P - 1)*var1*
(ltime + 2*(qtime - t - var2) - 1)/2,
0]]/156000

Without realistic test data and knowing the values of the constants that are not parameters, I will not go further.

Also, if you look at the symbolic output expression for mtest1[t, ltime] you will see that it might simplify considerably if you include any known constraints on the constants and/or parameters.


Bob Hanlon

---- Ktota <nuk...@gmail.com> wrote:

=============

Darren Glosemeyer

unread,
Jan 11, 2010, 6:54:29 PM1/11/10
to

A working example would be needed to figure out what is happening. My
best guess is that there is a problem with the model specification
(Daniel and Bob mentioned a couple possible issues) or that this example
runs into trouble computing derivatives of the model which are needed
for standard errors and such. If it is trouble with derivatives, it may
be a bug in need of fixing, but a full working example would be needed.

Darren Glosemeyer
Wolfram Research

Ktota

unread,
Jan 13, 2010, 6:01:02 AM1/13/10
to

Dear All,

thank you for your replies. I try to post a working example again... i
though i send it yesterday. I guess I didn't actually press the send
button as my message still doesn't appear.

Even with the nice changes suggested by bob it didn't work (Daniel:
clearing didn't help :( ), it made the code certainly more elegant.
Nevertheless this is what happened when I introduced the changes:
Mathematica got stuck, till I was forced to abort the evaluation with
no result (mathematica prompted me several times to abort the
evaluation... if i don't do that the mathematica crashes after a
time). When I tried to see what happens if I use StepMonitor or
EvaluationMonitor I could see that Mathematica didn't even try to give
my parameters a value... so it must have got stuck at the very
beginning.

again: Using my code I get the same error messages as described in my
previous post.

Ok, I want to provide yo with an working example:

This are the optimum parameter sets:

1.Please replace the 8000 with 6600, it should not matter to much at
the end... but well, this would be the optimum number to set.

2.Here are the constant values:

ltime = 10
var1=40
qtime=40
var2=10
P=0.7

suitable ranges for t <360 (but you can see that from the example data
provided)

Right now i proceed the following way: I clear the parameter i'm
looking for and set the rest (and update replace the corresponding
line of code). So if you fitting for ltime or P you need to set the
values above correspondingly. Usually what i get if i fit for P is
approx. 0.7, if i fit for ltime approx. 9.5.

3. A working dataset for tests:

{{10, 0}, {20, 0}, {30, 0}, {40, 0}, {50, 0}, {60, 0.00585596}, {70,
0.00978394}, {80, 0.014027}, {90, 0.0193965}, {100, 0.033127},
{110,
0.0229201}, {120, 0.0342658}, {130, 0.038038}, {140, 0.0467315},
{150,
0.0599289}, {160, 0.0843373}, {170, 0.0933467}, {180, 0.0972515},
{200,
0.124476}, {220, 0.126171}, {240, 0.149213}, {260, 0.125667}, {280,
0.131284}, {300, 0.111403}, {20, 0}, {30, 0}, {40, 0}, {50, 0},
{60,
0.00504185}, {70, 0.00105643}, {80, 0.00476066}, {90, 0.0199289},
{100,
0.0278976}, {110, 0.0363378}, {120, 0.0487953}, {130, 0.0592385},
{140,
0.0586732}, {150, 0.0720589}, {160, 0.0790288}, {170, 0.0908122},
{180,
0.098357}, {200, 0.120454}, {220, 0.133432}, {240, 0.137956}, {270,
0.159881}, {300, 0.152705}, {330, 0.170188}, {360, 0.125013}, {20,
0}, {30,
0}, {40, 0}, {50, 0.0057359}, {60, 0.00883602}, {70, 0.0155384},
{80,
0.0219417}, {90, 0.0356022}, {100, 0.0309318}, {110, 0.0378177},
{120,
0.0602476}, {130, 0.0657433}, {140, 0.0676202}, {150, 0.0840599},
{160,
0.100496}, {170, 0.0842674}, {180, 0.113089}, {200, 0.0969867},
{220,
0.123612}, {240, 0.119192}, {270, 0.115528}, {300, 0.129542}, {330,
0.119207}, {360, 0.124696}}


3. For convinience here also an updated model:

mtest1[t_,ltime_]:=If [var1*(t+var2-qtime)>6600,Sum[If [var1*(tsum
+var2-qtime)>6600,6600*(1-P),var1*(tsum+var2- qtime)*(1-P)],{tsum,t-

ltime+1, t,1}],Max[{Sum[{var1*(tsum+var2- qtime)*(1-P)},{tsum,t-ltime
+1, t,1}]},0]]/156000

This is how i do the fitting:

parameterWT2 =
NonlinearModelFit[ExperimentalData, mtest1[t, ltime], {ltime},
t]

I hope i didn't miss out anything.

Best Wishes

Bob Hanlon

unread,
Jan 14, 2010, 5:49:18 AM1/14/10
to

First, you cannot assign a value to ltime if it is the parameter of the NonlinearModelFit.

As stated before, use Piecewise instead of If.

Clear[ltime, mtest1, parameterWT2];

var1 = 40;
qtime = 40;
var2 = 10;
P = 7/10;

ExperimentalData = Rationalize[{

{330, 0.119207}, {360, 0.124696}}, 0];

mtest1[t_, ltime_] =
FullSimplify[Piecewise[{{
Sum[
Piecewise[
{{6600*(1 - P), var1*(tsum + var2 - qtime) > 6600}},


var1*(tsum + var2 - qtime)*(1 - P)],
{tsum, t - ltime + 1, t, 1}],

var1*(t + var2 - qtime) > 6600}},
Max[{


Sum[{var1*(tsum + var2 - qtime)*(1 - P)},
{tsum, t - ltime + 1, t, 1}]

}, 0]]/156000, 0 <= t <= 360]

parameterWT2[t_] = Normal[NonlinearModelFit[
ExperimentalData, mtest1[t, ltime], {ltime}, t]] // FullSimplify

Plot[parameterWT2[t], {t, 0, 360},
Epilog -> {Red, AbsolutePointSize[3],
Point[ExperimentalData]}]


Bob Hanlon

---- Ktota <nuk...@gmail.com> wrote:

=============

Ktota

unread,
Jan 15, 2010, 3:15:22 AM1/15/10
to
Of course i clear the paramater for which i'm trying to find a best
fit... that is not the problem! . You can exchange ltime with P in the
nonlinearmodelfit... in case of P it will work.. in case of ltime it
won't work.
Nevetheless thank you for your new suggestion, i will see if i can get
it to work now.

Thank you for your help again :)

Konstantin

Ktota

unread,
Jan 15, 2010, 3:19:36 AM1/15/10
to
Sorry, my problem is not to find the best fit value of ltime. That
worked.. But i can't get confidence intervals and other values from
nonlinearmodelfit... also bob's version of my code doesn't work for
that. But i can see what i can do with that, as at least it is not the
same error i get. Just again to say again: my problem is not getting
best fits.. my problem is to get confidence intervals and other
statistics (or even just getting a parametertable).

Best wishes

0 new messages