[ADMB Users] string identifier error in ADMB-RE

Charlotte Boyd boydchar at u.washington.edu
Thu Jan 7 15:26:40 PST 2010


Hi

I've been working on adding random effects to a model that I developed in
ADMB. In ADMB-RE, I frequently (but not always) get the error message:

'Error in string identifer in list value should be UZ it appears to be
...' during the Newton Raphson 2 phase. 

So far, I've failed to identify the cause of the error, and would really
appreciate some suggestions. 

The full model is a hidden Markov model (designed to partition animal
movement tracks into movement modes), solved with a forwards-backwards
algorithm. 
I started with a relatively simple version of the model (forwards only, 12
estimated parameters, 6 random effects, standard deviation on random effects
fixed) and a simulated dataset. I can run this version successfully on some
datasets, but the error message occurs with others. In general, more complex
versions of the model (e.g. 16 estimated parameters) are more likely to
produce the error, but occasionally the more complex model runs to
completion while the simpler version fails. Models without the 'if'
statement also tend to fail at the same point with the same error message.
(All datasets are simulated according to the same parameters. Some have 8
trips with 1,000 observations each, others 32 trips with 1,000 observations
each. The larger datasets are more likely to fail.) Sometimes a coding
change appears to resolve the problem, but it inevitably returns as I free
up more parameters.

I've pasted the complete code below. This version works on some datasets but
not on others. I'm fairly new to ADMB, so I'm sure there are many ways in
which the code could be tightened up or made more efficient, but resolving
the string identifier error seems to be key. If there is any additional
information that would be useful, please let me know. 

With many thanks in advance for your help.

Charlotte Boyd 

School of Aquatic and Fishery Sciences
University of Washington
1122 NE Boat St, Rm 116
Seattle, WA 98105

TOP_OF_MAIN_SECTION

  arrmblsize=20000000; 

DATA_SECTION
  
  init_int Nobs; // number of observations
  init_int Ntrips; // number of trips
  init_int Ntripobs; // number of observations per trip
  init_matrix Obs(1,Nobs,1,4); 
  
  vector treatment(1,Nobs); 
  vector trip(1,Nobs); 
  vector distt(1,Nobs); 
  vector theta(1,Nobs); 
  
  !!treatment = column(Obs,1); 
  !!trip = column(Obs,2); 
  !!distt = column(Obs,3); 
  !!theta = column(Obs,4);
  
  number pi;
  
  //stdevs on random effects - fixed in this version
  number sigma_scale2;
  number sigma_shape2;
  number sigma_rho2;  
  number sigma_scale3;
  number sigma_shape3;
  number sigma_rho3;
  
  //transition parameters - fixed in this version
  number pswitch11;
  number pswitch12;
  number pswitch13;
  number pswitch21;
  number pswitch22;
  number pswitch23;
  number pswitch31;
  number pswitch32;
  number pswitch33;
   
  !! cout<<"done reading data"<<endl; // indicates data has been read in

INITIALIZATION_SECTION

  //global parameters for weibull on distance and wrapped cauchy on turning
angle
  input_mode2_scale -2.3
  input_mode2_shape -0.22
  input_mode2_rho -0.32
  input_mode3_scale -0.22
  input_mode3_shape 1.61
  input_mode3_rho 2.4
  
  //treatment effects
  mode2_scale_treat 0.69
  mode2_shape_treat 0
  mode2_rho_treat 0.5
  mode3_scale_treat 0.41
  mode3_shape_treat 0.18
  mode3_rho_treat 0.69
     
PARAMETER_SECTION
  
  init_number input_mode2_scale(1); //global parameters
  init_number input_mode2_shape(1); 
  init_number input_mode2_rho(1);
  init_number input_mode3_scale(1);
  init_number input_mode3_shape(1);
  init_number input_mode3_rho(1);
  
  init_number mode2_scale_treat(1); //treatment effects
  init_number mode2_shape_treat(1); 
  init_number mode2_rho_treat(1);
  init_number mode3_scale_treat(1);
  init_number mode3_shape_treat(1);
  init_number mode3_rho_treat(1);
  
  random_effects_matrix u(1,Ntrips,1,6,2); // matrix of unscaled random
effects: re=sigma_re*u where u~N(0,1)
  
  objective_function_value obj_fun;
  
PROCEDURE_SECTION
 
  int t, obs; //counters for trip and all observations
  obs=0; 
  
  obj_fun=0; //resets objective function
  
  // loop over trips  
  for (t=1;t<=Ntrips;t++)
    	fit_trip(input_mode2_scale, input_mode2_shape, input_mode2_rho,
input_mode3_scale, input_mode3_shape, input_mode3_rho, mode2_scale_treat,
mode2_shape_treat, mode2_rho_treat, mode3_scale_treat, mode3_shape_treat,
mode3_rho_treat, u(t), t, obs); 

SEPARABLE_FUNCTION void fit_trip(const dvariable& input_mode2_scale, const
dvariable& input_mode2_shape, const dvariable& input_mode2_rho, const
dvariable& input_mode3_scale, const dvariable& input_mode3_shape, const
dvariable& input_mode3_rho, const dvariable& mode2_scale_treat, const
dvariable& mode2_shape_treat, const dvariable& mode2_rho_treat, const
dvariable& mode3_scale_treat, const dvariable& mode3_shape_treat, const
dvariable& mode3_rho_treat, const dvar_vector& ut, const int& t, int obs) 
  
  obs = (t-1)*Ntripobs; //sets obs for beginning of each trip

  int i; // loop counter
  
  pi = 3.141593; //specifies pi
  
  sigma_scale2=0.01;
  sigma_shape2=0.01;
  sigma_rho2 = 0.01;
  sigma_scale3=0.01;
  sigma_shape3=0.1;
  sigma_rho3 = 0.001;
  
  dvar_vector priorfor_mode1(1,Nobs);
  dvar_vector priorfor_mode2(1,Nobs); 
  dvar_vector priorfor_mode3(1,Nobs);
  
  dvar_vector likefor_mode1(1,Nobs); 
  dvar_vector likefor_mode2(1,Nobs); 
  dvar_vector likefor_mode3(1,Nobs);
  
  dvar_vector probfor_mode1(1,Nobs);
  dvar_vector probfor_mode2(1,Nobs); 
  dvar_vector probfor_mode3(1,Nobs);
  
  obj_fun-=(-0.5*norm2(ut)); // likelihood contribution from unscaled random
effects based on the prior ~N(0,1)
 
  //scale & shape passed thro log filter, rho thro arctan filter 
  dvariable
mode2_scale=mfexp(input_mode2_scale+(treatment(obs+1)*mode2_scale_treat))+(s
igma_scale2*ut(1));
  dvariable
mode2_shape=mfexp(input_mode2_shape+(treatment(obs+1)*mode2_shape_treat))+(s
igma_shape2*ut(2));
  dvariable
mode2_rho=(0.5+atan(input_mode2_rho+(treatment(obs+1)*mode2_rho_treat))/pi)+
(sigma_rho2*ut(3));
  dvariable
mode3_scale=mfexp(input_mode3_scale+(treatment(obs+1)*mode3_scale_treat))+(s
igma_scale3*ut(4));
  dvariable
mode3_shape=mfexp(input_mode3_shape+(treatment(obs+1)*mode3_shape_treat))+(s
igma_shape3*ut(5));
  dvariable
mode3_rho=(0.5+atan(input_mode3_rho+(treatment(obs+1)*mode3_rho_treat))/pi)+
(sigma_rho3*ut(6));

  pswitch11= 0.1 + (treatment(obs+1)*(-0.05)); 
  pswitch12= 0.6 + (treatment(obs+1)*0.1); 
  pswitch13= 1 - pswitch11 - pswitch12;
  pswitch21= 0.03 + (treatment(obs+1)*0.02); 
  pswitch22= 0.9 + (treatment(obs+1)*(-0.1)); 
  pswitch23= 1 - pswitch21 - pswitch22;
  pswitch31= 0.05 + (treatment(obs+1)*0); 
  pswitch32= 0.1 + (treatment(obs+1)*(-0.05)); 
  pswitch33= 1 - pswitch31 - pswitch32;
  
  //first obs'n does not contribute to the likelihood, but contributes to
priors for second obs'n
  probfor_mode1(obs+1)=0;
  probfor_mode2(obs+1)=0.5;
  probfor_mode3(obs+1)=0.5;
  
  for (i=obs+2;i<=obs+Ntripobs-1;i++)
  {
       	if (theta(i)==0)
        {
    	probfor_mode1(i)=1; //obs'ns with incomplete movement data
automatically assigned to mode1; do not contribute to likelihood, but
contribute to priors for subsequent obs'ns
    	probfor_mode2(i)=0;
    	probfor_mode3(i)=0;
        } else
	{    
     	priorfor_mode2(i)=(probfor_mode1(i-1)*pswitch12) +
(probfor_mode2(i-1)*pswitch22) + (probfor_mode3(i-1)*pswitch32);
        priorfor_mode3(i)=(probfor_mode1(i-1)*pswitch12) +
(probfor_mode2(i-1)*pswitch23) + (probfor_mode3(i-1)*pswitch33);
  
 
likefor_mode2(i)=(mode2_shape/mode2_scale)*(pow(distt(i)/mode2_scale,
mode2_shape-1)*mfexp(-1*pow(distt(i)/mode2_scale,mode2_shape))) *
(1/(2*pi))*(1-pow(mode2_rho,2))/(1+pow(mode2_rho,2)-(2*mode2_rho*cos(theta(i
))))*priorfor_mode2(i);  // likelihood for each observation under mode 2
 
likefor_mode3(i)=(mode3_shape/mode3_scale)*(pow(distt(i)/mode3_scale,
mode3_shape-1)*mfexp(-1*pow(distt(i)/mode3_scale,mode3_shape))) *
(1/(2*pi))*(1-pow(mode3_rho,2))/(1+pow(mode3_rho,2)-(2*mode3_rho*cos(theta(i
))))*priorfor_mode3(i);
        
        probfor_mode1(i)=0;
        probfor_mode2(i)=likefor_mode2(i)/(likefor_mode2(i) +
likefor_mode3(i));
        probfor_mode3(i)=likefor_mode3(i)/(likefor_mode2(i) +
likefor_mode3(i));
        
        obj_fun-= log(likefor_mode2(i) + likefor_mode3(i)); 
        }  
  }
        	   


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.admb-project.org/pipermail/users/attachments/20100107/b9927368/attachment.html>


More information about the Users mailing list