Hi,
I have a problem with the Constrained Maximum Likelihood Estimation.
As I am trying to conduct an analysis I get an error in the end of my code, depending on my modifications I get the errors:
G0181: Illegal assigment - type mismatch [cmlmt.src]
G0003: Indexing a matrix as a vector
G0058: Index out of range
When I look at my "Data" tab on the left I see the set I uploaded, but as soon as I click on "d0" which is my DS - I see nothing so I suspect the problem to be there.
Can you explain me how to set up a proper DS structure with a .txt file?
Best regards
1 Answer
0
accepted
When using CMLMT, the DS structure is used to pass data other than the model parameters to your likelihood function. The example file cmlmtarch.e has an example that loads ASCII text data into the DS structure. The statement in that file is a little complicated, because it calculates lags and then removes missing values. If you just wanted to load all the values in the file aoi.asc into one vector that you add to a DS structure, you would do it like this:
//Declare 'ds_data' to be an instance of a DS structure struct DS ds_data; //Fill in default DS structure values ds_data = dsCreate(); //Load the data into a GAUSS global variable load z[]=aoi.asc; //Assign the 'dataMatrix' member of 'ds_data' to hold //the vector in 'z' ds_data.dataMatrix = z;
Then if you need want to access this data inside your likelihood procedure, you could do it like this:
proc (1) = myLikelihood(struct PV p, struct DS d); local my_var; //assign vector from loaded from 'aoi.asc' to 'my_var' my_var = d.dataMatrix;
If you don't need any data other than your parameters in your model, then you can just pass in the dsCreate() function to your call to CMLMT. This works because, dsCreate() returns a DS structure.
Finally, here is an example that will: 1) create some data 2) save it to a .txt file 3) load and assign it to the dataMatrix member of a DS structure.
//Create the sequence 1,2,3...100 as a column vector x = seqa(1, 1, 100); //Set print output to the file 'mydatafile.txt' output file=mydatafile.txt reset; //Print the contents of 'x' to the screen and 'mydatafile.txt' print x; //Stop output from going to 'mydatafile.txt' output off; //Load the column vector from 'mydatafile.txt' load my_vec[]=mydatafile.txt; //Declare DS structure instance and fill in defaults struct DS my_ds; my_ds = dsCreate(); //Assign column vector to 'dataMatrix' member of 'my_ds' my_ds.dataMatrix = my_vec;
I am not sure if that answers all of your questions, but it should be a good start. Feel free to post any further questions.
Your Answer
1 Answer
When using CMLMT, the DS structure is used to pass data other than the model parameters to your likelihood function. The example file cmlmtarch.e has an example that loads ASCII text data into the DS structure. The statement in that file is a little complicated, because it calculates lags and then removes missing values. If you just wanted to load all the values in the file aoi.asc into one vector that you add to a DS structure, you would do it like this:
//Declare 'ds_data' to be an instance of a DS structure struct DS ds_data; //Fill in default DS structure values ds_data = dsCreate(); //Load the data into a GAUSS global variable load z[]=aoi.asc; //Assign the 'dataMatrix' member of 'ds_data' to hold //the vector in 'z' ds_data.dataMatrix = z;
Then if you need want to access this data inside your likelihood procedure, you could do it like this:
proc (1) = myLikelihood(struct PV p, struct DS d); local my_var; //assign vector from loaded from 'aoi.asc' to 'my_var' my_var = d.dataMatrix;
If you don't need any data other than your parameters in your model, then you can just pass in the dsCreate() function to your call to CMLMT. This works because, dsCreate() returns a DS structure.
Finally, here is an example that will: 1) create some data 2) save it to a .txt file 3) load and assign it to the dataMatrix member of a DS structure.
//Create the sequence 1,2,3...100 as a column vector x = seqa(1, 1, 100); //Set print output to the file 'mydatafile.txt' output file=mydatafile.txt reset; //Print the contents of 'x' to the screen and 'mydatafile.txt' print x; //Stop output from going to 'mydatafile.txt' output off; //Load the column vector from 'mydatafile.txt' load my_vec[]=mydatafile.txt; //Declare DS structure instance and fill in defaults struct DS my_ds; my_ds = dsCreate(); //Assign column vector to 'dataMatrix' member of 'my_ds' my_ds.dataMatrix = my_vec;
I am not sure if that answers all of your questions, but it should be a good start. Feel free to post any further questions.