### Aptech Systems, Inc. Worldwide Headquarters

Address:

Aptech Systems, Inc.

2350 East Germann Road, Suite #21

Chandler, AZ 85286Phone: 360.886.7100

FAX: 360.886.8922**Ready to Get Started?**### Request Quote & Product Information

### Industry Solutions

### Products

### Resources

### Support

### Training & Events

Want more guidance while learning about the full functionality of GAUSS and its capabilities? Get in touch for in-person training or browse additional references below.

### Tutorials

Step-by-step, informative lessons for those who want to dive into GAUSS and achieve their goals, fast.

### What’s New in GAUSS 17

### Want to find out more?

### Have a Specific Question?

### Q&A: Register and Login

### Support Plans

Premier Support and Platinum Premier Support are annually renewable membership programs that provide you with important benefits including technical support, product maintenance, and substantial cost-saving features for your GAUSS System or the GAUSS Engine.

### User Forums

Join our community to see why our users are considered some of the most active and helpful in the industry!

### Where to Buy

Available across the globe, you can have access to GAUSS no matter where you are.

### Recent Tags

applications character vectors CML CMLMT Constrained Optimization datasets dates dlibrary dllcall econometrics Editor error error codes error handling errors Excel file i/o floating network GAUSS Engine GAUSS Light graphics GUI hotkeys installation license licensing linux loading data loop loops matrix manipulation Maximum Likelihood Maxlik MaxLikMT Memory multidimensional array optimization Optmum output PQG graphics procs random numbers strings structures threading### Recent Questions

- codes in 2016 and I cannot open them in 2017 version
- rows with selif
- How can I find the index of the largest element of a matrix
- Is there any function similar to rep in R?
- G0152 Variable not Initialized error message
- Does Gauss have similar function as " %in%" in R or "find" in matlab
- Shall I change from I7 6700K to Ryzen X1800
- inther procedure
- About precision of cdfMvn and multi-thread
- Axis fonts, LaTeX font in legend

### Features

### Time Series 2.0 MT

### Industry Solutions

### Find out more now

### Time Series MT 2.1

### Find out more now

### Find out more now

# Resources

# Plotting the likelihood function

Hi,

I am wondering how can I extract the information from the optmum command with respect to the likelihood function values during the optimization path.

In other words, I would like the value of the likelihood at each iteration of the optimization so that I can plot it.

Any help?

thanks!

Barbara

## 5 Answers

If you want to write just the value of the likelihood function to a file, you would need to add the `output` call to your likelihood procedure right after it is calculated, but before you return:

proc (1) = myLikelihood(b); //calculate likelihood current_likelihood = ... output file=likelihood_vector.txt on; print current_likelihood; output off; retp(current_likelihood); endp;

This, above, will append each value to the text file. However, you could alternatively assign this to a global vector which you could then print out later, like this:

//create empty matrix global_likelihood_vector = {}; //Settings and call to 'optmum' ... ... proc (1) = myLikelihood(x); local current_likelihood; //Calculate likelihood current_likelihood = ... //Concatenate current likelihood to vector //of all likelihoods global_likelihood_vector = global_likelihood_vector | current_likelihood; retp(current_likelihood); endp;

Assuming your objective function is computing -logL (it has to be minus because Optmum minimizes rather than maximizes the objective function), then

output file = thisrun.txt reset;

__output = 1;

.

.

// your call to optmum

.

.

output off;

the value of the objective function, -logL, will be printed to the output file, thisrun.txt as well as to the screen. It will be printed with a lot of other information so it might be hard to grab. You could copy and paste each line containing the function value at each iteration to another file. Or you could write a GAUSS program to read that file and collect the function values into another file. That's what I would do.

Thanks a lot!

Hi,

I did what you suggested, but I dont get anything new from what I already see in the command window when I am estimating. The only thing I get is a .txt file with all the iterations and the function value in each of them. But what I want is a vector with all those values so that I can plot them.

How can I get this?

Thanks again.

Barbara

Many many thanks!

## Your Answer

## 5 Answers

If you want to write just the value of the likelihood function to a file, you would need to add the `output` call to your likelihood procedure right after it is calculated, but before you return:

proc (1) = myLikelihood(b); //calculate likelihood current_likelihood = ... output file=likelihood_vector.txt on; print current_likelihood; output off; retp(current_likelihood); endp;

This, above, will append each value to the text file. However, you could alternatively assign this to a global vector which you could then print out later, like this:

//create empty matrix global_likelihood_vector = {}; //Settings and call to 'optmum' ... ... proc (1) = myLikelihood(x); local current_likelihood; //Calculate likelihood current_likelihood = ... //Concatenate current likelihood to vector //of all likelihoods global_likelihood_vector = global_likelihood_vector | current_likelihood; retp(current_likelihood); endp;

Assuming your objective function is computing -logL (it has to be minus because Optmum minimizes rather than maximizes the objective function), then

output file = thisrun.txt reset;

__output = 1;

.

.

// your call to optmum

.

.

output off;

the value of the objective function, -logL, will be printed to the output file, thisrun.txt as well as to the screen. It will be printed with a lot of other information so it might be hard to grab. You could copy and paste each line containing the function value at each iteration to another file. Or you could write a GAUSS program to read that file and collect the function values into another file. That's what I would do.

Thanks a lot!

Hi,

I did what you suggested, but I dont get anything new from what I already see in the command window when I am estimating. The only thing I get is a .txt file with all the iterations and the function value in each of them. But what I want is a vector with all those values so that I can plot them.

How can I get this?

Thanks again.

Barbara

Many many thanks!