[ADMB Users] likelihood profile for elements in vector?
Poos, Jan Jaap
janjaap.Poos at wur.nl
Sun Sep 19 07:25:34 PDT 2010
You can do just about anything in C++.
Define a class likeprof_vector in the GLOBALS_SECTION
You may have to move some things in the header file to make them
public. also this was originally done on dos with 8+3 file names so
keep them short
or they may get truncated.
DATA_SECTION
PARAMETER_SECTION
init_number logR1
init_number logR2
sdreport_number avgR
!!CLASS likeprof_vector xx(1,20,"my") // vector of 20
likeprof_numbers
sdreport_number R1
sdreport_number R2
objective_function_value f
PROCEDURE_SECTION
R1=exp(logR1);
R2=exp(logR2);
avgR=(R1+R2)/2.0;
f=100*square(logR1+logR2);
f+=square(R1);
f+=square(R2);
for (int i=1;i<=20;i++)
{
xx(i)=i*R1;
}
GLOBALS_SECTION
#include <admodel.h>
class likeprof_vector
{
int index_min;
int index_max;
param_likeprof_number * v;
public:
int indexmin(){ return index_min;}
int indexmax(){ return index_max;}
param_likeprof_number& operator () (int i) {return v[i];}
likeprof_vector(int lb,int ub,const char * la)
{
index_min=lb;
index_max=ub;
v=new param_likeprof_number[index_max-index_min+1];
v-=index_min;
for (int i=index_min;i<=index_max;i++)
{
adstring label=la + adstring("_") + str(i);
(*this)(i).allocate(label);
}
}
~likeprof_vector()
{
v+=index_min;
delete [] v;
v=0;
}
};
51,1 Bot
----------------------------------------
Hi,
Thanks for this quick response and the worked out example. Indeed I had to move around two lines in the admodel.h file to make them public members of a class. Also, I had to remove the " // vector of 20" comment. I did not change the newmodmn.cpp file. It runs, but I have some questions about its behaviour.
I tried this on both my own code and the example provided above, and I get the same results (using ADMB 9.0). First, whenever I add the
!! likeprof_vector xx(1,20,"my")
likeprof_numbers
part to the model, ADMB warns that the covariance matrix may not be pos definite, while without that code, I do not get a warning. The warning is followed by a vector with the length of the estimated parameters. The estimation did not change (in terms of estimated parameters, starting values, data), so why do I get a warning that I did not have previously?
If I run the model with the -lprof flag, both the example and my own code end with
"Error standard dev of likeprof parameter is 0
xdist(0,-8) too small"
I get two files in the directory, one called "s.plt" with only "s:" in it, and one file ending in .prf with
s:
0
123456 345678 (these numbers being different for the example and my own code)
What I am doing wrong?
Kind regards, Jan Jaap
More information about the Users
mailing list