Goals
After this tutorial, you should be able to
- Run interactive commands in GAUSS.
- Create matrices and vectors.
- Create strings.
- View workspace variables.
- Print numeric and string output.
- Index matrices.
- Call functions.
- Configure the GAUSS user interface.
- Run example programs.
- Get help on a function.
Interactive commands
Open GAUSS and click on the Command tab on the left side of the GAUSS user interface. This will take you to the Command Mode, which contains:
- The Command History window, which keeps track of your recent GAUSS commands.
- The Program Input/Output window where you can enter interactive commands and see the output from interactive commands and programs.
Let's start with a simple calculation of the Body Mass Index (BMI). The formula for BMI is
$$BMI = weight / height^2$$
For a person who weighs 81.6 kg and is 1.75 m tall, we would enter the command as shown in the image above.
Matrix and vector creation
Most of the time in GAUSS, you will be working with matrices and vectors. Matrices and vectors are created by placing a list of numbers inside of curly braces {}
with commas separating the rows.
// Create two, 3x1 vectors
weight = { 81.6, 72.5, 78.2 };
height = { 1.75, 1.82, 1.55 };
Then we use the dot operators to perform element-by-element operations on the vectors.
// Use 'dot' operators to perform element-by-element operations
bmi = weight ./ height .^ 2;
After the code above, bmi
equals
26.644898 21.887453 32.549428
String creation
Strings are GAUSS variables that contain characters. String data is declared inside of double-quotes, "
.
// Create a string
my_string = "This is my first string!";
Workspace variables
All data created in GAUSS are considered Workspace Variables. You can view the data in your GAUSS workspace by clicking on the Data tab on the left side of the GAUSS interface.
Double‐click the name of a variable, to view its entire contents.
Clearing the workspace
The new
command will remove all variables from your GAUSS workspace.
// Remove all workspace variables
new;
Print statements
- The
print
keyword in GAUSS takes a space‐separated list of items to print. - Expressions should be surrounded by parentheses.
mass = 12;
acceleration = 2.5;
force = mass * acceleration;
// Print a string and a workspace variable
print "Force = " force;
// Print a string and an expression
print "Force = " (mass * acceleration);
Both of the above print statements will produce the output below.
Force = 30.0000
Implicit print statements.
The print
keyword is not strictly required. For example:
mass = 4;
// Entering a workspace variable
// name alone is an implicit 'print'
mass;
will return the output:
4.00000
Clearing printed output
You can remove all printed output with the cls
command. cls
stands for 'clear screen'.
// Clear the program input/output window
cls;
Calling functions
GAUSS has more than 1000 built‐in functions.
- Inputs to GAUSS functions or procedures are passed inside of parentheses.
- Return values are always on the left side of the equals sign.
// Declare a 2x2 matrix
prices = { 100 50,
90 25 };
// Compute the mean of each column
price_bar = meanc(prices);
// Compute the max of each column
price_max = maxc(prices);
will make the following assignments:
price_bar = 95 37.5 price_max = 100 50
Indexing
GAUSS uses square brackets []
for indexing. For example:
// Declare a 3x2 matrix
A = { 21 33,
14 19,
25 18 };
// Assign 'B' to equal the element
// from the 2nd row of the first
// column of 'A'
B = A[2,1];
will assign B
equal to
14
The colon operator :
indicates a range. For example:
// Assign 'B' to equal the first two elements
// from the 2nd column of 'A'
B = A[1:2,2];
will assign B
equal to
33 19
Configure the GAUSS User Interface
We will now move to the GAUSS Edit Mode. The Edit Mode is where you will likely spend most of your time in GAUSS. It allows you to:
- Open, edit and run GAUSS program files.
- Keep track of different folders and libraries.
Click the Edit tab on the left side of the GAUSS user interface to go to the Edit Mode.
Customize widget locations
To relocate a GAUSS widget (or window):
- Grab the title bar of the widget with your mouse and drag it to your desired location.
- When the window is over a valid location, a drawer will open indicating the landing place for the widget.
- Let go of your mouse and the widget will be dropped into the new location as shown below.
Open widgets
All available widgets may be opened from the GAUSS View menu as shown below. Note that each GAUSS Mode (Command, Edit, Data, Debug, Graphics and Help) will have different widgets available.
Run example programs
The example programs that come with GAUSS are located in GAUSSHOME/examples, where GAUSSHOME is your GAUSS installation directory. To make it easy to browse the example files, we will open our GAUSSHOME directory in the project folders window.
Open a project folder
The Project Folder window allows you to view the contents of any folder on your computer. You can open a particular folder by either:
- Right-clicking in the Project Folder Window and selecting Add Folder.
- Selecting File > Open Project Folder from the main GAUSS menu.
Next, an operating system file explorer will open. Browse to your GAUSS installation location and open the folder. Once this is accomplished, expand the GAUSS installation folder and examples folders nodes. You should now see the list of GAUSS example files and datasets as shown below.
All of the GAUSS example programs end with the file extension .e
.
- Scroll down and locate the example
glmbinomial1.e
. - Double‐click its name in the list to open the file.
- To run this example file:
- Click the downward pointing arrow just to the right of the Run button on the GAUSS toolbar.
- Select Current File as shown below.
You should now see the output from the generalized linear model estimation printed in the GAUSS program input/output window as in the image above.
Get help on a function
You can get help on GAUSS functions by highlighting the name of the function with your mouse, right‐clicking and selecting Help on Selected Text from the context menu.
If you do this for the function, glm
, as shown in the above image, you will find information about the inputs and outputs of the function as well as 10 different examples.