GAUSS T U T O R I A L

Similar documents
Introduction to MATLAB

Session 6 Gauss Procedures page

Introduction to Matlab

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin

x = 12 x = 12 1x = 16

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

Matlab- Command Window Operations, Scalars and Arrays

Introduction to MatLab. Introduction to MatLab K. Craig 1

Polymath 6. Overview

SF1901 Probability Theory and Statistics: Autumn 2016 Lab 0 for TCOMK

ECE Lesson Plan - Class 1 Fall, 2001

Introduction to MATLAB

Laboratory 1 Octave Tutorial

Introduction to Matlab. By: Hossein Hamooni Fall 2014

18.02 Multivariable Calculus Fall 2007

MATLAB GUIDE UMD PHYS375 FALL 2010

Sharp EL-9900 Graphing Calculator

Dr. Barbara Morgan Quantitative Methods

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

OVERVIEW DISPLAYING NUMBERS IN SCIENTIFIC NOTATION ENTERING NUMBERS IN SCIENTIFIC NOTATION

INTRODUCTION TO MATLAB

1. What specialist uses information obtained from bones to help police solve crimes?

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

Introduction to Matlab

A Guide to Using Some Basic MATLAB Functions

STRAT. A Program for Analyzing Statistical Strategic Models. Version 1.4. Curtis S. Signorino Department of Political Science University of Rochester

% Close all figure windows % Start figure window

A = [1, 6; 78, 9] Note: everything is case-sensitive, so a and A are different. One enters the above matrix as

Programming in Mathematics. Mili I. Shah

PC-MATLAB PRIMER. This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens.

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

Writing MATLAB Programs

Matlab Tutorial: Basics

Chapter 1 Introduction to MATLAB

,!7IA3C1-cjfcei!:t;K;k;K;k ISBN Graphing Calculator Reference Card. Addison-Wesley s. Basics. Created in conjuction with

Introduction to MATLAB LAB 1

AMS 27L LAB #2 Winter 2009

EXCEL 98 TUTORIAL Chemistry C2407 fall 1998 Andy Eng, Columbia University 1998

1 Introduction to Matlab

AEMLog Users Guide. Version 1.01

Summer 2009 REU: Introduction to Matlab

hp calculators hp 39g+ & hp 39g/40g Using Matrices How are matrices stored? How do I solve a system of equations? Quick and easy roots of a polynomial

MATLAB Project: Getting Started with MATLAB


Introduction to MATLAB

MATLAB SUMMARY FOR MATH2070/2970

Matlab Tutorial 1: Working with variables, arrays, and plotting

Teaching Manual Math 2131

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu

MATLAB GUIDE UMD PHYS401 SPRING 2011

Introduction to Stata: An In-class Tutorial

Graphing Calculator Tutorial

Finding MATLAB on CAEDM Computers

Exercise: Graphing and Least Squares Fitting in Quattro Pro

Lecture 2. Arrays. 1 Introduction

Applied Regression Modeling: A Business Approach

Introduction to PartSim and Matlab

Matlab Tutorial. Get familiar with MATLAB by using tutorials and demos found in MATLAB. You can click Start MATLAB Demos to start the help screen.

A Short Introduction to Matlab

3. Replace any row by the sum of that row and a constant multiple of any other row.

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

Introduction to Matlab

Lecture 2: Variables, Vectors and Matrices in MATLAB

Lab 2: OLS regression

Colorado State University Department of Mechanical Engineering. MECH Laboratory Exercise #1 Introduction to MATLAB

Mathematics 4330/5344 #1 Matlab and Numerical Approximation

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

Mathematics 308 Geometry. Chapter 9. Drawing three dimensional objects

On Your Own. ). Another way is to multiply the. ), and the image. Applications. Unit 3 _ _

MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED. Christian Daude 1

MATH 51: MATLAB HOMEWORK 3

Computational Photonics, Seminar 01 on Introduction into MATLAB, Page 1

FreeMat Tutorial. 3x + 4y 2z = 5 2x 5y + z = 8 x x + 3y = -1 xx

Unix Computer To open MATLAB on a Unix computer, click on K-Menu >> Caedm Local Apps >> MATLAB.

MATLAB Basics. Mohamed Taha. Communication Engineering Department Princess Sumaya University Page 1 of 32. Full Screen.

Computer Problem Sheet 1: Introduction to Matlab

Course Number 432/433 Title Algebra II (A & B) H Grade # of Days 120

Introduction to Scientific Computing with Matlab

CS1114: Matlab Introduction

Maple Quick Start. Maplesoft, a division of Waterloo Maple Inc.

Introduction to MATLAB

AN INTRODUCTION TO MATLAB

Matrices. Chapter Matrix A Mathematical Definition Matrix Dimensions and Notation

Matlab (Matrix laboratory) is an interactive software system for numerical computations and graphics.

Classroom Tips and Techniques: Least-Squares Fits. Robert J. Lopez Emeritus Professor of Mathematics and Maple Fellow Maplesoft

Introduction to MATLAB Programming

College Algebra Exam File - Fall Test #1

Matlab Introduction. Scalar Variables and Arithmetic Operators

Nuts & Bolts guide to MATLAB

WEEK 4 REVIEW. Graphing Systems of Linear Inequalities (3.1)

Scilab Programming. The open source platform for numerical computation. Satish Annigeri Ph.D.

Here is a quick introduction to Matlab and a couple of its symbolic and control functions.

1 Introduction to MATLAB

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd

Learning from Data Introduction to Matlab

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

An SM tutorial for programming and plotting

FACULTY OF ENGINEERING LAB SHEET INFORMATION THEORY AND ERROR CODING ETM 2126 ETN2126 TRIMESTER 2 (2011/2012)

Excel Primer CH141 Fall, 2017

Transcription:

Social Science Research Lab American University Washington, D.C. http://www.american.edu/ssrl 202.885.3862 GAUSS T U T O R I A L GAUSS is a powerful matrix-oriented computer programming environment. It is a programming language designed for matrix-based operations and manipulations, suitable for high level statistical and econometric computations. Here are some very important tips for GAUSS users: Each line of code must end with a semi-colon, ";" GAUSS environment is case insensitive. Typing variable names in uppercase, lowercase or a combination of both does not matter. That is, character "A" is the same as "a" A GAUSS program must start with the statement new; A GAUSS program must end with the statement end; Any comment used in programs should be bounded either by /*comment*/ or @comment@ characters The ORDER of commands sometimes makes a great difference in how GAUSS processes data GAUSS Windows - GAUSS uses six types of windows: a Command window, an Edit window, an Output window, a Debug window, a Matrix Editor window, and an HTML-based Help window Command Window - You enter interactive commands in the Command window. This window can be selected from the Windows Menu or from the Status bar. Edit Window - An Edit window is created when you open a file. When you execute GAUSS from an Edit window, the entire file is executed. This is the equivalent of the GAUSS "run filename" statement. Output Window - Output is written to the Output window. GAUSS commands cannot be executed from this window. 1.1 Creating Programs Gauss can be used interactively OR in the EDIT MODE. It is recommended that you use the EDIT MODE to create your program and run the entire program. If you wish to use the program interactively, then you just enter commands at the Gauss prompt. But if you wish to create a batch (program) file you must enter the following command in order to go into the EDIT mode: EDIT DRIVE:FILENAME where FILENAME refers to the name of the file into which the program is to be stored, and DRIVE refers to the drive containing the computer disk. Therefore, if the disk is in drive A and the file name is CP1.PRG, then write the command as: EDIT A:CP1.PRG If the file already exists it will be displayed ready to be edited. But if the file does not exist, then the new file can be created using a normal editing commands on the blank screen under NEW. Generating/Imputing Data All variables in Gauss are treated as matrices. This means that all operations must adhere to the rules of matrix algebra. Suppose we have three data points for three variables X, Y, and Z. Then we can define the

matrix W containing this data in three different ways: 1) W={1 4 7, 3 5 9, 2 3 7}; 2) let W[3,3]=1 4 7 3 5 9 2 3 7; 3) let W=1~4~7~3~5~9~2~3~7; The matrix W has dimensions (3 x 3). Suppose that all the data for variable X is located in the first row, all of Y's in row 2, and all of Z's in row 3. The variables X, Y, and Z can be defined in the following way: X = W[1,.]; Y = W[2,.]; Z = W[3,.]; This says that the values of the variables X, Y, and Z are in rows one, two, and three, respectively. Example One of the most frequently used operations in GAUSS is Matrix multiplication Suppose we are asked to multiply the following two matrices: 1 2 3 1 4 7 A = 4 5 6 B = 3 5 9 7 8 9 2 3 7 new; let A[3,3]=1 2 3 4 5 6 7 8 9; let B[3,3]=1 4 7 3 5 9 2 3 7; C=A*B; Print C; end; Save and run the program. The following will appear on the output table: 13.000000 23.000000 46.000000 31.000000 59.000000 115.00000 49.000000 95.000000 184.00000 To remove the zeros add: format /ld 7,0; before the end; command Reading Data Data can be read into the Gauss program from either within the Gauss Program file itself or by using an external ASCII file containing the data. If the data for matrix W was present in an ASCII text file (called A:MYFILE.DAT) in the following form: 1 4 7 3 5 9 2 3 7 Then, the information could be read into Gauss using the LOAD command: LOAD W[3,3] = A:MYFILE.DAT; Data Transformation To repeat, all variables defined in Gauss are treated as matrices. Even a variable containing a single value (a scalar) is defined as a (1 x 1) matrix. This means that operations can only be performed if matrices are conformable, and if they satisfy the conditions set by the theory of matrices. For example, two matrices can be summed only if they have the same dimensions. And, obviously, only nonsingular matrices can be inverted. Some most frequently used operations: 2

A = X + Y; A is the sum of X and Y A = X+Y[2,.]; A is the sum of X and row 2 of Y A = X - Y; A is the difference of X and Y A = X[.,1]-Y; A is the difference of the first of X and Y A = X * Y; A is the product of X and Y A = X'Y; A is the product of X transpose and Y A = X[1,.]*Y; A is the product of the first row of X and Y. A = B'; A is the transpose of B. Y = X!; This computes the factorial of every element in the matrix X. Procedures Sometimes we are given large computing tasks for which it is difficult to write programs as a whole. We need to use procedures to separate large tasks into collection of smaller tasks by using specific codes repeatedly. Any procedure should contain the following parts: 1. Procedure declaration done by GAUSS command proc 2. Local variable declaration done by GAUSS command local Note: WE should distinguish local variables from global variables. Variables that do not affect other parts of the program are considered to be local 3. Body procedure describe smaller tasks that will be repeated, we call this looping 4. Return from procedure - by GAUSS command retp we want the smaller task to repeat as many times as needed to complete the main task 5. End of procedure we require the procedure to end by GAUSS command endp Note: GAUSS procedures are recursive, so that it can repeat as long as there is a logic to prevent from infinite recursion Example Suppose we are asked to calculate the n th power of any square matrix. We need to use a procedure since taking n th power of matrix is a multiple task to be performed. The following is an example of the syntax used to define this procedure: proc(1)=pow(a,n); local xn; xn=a; for ctr(2,n,1); A=xn*A; endfor; retp(a); endp; Graphics /*declares the procedure-we can give any name to procedure*/ /*the local variable is the matrix A*/ /*start looping-start taking power of matrix A for n times*/ /*note: start from 2 b/c we have already assign A to local variable xn*/ /*the loop end here*/ /*return to the procedure*/ Gauss is capable of making complex graphs and can create a variety of Graph types. Each of them has a distinct pre-defined procedure name and hence must be called up as one. Following is the list of graph types that Gauss can create and the procedure names associated with each: 3

BAR BOX CONTOUR DRAW HIST HISTF HISTP LOGLOG LOGX LOGY POLAR SURFACE XY XYZ Generate bar graph Graph data using box graph percentile method Graph contour data Supply additional graphic elements to graphs Compute and graph frequency histogram Graph histogram given vector of frequencies Graph percent frequency histogram of a vector Scatter plot with logarithmic X and Y axes Scatter plot with logarithmic X axis Scatter plot with logarithmic Y axis Polar plots Graph 3-D surface Scatter plot Graph 3-D scatter plot Before we can create a Graph in Gauss, we need to invoke the Graphics Library by using the command library pgraph;. Also all data (or matrices/vectors) that are used in the graph generation must be defined before using them. Once these pre-requisites are met, the graphing procedure can be called up with the required syntax. Example Plot the graph of the following function: y=x^2 (x to the power of 2) library pgraph; fn parabola(x)=x^2; /*let domain be (-2,2) and let applied range be (-4,0)*/ d=seqa(.2,.01,401); /*divide entire range into small units,.01 is the size of increment*/ xy(d, parabola(d)); /*U-shaped parabola with minima at the origin (0,0)*/ Statistical Analysis Using Gauss Procedures Below is an example of a multivariate regression where the dependent variable is a 100 by 1 uniform random variable, and the independent variables are from a 100 by 5 matrix of normal random numbers: new; x = rndn(100,5); y = rndu(100,1); call ols("",y,x); end; We can run this either interactively by simply typing these commands in Gauss, or non-interactively by entering these commands in a command file and then executing them. Below is the descriptive statistics that will appear on the output window: Valid cases: 100 Dependent variable: Y Missing cases: 0 Deletion method: None Total SS: 8.460 Degrees of freedom: 94 R-squared: 0.032 Rbar-squared: -0.019 Residual SS: 8.187 Std error of est: 0.295 F(5,94): 0.627 Probability of F: 0.679 Standard Prob Standardized Cor with Variable Estimate Error t-value > t Estimate Dep Var ------------------------------------------------------------------------------- CONSTANT 0.481277 0.030025 16.029103 0.000 --- --- X1 0.002540 0.029176 0.087042 0.931 0.008989 0.005182 4

X2-0.026961 0.031554-0.854458 0.395-0.088646-0.072611 X3 0.044416 0.033791 1.314448 0.192 0.138098 0.144467 X4 0.021887 0.029694 0.737095 0.463 0.077260 0.079122 X5-0.002981 0.031551-0.094486 0.925-0.009913 0.025793 Saving and Printing Results It is good programming practice, and often necessary, to save the output of a program onto a file. In order to accomplish this in GAUSS, use the command : output file=capture.out [reset][on]; All the output that appears on the screen after this line is written in the text file capture.out. The command reset erases all previous content in the file. The command on appends to the file. To close the file, use output off Note: files must be closed before they can be printed or edited. A closed file can be re-opened with output on. The file capture.out is in ASCII format and can be viewed and printed with any text editor. How To Use Help On Gauss Getting general help for Gauss is obtained by pressing ALT-H, then typing? will give you the index of help, you can keep pressing pagedown keypad till you see the information you need. Typing?? will give you list of all the operators in Gauss, tpye h and it will ask for the name of operator, put in the name of the operator and it will show the detail information on the operator. The help system also includes context sensitive help while in all of the pop-up menus and input screen. THE END 5