oostatshelp: Introduction

Introduction

A very brief introduction is presented in this chapter, showing how to create a database from a set of variables in APL, and how statistical facilities can be created from within the database structure.


oostatshelp: The Context

The Context

Statistical analyses are performed on a rectangular database where each row represents a case and each column a variable. Variables may contain missing values, thus when a statistical procedure is applied, it is first necessary to choose only those cases which have no missing values in the variables to be used. For example, in a simple linear regression of variable weight on variable height, only those cases will be used for which both weight and height are simultaneously non-missing. This is no easy task using raw APL and much of the immediacy of APL is hindered by having to clean one’s data before performing any particular statistical task. Just how to do this using OOStats is the purpose of these help notes.

In this introduction we present a quick overview of some of the basic features of OOStats before embarking on a more detailed description. The basic ingredients discussed here are:-

  • Establishing a database
  • Creating a simple statistical object for that database
  • Saving and Opening a database
  • How to open a database from within a graphical user Interface


oostatshelp: Establishing a database object

Establishing a database object

The minimum needed to create a database structure is a vector of vectors (variables) all the same length and a nested vector of associated names. Generally speaking, variables should be numeric (with any descriptive information attached as value labels), but string entries in variables are allowed. Here is a simple example :-

 db←⎕new s_db (('alan' 'adrian')((1 2 3 4 )(2 1 3 5)))
      db.VarNames
 alan  adrian  _CSel  _CFreq
      db.GetVar 'alan'
1 2 3 4
      db._CSel
1 1 1 1
      db._CFreq
1 1 1 1

The variable _CSel is a system variable denoting the cases currently selected, and _CFreq, another system variable, is a non-negative integer variable denoting case frequency – both default to a vector of 1’s.

Note that db is used by default here – it could be another name.


oostatshelp: Creating a statistical object in the database

Creating a statistical object in the database

The database object created contains a large number of methods, many of which are concerned with database activities which will be described later. Statistical functionality is provided through statistical methods, each of which create a further statistical object with its own methods. This object will normally be db.s and will have methods of the form db.s.method.

If we wish to calculate the mean and standard deviation of the variable alan, then we can use the database method Unistats. In this case (when in the apl session) it makes sense for ths to create an apl object with the variable name:-

⎕←db.Unistats 'alan'
Created object #.alan.?
Currently, # cases excluded = 0

Now, two (amongst others) methods are available within alan

alan.Mean
2.5
      alan.StDev
1.29099

Note that in creating the object alan using the database method Unistats missing values, ithere were any, are filtered out.


oostatshelp: Saving and Opening a database

Saving and Opening a database

Having created a database, you may well want to save it for future reference or analysis or refinement.

db.Save 'silly'

This saves a component file representation of the database in the file silly.adb in the defaulty directory. The command:-

Open 'silly'.adb

will retrieve the database (currently) to a default-named database db.

Object 'db' has been created using s_db from file silly
      db.VarNames
 alan  adrian  _CSel  _CFreq

If you wish to browse through files, then

Open ''

will open the usual WIndows file-box.


oostatshelp: A Graphical User Interface

A Graphical User Interface

If the left argument of Open is 1, this opens the database via a gui-front end, which we will explore in detail in a subsequent chapter. Part of the screen is shown below – note the menu of statistical topics (n.b. the list is incomplete here).

This has the look and feel of a statistics package and is designed to make it easy to evaluate and compare different models and analyses for a particular dataset.

Note too, that the Open command may be used to create an empty database of the proscribed size

1 Open 10 2

This creates a database with 10 cases and two variables with default names var1 and var2. All values are zero by default but you can select Edit On from the Database menu and then type in values.


oostatshelp: Error Messages and Error Trapping

Error Messages and Error Trapping

There are two variables #.ErrorTrapOn and #.PrtError.Set #.ErrorTrapOn←1to trap Errors. This is the default setting when using the gui wrap, but may be changed using the [Errors] menu. It is probably advisable to use the same setting when using OOStats from the session, unless you are in developmental mode.

How error messages that are generated are treated depends on the setting of #.PrtError. With the setting #.PrtError←1, messages are sent to the Windows Error Message Box, irrespective of whether you are operating from the session or not. If #.PrtError←0, then at the session, error messages are printed to the session manager, whilst when using the gui wrap, the messages are sent to the rtfViewer.

Error messages are stored temporarily in #.EM and the function #.E checks the error message for the phrase 'Error:-' at the beginning:- if it is there, then the code →#.E/0 will cause a branch out of the executing function. This allows the programmer to check for potential errors before they occur – s et #.EM to the approrpriate string, and then use #.E accordingly. System error messages are stored in an APL conponent file – see the function #.Error which takes a positive integer as a right argument.

The function #.ETON sets error trapping on (depending on the state of #.Error. If an unexpected error occurs, then this kicks in as appropriate, so the user is not left high and dry when operating in the gui mode.

When using #.Explore to gain output from a statistical object, bespoke error trapping is used to ensure that methods which are error free are allowed to deliver results.


oostatshelp: Variable Names

Variable Names

As discussed in the previous section, the very least that is required to construct a database is to provide it with a set of vectors (of equal length) and a set of names to go with them. There is much more that needs to be considered before moving on to look at the statistical provisions. Throughout the discussion we will assume that the database object created is db.

db.VarNames is a vector of character vectors containing the names of all the variables. Each character vector can be anything. However it is preferable to avoid names which begin with ‘_’ as there are a number of system variables which are so indicated.

db.VarNames
 alan  adrian  _CSel  _CFreq

User variable names may be changed susbequently by using the database method db.Format.


oostatshelp: Database Variables

Database Variables

db.Vars is a nested vector of database vectors corresponding to the names

↑⍉db.Vars
1 2 3 4
2 1 3 5
1 1 1 1
1 1 1 1


oostatshelp: Viewing the Database

Viewing the Database

db.Mat is a matrix of formatted database vectors and system variables to enable the user to look at the database in a sensible way when operating from the APL session window. The first column of the matrix is the system variable _Cases which just lists the cases in order. (This is necessary if one wants to order the database whilst still being able to refer to the original case structure.)

db.Mat
1 1 2 1 1
2 2 1 1 1
3 3 3 1 1
4 4 5 1 1

In addition, the database may be viewed as a form:-

db.View


oostatshelp: Variable Labels

Variable Labels

db.VarLabels is a nested vector of character vectors that describe the database vectors. For example, the variale label corresponding to a database vector height might be 'height of student in cm'. Assigning variable labels can be done, with care, directly from APL as illustrated here:-

db.VarLabels[1]←⊂'This is alan''s variable'

Alternatively, labelling variables may be done through a simple form editor:-

db.GetVarLabels


oostatshelp: Value Labels

Value Labels

db.ValueLabels is a nested vector of matrices, one for each variable, each having two columns. Each first column is a set of values for that variable,and the associated elements in the second column are character vectors which explain the meaning of the values. For example, corresponding to a database variable sex containing values 1, 2 there might be a two column matrix, the first column being 1 2 and the second 'male' 'female'

If you wish to attach value labels for the first database vector, you may use a command such as

db.ValueLabels[1]←⊂4 2⍴1 'one' 2 'two' 3 'three' 4 'four'

Alternatively, this may be done through a grid-edit object

db.GetValueLabels

Note how the matrix for the first variable is entered in one line.


oostatshelp: Variable Types

Variable Types

db.VarType is a nested vector of types of variable in the database. Currently this facility is not used but may become important later on. Note however, that in constructing a database using the command ⎕new s_db,

you are asked whether any non-numeric values should be converted to missing values. Ideally all variables in a database should be numeric with associated strings recorded through a ValueLabels matrix.


oostatshelp: Missing Values

Missing Values

Associated with every database variable is a vector of missing values. At creation these are set by the command:-

MissVals←((⍴VarNames))⍴⊂'(⎕null)(⊂'''')(⊂⍬)('''')'

Other values may be included by the user either by a direct APL assignment or through the use of the method fdb.GetMissVals.

For example if for variable 1, the value 4 was to be regarded as ‘missing’ this may be added to the appropriate list of missing values for the first variable:-

db.GetMissVals

To see the effect of this, we create again, a univariate statistics object for the first variable and ask for the new mean:-

db.Unistats 'alan'
Created object #.alan.?
Currently, # cases excluded = 1
      alan.Mean
2

(This was to be expected, as the mean is taken only using the values 1,2,3 and not including the last value 4.)


oostatshelp: The Database Object - Methods

The Database Object – Methods

The most important database methods are presented in this section.


oostatshelp: Selecting Cases

Selecting Cases

Selecting Cases

Often we wish to work only on a subset of the data – this can be done in a straightforward manner by creating (in quotes) a boolean statement involving the database variables. For example:-

db.SelectCases '_Cases>2'
Cases selected according to expression _Cases>2
There are 2 cases not selected

If we view the database, the cases not included are shown in grey:-

Alternatively, we might wish to work only on cases where the variable adrian takes values less than 3:-

db.SelectCases 'adrian<3'

Any executable expression involving known variables resulting in a boolean vector is appropriate.

Note that there is no attempt to create a new database with only the cases selected – rather, as and when a statistical method is used, only those cases selected will be used in creating the statistical object. This means that if you wish to perform a calculation on a different selection, you must (a) make the new selection and then (b) repeat the process of creating the statistical object with the required information again.


oostatshelp: Deleting Variables

Deleting Variables

To delete a variable, simply name it as the right argument of fdb.DeleteVariable. System variables cannot, of course, be deleted.

db.DeleteVariable 'alan'
Variable alan has been deleted

Alternatively, if you are not sure of the name of the variable you wish to delete, you can select it from a listbox using db.DeleteVariable ''.


oostatshelp: Adding a new variable

Adding a new variable

Quite often, we want to compute a new variable and add it to the database:-

db.AddVariable 'new←alan+2×adrian'
Variable new created by expression 'alan+2×adrian' added to database
      db.Mat
1 1 2  5 1 1
2 2 1  4 1 1
3 3 3  9 1 1
4 4 5 14 1 1

Of course, if there are any missing values in the variables concerned, then the new variable will also have corresponding missing values. If preferred, the statement defining the new variable may be written in an apl textbox:-

db.AddVariable''


oostatshelp: Coding an existing variable

Coding an existing variable

Some statistical routines (such as regression modelling) require one to refer to the data split up into different subsets. This is usually done using a ‘factor variable’ which must take the values 1,2,.. and so on (0 is excluded.) This can be created from an existing variable using for example:-

db.AddVariable 'newvar←(∪var)⍳var'

Alternatively the method Code can be used – it takes each unique value in the old variable in turn and replaces it with 1,2,3.... In addition, if there are any value labels attached to the original variable, or if the original variable values are strings, these are stored as value labels. You can use db.Code 'varname' or db.Code '' to choose the variable via a listbox.


oostatshelp: Case Frequency

Case Frequency

In some cases, the statistical database that you require to work on lists the unique cases, each case then having an associated frequency. The system variable _CFreq defaults to a vector of 1’s. However any non-negative integer variable in the database may be declared to be the case frequency variable:-

db.CaseFrequency 'adrian'
Case Frequency is user defined by expression adrian
      db.Unistats 'alan'
Created object #.alan.?
Currently, # cases excluded = 0
      alan.Mean
3

This corresponds to:-

(1 2 3 4+.×2 1 3 5)÷2 1 3 5+.×1
3


oostatshelp: Ordering Cases

Ordering Cases

Sometimes in looking at a database, it is useful to be able to order the data in a different order to the original one (which may have been quite haphazard). For example,

db.OrderCases 'adrian'
      db.Mat
2 2 1 1 1
1 1 2 1 2
3 3 3 1 3
4 4 5 1 5

As you can see, the variable adrian in the third column is in ascending order, and the original case 1 is in second place as indicated by the _Cases (first column). By default the ordering is from small to large. However, if a left argument is specified, such as

0 db.OrderCases 'adrian'

then the ordering is from high to low.

To restore the original order,

db.Order '_Cases'

More than one variable may be used with the variables to the left taking precedence over those to the right. This information can also be supplied by entering 1,2,3.. as required against the variables in the grid (those with zero values play no part):-

db.Order ''


oostatshelp: Colour Coding Numeric Variables

Colour Coding Numeric Variables

When viewing the database through a grid object, as in using db.View from the session, or in using the gui interface, it is sometimes quite helpful to colour code numeric variables. A very simple progression of dark blue, medium blue, light blue, neutral, pale pink, pink, red colour codes each numeric variable from low (blue) to high (red) values.

To do this, use the metnod

db.ColourOn, and to switcho off,

db.ColourOff.

Indicating that a case is currently not selected takes precedence over the colouring, and all cells corresponding to such a case will be grey. Generally speaking, it is probably best not to colour the cells if you are changing the selection of cases frequently.

The example below uses a database of the weight of cork on trees in the directions North, South East and West. If we order the database so that the first variable North is increasing, the picture below shows clearly how positively correlated the variables are.

.Open oostats/cork.adb
db.OrderCases 'North'
db.View


oostatshelp: Ordering the Columns in the Grid

Ordering the Columns in the Grid

You may find you wish to order the display of the columns, if only temporarily. It may be that you don;t necessarily wish to change the position of all columns, so, if for example, you want the first two variables in the grid to be the tenth and the third, then

db.OrderVars 10 3 will do the trick.

Alternatively db.OrderVars '' will give you a grid object. For example,

filled in as indicated, will pull the beds variable and the area variable to the front of the database.


oostatshelp: The Univariate Statistics Object

The Univariate Statistics Object

The most commonly used statistical procedures involve looking at a single set of data and obtaining some understanding of the variability in the data.


oostatshelp: Introduction

Introduction

The most common statistical calculations are those to do with a single numeric variable. To illustrate this in a meaningful way, consider the dataset of Swanse house-prices supplied with the software.

Open 'oostats\housedata.adb'
Object 'db' has been created using s_db from file oostats\housedata.adb
      db.VarNames
 price  area  beds  type  age  _CSel  _CFreq
      db.GetVar 'price'
156 55 65 46.95 46.95 47.5 110 65 54 85 70 82.5 78.5 49.95 77 37.5 65 75 96.5 53.95 75 60.5 148 79.95
      120 102 145 68 98

These are values of house prices in units of £1000. To calculate some statistics or provide graphical information on these house prices, we create a univariate statistics object


oostatshelp: Creating the Univariate Statistics Object

Creating the Univariate Statistics Object

⎕←db.Unistats 'price'
Created object #.price.?
Currently, # cases excluded = 0

The method Unistats, a database method, filters out missing values and creates a statistical object #.price using the statistical object code contained in s_unistats. To see what facilities this provides us with (public fields and methods)

price.Options
 Mean  StDev  StError  Lhinge  Median  Uhinge  Outliers  ExtremeOutliers  Tstat  NonParTest  Pctile
FreqTable  ConfInt  Hist  Boxplot

An alternative approach to exploring what is available with this statistical object and other is to use the method price.Explore


oostatshelp: Simple Statistics

Simple Statistics

The first eight options of the univariate statistics object are:-

Mean  StDev  StError  Lhinge  Median  Uhinge  Outliers  ExtremeOutliers

Having established a univariate statistics object for price these elementary statistics are easily obtained – for example:-

price.Mean
79.7845
      price.StDev
31.3536


oostatshelp: Boxplot

Boxplot

This produces a boxplot, with any outliers or extreme outliers indicated by their case number, here the cases 5 and 24 are high outliers.

price.Boxplot


oostatshelp: Confidence Interval for the True Mean

Confidence Interval for the True Mean

A confidence interval for the true mean is an expression of how much (or how little) certainty there is as to the true location of a population mean. Purely by convention, users of statistics often quote a 95% confidence interval – other ‘levels of confidence’ might also be used, by supplying the appropriate right argument:-

price.ConfInt 95
 Lower Bound  67.8582
 Upper Bound  91.7108


oostatshelp: Testing the hypothesis about the true mean

Testing the hypothesis about the true mean

Related to the confidence interval is the idea of testing the hypothesis that the true population mean is equal to a particular value.

price.Tstat 60
 #               29
 Mean            79.7845
 Std Error        5.82222
 t-Stat           3.3981
 p-val            0.00205256
 lower 95% conf  67.8582
 upper 95% conf  91.7108

A low p-value (typically less than 0.05, as is most definitely the case here) is used to suggest that the hypothesised mean, in this case 60, is not the correct population mean. You may prefer to relate this to confidence intervals, in which case the two statements

‘The calculated p-value is less than 0.05 and hence we reject the hypothesis that the true population mean is 60 at the 5% level’

and

‘The hypothesis mean value of 60 is outside the 95% confidence level, hence we reject the two-sided hypothesis at the 5% level ‘

are equivalent.


oostatshelp: Histogram

Histogram

A pictorial representation of the sample distribution is given by a histogram, constructed by specifying an interval end-point and an interval width:-

price.Hist 35 10

(N.B. the first value does not have to be in the range of the data)

Note the menu items – View to view the picture through Rainpro’s full-screen viewer, and Overlay to display a density curve.


oostatshelp: Exploring the Options

Exploring the Options

All statistical objects created from the database by statistical methods may be explored by using the root-level function

#.Explore

with right-argument equal to the statistical object name. This is useful for a quick exploration of the functionality of the object and also leads to annotated output that aids understanding of the analyses performed.

A grid-object lists the statistical fields and methods for the object. Where arguments are required, suggested entries are given so that you can replace the supplied values with your own. Note that only information typed to the right of an assignment arrow is used. Tick the facilities you require – default options are already ticked but not obligatory!

pre>Explore price

Univariate Statistics for price
-------------------------------

Testing the hypothesis that the true mean is 75
-----------------------------------------------

 Statistic         Value
 #               29
 Mean            79.78
 Std Error        5.822
 t-Stat           0.8218
 p-val            0.4182
 lower 95% conf  67.86
 upper 95% conf  91.71


oostatshelp: A Case Study

A Case Study

We illustrate some of the univariate statistic tools using a case study from the database oostats/cholesterol.adb.

  Open 'oostats/cholesterol.adb'
Object 'db' has been created using s_db from file oostats/cholesterol.adb

Some information can be found using

↑db.Info

However from a list of variables

db.VarNames
 who  bmi  wtbf  wtaf  ht  cholb  chola  sex  age  _CSel  _CFreq

note that the two variables cholb and chola are measurements of cholesterol levels in patients before and after an interventionist campaign to reduce cholesterol. To investigate whether the intervention was successful, we calculate the difference in levels, before minus after, and then test the hypothesis that the true mean difference is 0.

db.AddVariable 'choldiff←cholb-chola'
Variable choldiff created by expression 'cholb-chola' added to database
      ⎕← db.Unistats 'choldiff'
Created object #.choldiff.?
Currently, # cases excluded = 0
       choldiff.Hist 0.25 .5

To test the hypothesis:-

choldiff.Ttest 0
 #               1.18000E2
 Mean            6.24407E¯1
 Std Error       8.87040E¯2
 t-Stat          7.03922E0
 p-val           1.41369E¯10
 lower 95% conf  4.48733E¯1
 upper 95% conf  8.00081E¯1

The p-value is very small, so we reject the hypothesis of zero mean – hence it seems that the diet was successful. Note however that the confidence interval for the true mean drop is (0.448, 0.8) – quite small. The histogram indicates that there are some possible outliers – these can be found to be cases 80 and 117 from a boxplot. The analysis could be repeated after delesecting these cases using a command such as:-

db.SelectCases '~_Cases∊80 110'
Cases selected by ~_Cases∊80 110
2 cases not selected

(Remember, after de-selecting cases or other database options, you must re-create the univariate statistics object again – this applies to any other statistical method that creates its fields and methods from the database.)

However this makes no difference to the conclusion. Probably of more interest would be to investigate whether there was any relation between those who did successfully reduce their cholesterol and the other variables.


oostatshelp: The Cross-Tabulation Object

The Cross-Tabulation Object

Many databases constructed in the course of research will include categorical variables which may be related. This chapter demonstrates how to explore the relationship between two such variables.


oostatshelp: Introduction

Introduction

Perhaps the second most frequently used statistical object is a cross-tabulation of two categorical variables. In the database on house prices, if the number of bedrooms was the only variable measuring size, we could investigate the relationship between size and type of house by looking at the bi-variate frequency table of these two variables. The statistical object s_crosstabs is invoked from the database using db.CrossTabs together with the appropriate two variable names.


oostatshelp: The CrossTabs Object

The CrossTabs Object

We create a CrossTabs object by using the database method CrossTabs followed by the names of two database variables. To make sense, these should be variables with relatively few unique values – here we use the type of house and the number of bedrooms.

db.CrossTabs'type' 'beds'
Sub-Object s created using s_crosstabs

Now, if you wish to explore this new object, type

db.s.Explore
to obtain a spreadsheet of options for cross-tabulation, or you can use
db.s.Options
Observed  Expected  StandResid  Table  ChiSquareTest  FullTable  ViewFullTable  TowerChart


oostatshelp: Observed Frequencies

Observed Frequencies

The matrix of observed frequencies for each pair of values

 db.s.Observed
1 2 2 2 2
1 0 9 1 0
0 0 2 3 0
0 1 3 0 0


oostatshelp: Frequency table with labels

Frequency table with labels

If the variables concerned have value labels then use

db.s.Table
                 1 2 3 4 5
 terraced house  1 2 2 2 2
 semi-detached   1 0 9 1 0
 detached        0 0 2 3 0
 bungalow        0 1 3 0 0


oostatshelp: Expected Frequencies

Expected Frequencies

These are the expected frequencies corresponding to the observed frequencies in the cross-tabulation, which indicates what frequencies we would expect to observe, if there were no relationship between the two categorical variables (here, number of bedrooms and type of house).

db.s.Expected
0.62069  0.931034 4.96552 1.86207  0.62069
0.758621 1.13793  6.06897 2.27586  0.758621
0.344828 0.517241 2.75862 1.03448  0.344828
0.275862 0.413793 2.2069  0.827586 0.275862

The chi-square statistic is calculated by comparing the observed and expected frequencies as shown below.

o←db.s.Observed
      e←db.s.Expected
      +/,(o-e)×(o-e)÷e
18.0545

There are more details on the chi-square statistic here..


oostatshelp: Chi-Square Test Statistic

Chi-Square Test Statistic

The Chi-Square test for a bivariate frequency table is concerned with whether there appears to be any relationship between the two category variables. In the current context, the null hypothesis would be that the proportions of houses with 1,2,3.. bedrooms is the same irrespective of the type of house.

db. s.ChiSquareTest
  Chi-square  Degrees of Freedom  p-value   18.0545 12 0.114045
      Tab db.s.ChiSquareTest
 Chi-square  Degrees of Freedom   p-value
    18.0545                  12  0.114045

The Chi-Square test proceeds by calculating the chi-square statistic using the expected frequencies under the null hypothesis as indicated there. An associated p-value less than 0.05 would be evidence to reject the null hypothesis so, here, we conclude that, on the basis of the data in the sample, there was no evidence of a relationship between the two variables as the p-value=.114, which is greater than 0.05.

For a case where there appears to be a relationship between the two variables, it is important to try to understand what that relationship is – see the case study.

.


oostatshelp: A Case Study

A Case Study

Universities in the UK grade degrees awarded into categories (First Class, Upper Second, Lower Second and Third Class). An interesting question using contingency table techniques is to analyses degree results of a university versus the faculty (e.g. Arts, Science..). The null hypothesis in such an investigation would be that the proportions of degrees in the different classes do not vary across the different faculties.

Open 'oostats/degclass.adb'
Object 'db' has been created using s_db from file oostats/degclass.adb
      db.VarNames
 degree  faculty  frequency  _CSel  _CFreq
      db.CrossTabs 'faculty' 'degree'
Sub-Object s created using s_crosstabs
Currently, # cases excluded = 0
      db.s.Table
                 First  Two-one  Two-two  Third/Pass
 Engineering        29       54       62          41
 Business           14       87       58          13
 Social Studies      5       99       96          15
 Arts (NL)          19      210       95          18
 Arts (L)           11      146      108           8
 Science 1          25       95       92          21
 Science 2          18       72       84          28
     Tab db.s.ChiSquareTest
 Chi-square  Degrees of Freedom  p-value
    146.037                  18        0

Clearly. with a p-value so close to zero that is recorded as zero, we must reject this hypothesis. To understand then just what the relationship is between class of degree and faculty use

db.s.ViewFullTable

In this full table, not only do we see observed values together with expected values, a standardised residual is calculated measuring the difference between the two on a standardised scale (approximately a Normal distribution scale). Cells where the observed is sufficiently higher than the expected frequency to give a residaul greater than 2 are shown in red, whilst the equivalent ones (observed sufficiently lower than expected to give a residual less than -2) are shown in blue. By looking at the colour pattern, it becomes clear that numerate-based faculties tend to have more in the extreme degree classes (firsts and thirds) than the more discursive faculties where degree results tend to bunch in the upper and lower second categories.


oostatshelp: Two-Sample Analysis

Two-Sample Analysis

A common requirement in statistics is to compare values of the same measurement in two distinct samples. This chapter demonstrates the appropriate tools.


oostatshelp: Introduction

Introduction

It is frequently the case in Statistics that we wish to compare two comparable samples of values with a particular interest in whether the locations of the two sets are the same – one example might be to compare weight losses of males on a diet with weight losses of females using the same diet. There is a natural null-hypothesis, namely that the true mean weight loss for males is the same as that for femaies. This is not to be confused with the actual sample means which either are the same (very unlikely) or not. This is the scenario that is covered here. Within the context of a database, both data sets will be within one column of figures – the weight loss figures. A second variable is then needed to define the membership of each group.


oostatshelp: The TwoSampleMeans Method

The TwoSampleMeans Method

We will illustrate the analysis using once again the house price data, and compare the mean house price for houses with less than 3 bedrooms with those with more than 2 bedrooms (note, these two categories should be mutually exclusive, but need not include between them, all the data as they do here). The method TwoSampleMeans requires three strings to specify (a) the observation data – here the variable beds (b) a definition of the first group of cases – here 'beds<3' and (c) the second group of cases – here 'beds>2'

Open 'oostats/housedata.adb'
Object 'db' has been created using s_db from file oostats/housedata.adb
      db.VarNames
 price  area  beds  type  age  _CSel  _CFreq
      db.TwoSampleMeans 'price' 'beds<3' 'beds>2'
Sub-Object s created using s_twosamt
      db.s.Options
 Stats  PooledVar  EqualVarTest  Ttest  NonParTest  Outliers  ConfInt  CooksDistance  Boxplot Rankitplot


oostatshelp: Boxplot

Boxplot

It is useful to display the data in two groups – using a histogram is difficult, but a boxplot is ideal.

db.s.Boxplot

This gives a clear idea that house prices of 1 or 2 bedroom houses are generally lower than those with three or more bedrooms and there appear to be no outliers.


oostatshelp: The Two-Sample t test

The Two-Sample t test

Having created the two sample object with the command

db.TwoSampleMeans 'price' 'beds<3' 'beds>2'
we can do a t-test:-
Tab db.s.Ttest 0
 t-Statistic  df    p-value
    ¯2.22735  27  0.0344537

The p-value, lower than 0.05 suggests that the null hypothesis of equal group means should be rejected at the 5% level.

To calculate a 95% confidence interval

Tab db.s.ConfInt 95
 Lower value  Upper Value
    ¯55.7412      ¯2.2863


oostatshelp: Equal Variances

Equal Variances

The usual two-sample t-test assumes that the variances of the two groups are equal. If they are not, then interpretation of the p-value in the t-test in the usual way is suspect. It is possible to test whether the variances are equal:-

Tab db.s.EqualVarTest
 df1  df2  F-statistic    p-value
   4   23      3.50246  0.0225341

The low p-value (less than 0.05) suggests that we should reject the null hypothesis of equal group variances. This means that we should use a different procedure for calculating a t-statistic and p-value, or confidence interval. This is done by using a left argument of 2 for the Ttest and ConfInt methods.

Tab  2 db.s.Ttest 0
 t-Statistic  df      p-value
      ¯4.227  24  0.000296473
Tab 2 db.s.ConfInt 95
 Lower value  Upper Value
    ¯43.1802     ¯14.8473

It is interesting to note that we now have much firmer evidence to reject the null hypothesis than previously (a much lower p-value, or equivalently, zero is a long way outside the confidence interval).

Note, that if you use the Explore option, then the left argument for the two methods has a list-box indicating the choice of assumption of equal variance or not:-


oostatshelp: Rankit Plot

Rankit Plot

A Rankit Plot is a plot designed to test whether the assumption of a Normal distribution is justified. It may be applied in a one-sample situation where the assumption is that observations are equal to the true mean plus a normally-distributed error. It may also be applied in more complicated contexts, such as the two-sample analysis as here (where the assumption is that each observation differs from its true mean by a normally-distributed error) and also in regression and analysis of variance models.

The Rankit plot consists of a plot of the ordered standardised residuals against their corresponding normal quantiles. On top of this scatterplot, an envelope or upper- and lower- 1 in 20 bounds are constructed by simulating the assumed model and generating random normal errors. Rather than looking simply at the scatterplot and judging whether it is approximately linear (which it should be if the normal distribution assumption is satisfied), one can check whether the plot is within the simulated bounds. If the scatterplot is substantially outside the bounds, then this casts serious doubt on the assumption of normality. This in turn would cast some doubt on the validity of the t-test and confidence interval results.

For the example of the price of houses split into the two categories of number of bedrooms (<3 and >2) the Rankit plot is:-

In this case, despite some evidence of non-linearity in the residuals, the plot just about lies within the bounds, and so one can be reasonably confident of the results of the appropriate t-test – see the two-sample t-test.


oostatshelp: Tables of Univariate Statistcs

Tables of Univariate Statistcs

Tables of simple univariate statistics within groups specified by one or two variables


oostatshelp: tables

tables

Sometimes it is useful to have numerical summaries (e.g. such as mean and standard deviation) for a variable grouped by the unique values of one or two variables. This method provides such facilities together with illustrative boxplots.


oostatshelp: An Example

An Example

Consider a database from an investigation into cholesterol levels. The variable cholb is the level of cholesterol before diet, sex is the gender variable, and who indicates whether people were seen by a dietician or health visitor.

db.Table 'cholb' 'sex'
Created sub-object s.?
Currently, # cases excluded = 0
      Tab db.s.Table
             Female       Male
 #-Cases  60         58
 Mean      7.33517    7.37034
 StdDev    0.874952   0.760858

All statistics available may be be obtained using:-

 Tab db.s.FullTable
              Female        Male
 #-Cases   60          58
 Sum      440.11      427.48
 Mean       7.33517     7.37034
 StdDev     0.874952    0.760858
 5%ile      5.76        6.48
 25%ile     6.975       6.87
 50%ile     7.395       7.16
 75%ile     7.665       7.62
 95%ile     8.825       9.29

or you may exercise your choice using

#.Explore db.s
.

Using two categorising variables is simple:-

  db.Table 'cholb' 'sex' 'who'
Created sub-object s.?
Currently, # cases excluded = 0
      Tab db.s.Table
                  Health Visitor   Dietician
 Female  #-Cases       29          31
         Mean           7.29621     7.37161
         StdDev         0.953915    0.808353
 Male    #-Cases       28          30
         Mean           7.46393     7.283
         StdDev         0.914793    0.585121

Using the Boxplot option will give a one-way or two-way boxplot as appropriate.

db.Table 'cholb' 'sex' 'who'
Created sub-object s.?
Currently, # cases excluded = 0
      db.s.Boxplot


oostatshelp: One-Way Analysis of Variance

One-Way Analysis of Variance

This topic is a natural extension of the Two Sample Analysis to a technique for testing equality of means in two or more samples.


oostatshelp: Introduction

Introduction

This chapter addresses the need to test the equality of 2 or more samples of measurements of the same kind. The sections on Two Sample Meansonly allowed two sample means to be tested – here this restriction is removed.


oostatshelp: The OneWayAnova Method

The OneWayAnova Method

As with the related TwoSampleMeans method, we look at the house price data again. There are four types of house – detached, semi-detached, terrace and bungalow. All houses in the database fall into one of these categories. It is appropriate therefore to use the OneWayAnova method to test the hypothesis that the true mean prices of each type of house are the same.

db.OneWayAnova 'price' 'type'
Created sub-object s.?
Currently, # cases excluded = 0
      db.s.Options
 MeansTable  EqualVarTest  AnovaTable  Ftest  GroupContrasts  CooksDistance  Outliers  Boxplot  RankitPlot

To see what statistical options we can use:-

Tab db.s.MeansTable
 Group           #-cases      Mean   Std Dev
 terraced house        9   60.7611  18.738
 semi-detached        11   71.2182  22.7663
 detached              5  116.7     29.5838
 bungalow              4   72.5      9.57427

As with the two-sample t test, it is important to test the hypothesis that the variances in each group are the same, although it is not so easy to deal with the analysis if there is a difference.

 Tab db.s.EqualVarTest
  Bartlett Chi Square Test Statistic  df        pv
                            3.50968   3  0.319509

This tells us that the assumption of equal variances is justified, so that we can now test the null hypothesis of equal means using, in this case, and F-test:-

 Tab db.s.Ftest
 df1  df2  F-Statistic      p-value
   3   25      7.55809  0.000921975

The very low p-value indicates that the null hypothesis is firmly rejected. It is good to investigate why – from the table of means it is clear that detached houses are highly priced – the mean differences can be readily seen via a boxplot:-

 db.s.Boxplot

For more details on which pairs of group means are significantly different from each other, use

Tab db.s.GroupContrasts  95
 First Group     Second Group   Mean Difference    Lower CL  Upper CL  Sig Diff?
 terraced house  semi-detached         10.4571   ¯18.7548     39.669
 terraced house  bungalow              11.7389   ¯27.3167     50.7945
 terraced house  detached              55.9389    19.6879     92.1899  *
 semi-detached   bungalow               1.28182  ¯36.6656     39.2292
 semi-detached   detached              45.4818    10.4275     80.5361  *
 bungalow        detached              44.2        0.601772   87.7982  *

Note that these confidence intervals are simultaneous confidence intervals at the proscribed level. From this, we see that detached houses are significantly higher priced than each of the other three types of houses.

Note also that once again, the Rankitplot option may be used to validate the assumption of normality.


oostatshelp: Introduction

Introduction

Regression analysis is a huge topic in statistics, covering a wide range of applications. The latter are extended even further by the use of generalized linear models. The essence of a regression model is that one variable, usually denoted by the name ‘y-variable’ is to be predicted by one or more predictor variables. The simplest example to set the scene is the notion of trying to predict the weight of a person given their height. The simple linear regression model is given by the notion that the expected weight of a person is given by the formula a+b×height. An observed weight value would be given by a+b×heighttplus an error term which is assumed to have a Normal distriution.

More complicated models can be constructed by introducing further predictor variables. For example, one can construct a regression model as above that would allow the constants a,bto depend on the sex of the individual.


oostatshelp: An Example of Simple Linear Regression

An Example of Simple Linear Regression

With the house prices data, we would not be surprised to find that the cost of a house ought to increase as the size (total room area in square feet) increases.

db.Regress
Created sub-object s using s_reg
      )cs db
#.[s_db]
      s.Yvar 'price'
      s.Lp 'gm+area'
      s.Fit
   Source                 ss  df        ms
   Due to Model      9864.65   1  9864.65
   Residual         12576.1   27   465.78
   Total Corrected  22440.7   28   801.454

   Percentage Variation Accounted for   F-statistic       p-value
                               43.9587       21.1788  0.0000887413

Using the command/method db.Regress creates a regression object from the database (all variables are available). Changing to the namespace db using )cs db facilitates issuing commands that mimic the approach taken in ASLGREG -

s.Yvar 'price' declares which variable we are trying to predict

s.Lp 'gm+area' states that we wish to predict house prices using a linear function of area (note gm stands for grand mean.

The command s.Fit provides the usual summaries of fitting this model, whereas

s.Display
 Var           Est     Std-Err   t-Stat       p-Value  Alias
 GM     32.0712     10.351      3.09838  0.0045082         1
 area    0.0515724   0.0112064  4.60204  0.0000887413      1

gives the estimates, their standard error, t-statistic and p-value. Note that a zero in the ‘Alias’ column would indicate that a variable has been left out because any information on the y-variable it could have given has already been given by a previous variable.


oostatshelp: Looking for outliers

Looking for outliers

One aspect of checking the model is to look for cases for which the model appears not to work, or alternatively, cases which are exerting too much influence on the estimates. To do this, output the table of diagnostics and scan for (a) cases which have a Cooks Distance greater than 1 – such cases, if deleted would result in substantially different estimates, or (b) cases with a high leverage. Note that cases with high leverage do not necessarily have a high Cooks Distance – they influence the estimates in the sense that if the y-value for this case changed, then the estimates would change considerably, but removing a case with high leverage does not necessarily result in a large change in the estimates.

#.Tab s.Diagnostics
 Case  Fitted Value  Stand_Resid  t-Residual   Leverage  Cooks Distance
    3       48.1618   ¯0.106357   ¯0.104391   0.112994      0.000720493
   12       49.9153    0.248817    0.244446   0.103412      0.00357033
   11       61.2096    0.180821    0.177548   0.0566325     0.000981414
   17       54.3505   ¯0.357882   ¯0.352028   0.081958      0.00571715
   18       58.7342   ¯0.564582   ¯0.557327   0.0646725     0.0110199
    2       72.4009   ¯1.175      ¯1.1837     0.0357896     0.0256231
    4      107.367     0.131121    0.128711   0.134276      0.00133332
    6       70.8537   ¯0.276415   ¯0.271633   0.0371586     0.00147434
    8       78.6927   ¯1.16484    ¯1.17291    0.0352225     0.0247681
   10       69.977     0.709763    0.703085   0.0381497     0.00999035
   13       68.0688    0.0913684   0.0896743  0.0408456     0.000177754
   14       72.0399    0.493655    0.486628   0.0360656     0.00455893
   15       67.9656    0.498438    0.491387   0.0410124     0.00531245
   16       70.2864   ¯0.96061    ¯0.959186   0.0377821     0.0181166
   19       70.5958    0.302452    0.297303   0.0374339     0.00177876
   21       63.1694   ¯1.22103    ¯1.23272    0.0511486     0.0401845
   23       60.4876    0.215518    0.211672   0.0588492     0.00145218
   26       70.9568    0.19091     0.187468   0.0370522     0.000701195
   27       75.9078    0.97103     0.969965   0.0344835     0.0168378
   28       58.7857   ¯0.231659   ¯0.227555   0.0644923     0.00184982
   29       64.7681    0.485707    0.478724   0.0472517     0.00585004
    1      100.456    ¯1.94629    ¯2.05987    0.0951571     0.199184
    5       86.5317    2.9156      3.45651    0.0457451     0.203754
    7       89.8324   ¯0.470763   ¯0.46387    0.0539029     0.00631322
    9      117.372     0.136831    0.13432    0.208068      0.00245955
   20       79.2084    1.07533     1.07857    0.0355319     0.0213
   24      103.396     2.04409     2.18179    0.110614      0.259831
   22       98.7028   ¯1.48867    ¯1.52476    0.0867714     0.105284
   25      113.556    ¯0.794763   ¯0.789192   0.177527      0.068169

This table pertains to the regression of price on area. Cases 1 and 5 have large t-residuals indicating that they do not fit too well into the model. However there appear to be no outliers (Cooks Distance greater than 1) such that deletion of the case would lead to substantially different estimates.


oostatshelp: Graphical Output for Regression Models

Graphical Output for Regression Models

If the regression model involves only one predictor variable, then the most natural plot to produce is a scatterplot of y-values against predictor (x-) values together with the fitted line. If however, there is more than one predictor variable, then the simplest alternative is a plot of observed y-values against fitted values. In either case, a Rankitplot will report on the assumption of normality. Examples of each plot are given below for the regression of price of house on floor area.

Scatterplot of y-values and x-values

Scatterplot of y-values against fitted values

Note that the scale of the horizontal axis is the same as that of the vertical axis

Rankitplot


oostatshelp: More regression models

More regression models

Regression analysis is a large topic, and this is not the place to try to cover it all. However it is useful to point out that the facilities available in the regression object are as extensive as those found in the previously published APL software by the name ASLGREG.

Factor variables

A variable may be declared to be a factor variable. This means that its positive integer values are interpreted as indicating a grouping of the y-variable into distinct classes. For example, in the database housedata.adbthe variable type takes values 1,2,3,4 indicating the type of house (and the value labels give meaning to these numbers).

If declared as a factor variable, the linear predictor of house prices given by gm+type results in an analysis which is equivalent to the one-way analysis of variance. There is one difference however – in the regression context, the parameters estimated are (a) the mean of the type=1 house, followed by the mean difference betwee type=2 and type=1 and so on.

Including both factor and regressor variables

In addition, a linear predictor can include a mixture of factor and regressor variables. For example, the linear predictor gm+area+type would fit four regression lines with different intercepts but with an estimated common slope on area.

s.Yvar 'price'
      s.Factor 'type'
      s.Lp 'gm+area+type'
      s.Fit
   Source                 ss  df        ms
   Due to Model     17015.7    4  4253.93
   Residual          5424.98  24   226.041
   Total Corrected  22440.7   28   801.454

   Percentage Variation Accounted for   F-statistic     p-value
                               75.8253       18.8193  4.02362E¯7
      s.Display
 Var             Est     Std-Err   t-Stat       p-Value  Alias
 GM       19.9812     9.18593     2.17519  0.0396952         1
 area      0.0451995  0.00853273  5.29719  0.0000196177      1
 type 2   15.9691     6.83722     2.33562  0.0281976         1
 type 3   46.9181     8.55709     5.48295  0.0000123028      1
 type 4   24.4387     9.34739     2.61449  0.0151977         1

In contrast, the linear predictor gm+area+type.area would fit four separate regression lines, each with its own slope and intercept for each type of house.

s.Lp 'gm+type+type.area'
      s.Fit
   Source                 ss  df        ms
   Due to Model     17527.9    7  2503.98
   Residual          4912.86  21   233.946
   Total Corrected  22440.7   28   801.454

   Percentage Variation Accounted for   F-statistic       p-value
                               78.1074       10.7033  0.0000106799
      s.Display
 Var                   Est     Std-Err     t-Stat      p-Value  Alias
 GM             30.3847     12.0214      2.52754   0.0195756        1
 type 2         ¯4.08632    17.2985     ¯0.236224  0.815547         1
 type 3         26.0701     29.7484      0.876351  0.390754         1
 type 4        ¯28.2856     66.7974     ¯0.423454  0.67627          1
 type 1  area    0.0336685   0.0120666   2.79023   0.0109671        1
 type 2  area    0.0575694   0.0148054   3.8884    0.000848079      1
 type 3  area    0.054679    0.0239041   2.28743   0.0326497        1
 type 4  area    0.113321    0.105047    1.07877   0.292924         1

Generalized Linear Models

All standard regression models assume that (a) the linear predictor specifies the expected value of the y-variable for given regressor variable values, and (b) the error distribution is assumed to be a Normal distribution. Both these hypotheses can be relaxed in the theory of generalized linear models.


oostatshelp: Using the gui interface - more details

Using the gui interface – more details

In the introductory chapter it was explained how statistical analysis on a database may be done using a gui front-end. In this chapter we present more details on this, though it is not difficult to use it without reading these notes.


oostatshelp: Starting up a database

Starting up a database

A pre-saved database created by oostats may be opened within a gui environment in a number of ways. If the datbase has been saved, then, from the session type:-

1 Open ''

which generates a file-box object for you to select the file required.

Alternatively,

1 Open 'oostats/housedata.adb'

loads the housedata file supplied in the folder oostats.

If you wish to create a database ready for editing, then

1 Open 'new' (10 4)

creates a new database with 10 cases and four variables (with default names).

Finally, if you have variables to hand, then you can create the database object using⎕new and the object s_guidb (that inherits the properties of s_db) as follows:-

 db←⎕new s_guidb (('alan' 'adrian')((1 2 3 4 )(2 1 3 5)))
      db.MainForm


oostatshelp: Editing

Editing

At the top-right of the tabbed sub-form of data items, there is an inactive grid cell entry box as seen in the diagram below.

The first two items on the Database menu are Edit On and Edit Off. It is good practice whilst performing statistical analyses to do so in Edit Off mode (the default). Simply select Edit On and you are free to edit the database in the usual way.


oostatshelp: Formatting Variables

Formatting Variables

On the database menu, the option Format Variables allows you to change the way a variable is shown in the grid object and change its name.

Note in this that we have changed the variablealan to claire and given it a format statement of F12.3. Note also how, if variables have value labels, you can opt to show these value labels, or both value and value label together:-

These changes in no way affect the actual values in the database.


oostatshelp: Creating statistical objects

Creating statistical objects

Choosing an entry in the Analyse menu is the route to creating a statistical object. The choices are shown below:-

Choosing one of these creates a tabbed sub-form allowing you to specify the object by naming appropriate variables to be used, etc. Such a sub-form contains two buttons – Close and Analyse. The former, simply closes down the whole application, whilst the second is to be pressed once the specification of the statistical object is complete. It is important to realise that one must use the Analyse button whenever a new analysis is required because, for example, a selection of cases has been made, or database values changed.

If the creation of the statistical object is successful, then as a result of pressing Analyse, a grid object appears on the sub-form which lists the methods for the object you might care to use. Alter the default selection according to your wishes and then press the new button Do Options. As a result, output including tables of statistics, explanatory notes, appropriate graphs are created and displayed on the right of the screen. Depending on the object, there may be up to three graphs created on different tabbed sub-forms. Each of these may be viewed via the Causeway Viewer bu appropriate selection on the View menu.

A typical use of a statistical object might invovle quite a few cycles through this procedure as perusal of any particular piece of output might suggest repeating the procedure on a sub-set of the data (e.g.having tried an analysis on all respondents, one may wish to repeat it separately on males and females), or perhaps repeating the same analysis but with an outlying case removed.

Unless directed otherwise, all output is collected in an output journal and a Newleaf report may be constructed at any time by using the optionPrint on the File menu. Also on the same menu, you can choose whether to send forthcoming output to the output journal (default setting) or not.

The statistical motivation for using these objects is briefly described here.

Tables of Univariate Statistics

It is often useful to have output consisting of means and standard deviations (for example) for a variable divided into groups according to values of one or two categorising values. For example, with the housedata, on may be interested to see how the mean and standard devation vary across the different types of houses and the number of bedrooms.

Univariate Statistics

If you wish to explore values of one particular numeric variable, then create the Unistats object e.g. finding out about house prices in the houseprice database.

Matched Pairs Analysis

Supplied with the software is a health-care database called cholesterol.adb. This has two variables measuring the level of cholesterol in patients before and after an intervention diet. Testing whether the intervention had any effect proceeds by using a matched pairs analysis (which tests the hypothesis that the true mean of all the differences, say before minus after, is zero.

Two Sample Analysis

Here the focus of attention is on values of a particular variable divided into two groups, and test the hypothesis that the true means in the two groups are the same. For example, with housedata.adb we may test whether houses with fewer than three bedrooms have the same mean price as houses with more than two bedrooms.

One-Way Analysis of Variance

If we wanted to test the hypothesis that the true means of all the different types of houses were the same, then select as follows:-

Unique Frequencies

This simply creates a frequency table of unique values. Missing values are listed, so it is a useful resource when starting to work on a messy database, particularly for a variable which might have text values. For the housedata.adb, for example we can find how many there are of each type of house.

Cross-Tabulation

This creates a two-way frequency table of unique pairs of values (missing values are excluded). For example, we can find the frequency of each type of house and the number of bedrooms:-

Regression

The simplest example to illustrate this is to try to predict the price of house given its area:-

If we also wanted to take into account, the number of bedrooms then we alter the linear predictor accordingly to read gm+area+age. Note that a right click whilst the mouse pointer is in a free text box such as that for specifying the linear predictor provides a list box of variable names to help you insert the correct variable name:-

Generalized Linear Models

This is a sophisticated object which is dealt with elsewhere

Multivariate Methods


oostatshelp: Introduction

Introduction

Elementary statistical analysis focuses attention on one variable. For example, with the houseprice data, we are primarily interested in investigating house prices. Even though other variables are involved, e.g. in investigating how house prices vary with the size of the house, nevertheless the methods used are relatively simple because the focus of attention is on one variable.

Multivariate methods are appropriate when one wishes to investigate a group of variables. For example, the depth of the four treads on a car tyre might be of interest and how they vary with how much they have been used (mileage). Analogous to the variation of price with size (a univariate regression analysis) the new situation would be a multivariate regression analysis.

Multivariate methods are important because a multivariate analysis often has much more to offer than individual univariate analyses on each of the variables. In this inital release of OOStats, one multivariate object is available wih an extensive set of options. More are envisaged later.


oostatshelp: Basic Multivariate Statistics

Basic Multivariate Statistics

The statistical object s_corr is used from the database using the command Mutlistats followed by a list of variable names required. The example below uses a small but interesting multivariate dataset on weights of cork on trees – the variable North giving measurements in a norterly direction etc.

Open 'oostats/cork.adb'
Object 'db' has been created using s_db from file oostats/cork.adb
      db.VarNames
 North  East  South  West  _CSel  _CFreq
      db.Multistats ¯2↓db.VarNames
Sub-object s created using s_corr
If you are not sure which variables to include, you can do this through a gui dyalog box - simply click variables in the left-hand box to include, and click in the right-hand box to exclude.

Basic statistics for these variables can be calculated either using db.s.UnivariateStats which would give information on each variable in turn, ignoring only missing values for that variable, or, db.s.MutlvariateStats which would calculate the same quantities using only those cases for which values are available for all variables. In this example, there are no missing values, so the results are the same.

Tab db.s.MultivariateStats
        #.Cases     Mean  Std Dev  5%ile  25%ile  50%ile  75%ile  95%ile
 North       28  50.5357  17.0413     32      38    46.5    60        81
 East        28  46.1786  14.83       29      35    41.5    54.5      79
 South       28  49.6786  18.7084     30      34    43      66.5      76
 West        28  45.1786  15.0334     25      34    41.5    58        75


oostatshelp: Correlations

Correlations

The key to multivariate analyses is to take into account that variables are generally correlated (as opposed to independent) – this is the key feature for pursuing multivariate analyses rather than individual univariate analyses. Various outputs of corrrrelations are provided.

Correlation Table

db.s.CorrelationMatrix
1        0.885367 0.904717 0.883219
0.885367 1        0.8256   0.76868
0.904717 0.8256   1        0.922808
0.883219 0.76868  0.922808 1

Correlation Table

The same information but with annotated rows and columns is given by:-

Tab db.s.CorrelationTable
           North      East     South      West
 North  1         0.885367  0.904717  0.883219
 East   0.885367  1         0.8256    0.76868
 South  0.904717  0.8256    1         0.922808
 West   0.883219  0.76868   0.922808  1

Paiarwise Correlations

It is often useful to have information on whether a variable is significantly correlated with other variables. For this, it is general to use all the information available for each pair of variables.

Tab db.s.PairwiseCorrelations
        North       East      South       West
 North      1   0.885367   0.904717   0.883219
                    n=28       n=28       n=28
               pv=0.0000  pv=0.0000  pv=0.0000
 East           1          0.8256     0.76868
                               n=28       n=28
                          pv=0.0000  pv=0.0000
 South                     1          0.922808
                                          n=28
                                     pv=0.0000
 West                                 1

Here the correlations are all high and all have p-values less than 0.0005. (Typically a p-value of 0.05 or lower would be used to indicate that the pair of variables was correlated.)

Covariance Matrix

The matrix of covariances is available:-

db.s.Cov
290.406 223.753 288.438 226.271
223.753 219.93  229.06  171.374
288.438 229.06  350.004 259.541
226.271 171.374 259.541 226.004

This is used for calculating the correlations and also for performing tests of hypothesis.


oostatshelp: Testing for Multivariate Normality

Testing for Multivariate Normality

It is possible to provide a graphical test of whether the data to hand has a Multivariate Normal distribution by plotting observed multivariate quantiles against expected quantiles. Simulated 1 in 20 bounds help to indicate departures from normality.

db.s.ChiSquarePlot


oostatshelp: Testing Single Sample Multivariate Hypotheses

Testing Single Sample Multivariate Hypotheses

With a single sample of multivariate data, having checked multivariate normality using the ChiSquarePlot, there are two hypotheses of interest:-

(a) testing that the mean vector is a specified vector

(b) testing the hypothesis that all means are the same.

The sample mean vector may be displayed:-

db.s.MeanVector
50.5357 46.1786 49.6786 45.1786

This suggests, as an example that we test the hypothesis that the true mean vector is 50 50 50 50

db.s.TsquareTest 50 50 50 50
        Tab db.s.TsquareTest 50 50 50 50
 Hotelling's T-square  F-value  df1  df2        p-val
              37.7684  8.39299    4   24  0.000195015

The very low p-value indicates that we should reject this hypothesis. Note that it is perfectly possible for individual univariate tests to be accepted, but the multivariate hypothesis to be rejected!

An obvious test for the cork data is to test the hypothesis that all means are equal without specifying what that value should be. If there were two variables, this would be equivalent to the matched-pairs analysis where the differences of the two variables are calculated and then the hypothesis that the true mean difference is zero tested. A similar procedure is available here – by calculating (in this case) the values of three observations, being the three differences (North-East), (East-South) and (South-West), and testing that this tri-variate data has a true mean vector of 0 0 0.

Tab db.s.TestHypEqualMeans
 Hotelling's T-square  F-value  df1  df2      p-val
               20.742  6.40186    3   25  0.0022804


oostatshelp: Boxplot

Boxplot

If variables are measurements on the same scale (as in the cork data example) then it makes sense to use a Boxplot to gain some information on relative location and spread of the variables.

db.s.Boxplot


oostatshelp: Other Multivariate Options

Other Multivariate Options

As with other statistical objects, the options provided in the objects_corr can be explored using

#.Explore db.s

Note that the first eight options specify which statistics are to be included in the univariate or multivariate statistics options.

Assuming multivariate normality is possible to work out whether there any outliers or extreme outliers. These can be provided directly using:-

db.s.Outliers
28
      db.s.ExtremeOutliers

So case 28 appears to be an outlier.


oostatshelp: Multivariate One Way Analysis of Variance

Multivariate One Way Analysis of Variance

Investigating whether the vector mean of two or more variables depends on a group structure.


oostatshelp: Introduction

Introduction

Suppose you have height and weight measurements for a group of males and femailes. Rather than testing the individual hypotheses that male height equals female height, and similarly for weight, the technique of one-way multivariate analysis of variance allows you to test the equality of two group mean vectors. If the variables (such as height and weight) are correlated, then it is preferable to investigate group effects using this multi-dimensional approach.

To construct a one-way manova object from the session, simply list the names of the variables, specifying the group variable at the end of the list as in, for example:-

db.OneWayManova 'weight' 'height' 'sex'
Sub-object s created using s_onewaymanova

      db.s.Options
 Left arg  Option                Right arg
           Heading
           MeanVector
           GroupMeansMatrix
           GroupMeansTable
           WGCovarianceMatrix
           BGCovarianceMatrix
           HomogeneityTest
           WilksLambda
           HotellingsTsquare
           ParallelProfilesTest
           GroupContrasts        'Conf Level←95'
           MeansPlot
           Profileplot
           CanonicalAnalysis
           Screeplot
           Canonicalplot

Overall Mean Vector

The mean vector of all the data may be obtained using:-

db.s.MeanVector
61.88 170.9

Group Means

The commanddb.s.GroupMeansMatrixwill give the individual group means for all variables as a matrix. More useful for documentation is:-

Tab db.s.GroupMeansTable
          weight   height
 Male    67.2222  176.389
 Female  55.6087  164.457

Covariance and Correlation Matrices

Information on the covariances between the variables within or betweenthe group structure is obtained using WGCovarianceMatrixorBGCovarianceMatrixx:-

Tab db.s.WGCovarianceMatrix
          weight   height
 weight  66.4519  36.6587
 height  36.6587  44.5535
      Tab db.s.BGCovarianceMatrix
          weight   height
 weight  3350.27  3442.25
 height  3442.25  3536.75

Homgeneity Test

To test whether the covariance structure is common to all of the groups, use:-

Tab db.s.HomogeneityTest
 -2×Log_likelihood_ratio  df   p-value
                 2.82207   3  0.419879

As indicated this is a likelihood ratio test with asymptotic p-value. (In this case, the hypothesis of equal covariance structure in the two groups would be accepted.)

Testing the equality of equal group mean vectors

With only two groups of data, use Hotellings T-square test procedure:-

Tab db.s.HotellingsTsquare
 Hotellings Tsquare  F-statistic  df1  df2      p-value
             81.589      82.4215    2   99  8.45925E¯22

The very small p-value indicates that there is clear evidence of unequal group mean vectors (as we would expect).

If there are more than two groups, use the Willks Lambda procedure:-

Tab db.s.WilksLambda
 WilksLambda  Chi-square approx  Df  p-value
     0.54569            59.0561   4        0


oostatshelp: More advance topics

More advance topics

In this section we look at some more advanced topics to do with multivariate analysis of variance. To illustrate these topics, we use Fisher’s famous collection of four-dimensional data on three different species of Irises. The preliminary analyses may be performed as in the introduction, but we ascertain first that the group mean vectors are not equal.

Open ''
Object 'db' has been created using s_db from file C:\oostats\iris.adb
      db.UserNames
 sepal_length  sepal_width  petal_length  petal_width  variety
      db.OneWayManova db.UserNames
Sub-object s created using s_onewaymanova
      Tab db.s.GroupMeansTable
                  sepal_length  sepal_width  petal_length  petal_width
 Iris Setosa             5.006        3.428         1.462        0.246
 Iris Versicolor         5.936        2.77          4.26         1.326
 Iris Virginica          6.588        2.974         5.552        2.026
      Tab db.s.WilksLambda
 WilksLambda  Chi-square approx  Df  p-value
   0.0234386            547.992  12        0

so there is a clear significant difference between the group mean vectors.

Group Contrasts

r←db.s.GroupContrasts 95
      ⍴r
6
      ⍕((⍴r),1)⍴ra
  Iris Setosa  v  Iris Versicolor
   Variable  Mean Diff  Lower Limit  Upper Limit  Significant    sepal_length  ¯0.93  ¯1.30631  ¯0.553693 *
                                                                 sepal_width    0.658  0.409691  0.906309 *
                                                                 petal_length  ¯2.798 ¯3.11257  ¯2.48343  *
                                                                 petal_width   ¯1.08  ¯1.2296   ¯0.930403 *
  Iris Setosa  v  Iris Virginica
   Variable  Mean Diff  Lower Limit  Upper Limit  Significant    sepal_length  ¯1.582 ¯1.95831  ¯1.20569  *
                                                                 sepal_width    0.454  0.205691  0.702309 *
                                                                 petal_length  ¯4.09  ¯4.40457  ¯3.77543  *
                                                                 petal_width   ¯1.78  ¯1.9296   ¯1.6304   *
  Iris Versicolor  v  Iris Virginica
   Variable  Mean Diff  Lower Limit  Upper Limit  Significant    sepal_length  ¯0.652 ¯1.02831  ¯0.275693  *
                                                                 sepal_width   ¯0.204 ¯0.452309  0.0443088 -
                                                                 petal_length  ¯1.292 ¯1.60657  ¯0.977429  *
                                                                 petal_width   ¯0.7   ¯0.849597 ¯0.550403  *

These 95% simultaneous confidence intervals hae been calculated by simulating the distribution of the ‘largest eigen-value’ using 10000 simulations (hence the reason for the delay). As can be seen. only one dimension sepal_width is not signifiantly different for one comparison (Iris Versicolou v Iris Virginica).

(For more details on the largest eigenvalue distribution of the matrix (⌹W)+.×B where W is the within groups covariance matrix and B is the between groups covariance matrix, see Mardia’s book on Multivariate Analysis, chapter 3, section 5.)

Parallel Profiles

In Psychology, where the object of interest is often a set of competing measures, a further hypothesis of interest is whether the differences between any pair of measurements are the same for each of the groups – i.e. are the profiles (means on each variable plotted on the same axis in the same order for each group) paralle?

Tab db.s.ParallelProfilesTest
 Theta (Largest eigenvalue)  p-value
                   0.958402        0

The answer, for this data is clearly no. More information on this can be obtained from the plot of the parallel profiles:-

db.s.Profileplot


oostatshelp: Canonical Analysis

Canonical Analysis

Canonical Analysis

This advanced topic is often of great interest in biology or archeology. Briefly, it is sometimes possible to reduce the dimension of the variables to 1 or 2, at least in so far as differences between groups are concerned. For example, it is possible that there may be just one direction in the data which allows us to differentiate adequately between the groups.

The Canonical Analysis performed here on the Fisher Iris data assumes two directions are required, calculates those directions, and then, if requested, the canonical plot plots the data in these two dimensions, and provides the 95% confidence regions for the group means. (These regions are in fact circles as the canonical variates are standardised – you can adjust the ratio of the graph produced accordingly.)

db.s.CanonicalAnalysis
      db.s.CanonicalVectors
 0.829378  0.0241021
 1.53447   2.16452
¯2.20121  ¯0.931921
¯2.81046   2.83919
      db.s.EigenValues
32.1919 0.285391
      db.s.ScreeplotValues
1 0.991213
2 1

Finally, for the canonical plot:-

db.s.Canonicalplot


oostatshelp: Introduction

Introduction

This is the sort of tool that is useful if you want to investigate quickly any relationships between two quantitative variables with the possibility of a third factor variable influencing the relationship between the two variables (call them y and x). This facility allows you to do a straightforward scatterplot, then fit a regression line, introduce a factor variable that splits the data into groups, then see if separate regression lines are necessary. (This topic is called analysis of covariance.)

In addition, we are not limited to ordinary regression models, but can fit generalized linear models too. In the sections that follow, we look at a number of examples.


oostatshelp: Regression lines

Regression lines

Ultimately this scatterplot object is controlled by a gui form to allow an interactive session. However it may be started off from the session:-

 Open 'oostats/anorexia.adb'
Object 'db' has been created using s_db from file oostats/anorexia.adb
      db.VarNames
 before  after  group  _CSel  _CFreq
      db.Scatterplot 'after' 'before'
Created sub-object 's' using s_scatplot

The resulting screen is very much like it would be if you had chosen the scatterplot option from the gui version. With the tabbed sub-form to the left, you have the opportunity to specify other variables and specify a model. For example, variable groupspecifies the different groups of subjects through the values 1, 2, 3. Declare this as the factor variable and then re-plot will produce a plot using different symbols for the three groups:-

This picture should have a key – however, if we declare the variablegroup to be the thumbnail variable, then we can see which points belong to which group by clicking on a bar in the thumbnail barchart:-

If we wish to fit a regression model, we have a choice of linear or quadratic, one model for all groups, regression lines with different slopes (tick the regression at all levels), or regression lines with different slopes and intercepts (tick both regression and intercepts at all levels) and press the button Fit-Plot.

With the thumbnail still selecting the first (Control group) it is clear that this is behaving very differently to the other two.


oostatshelp: Fitting a Logistic Regression Model

Fitting a Logistic Regression Model

The database oostats/drug2.adb is a manufactured database where the y-variable – number cured, is plotted against the dose. The database contains information for males and females so we can produce a scatterplot and indicate the female points:-

In this case, there are the same number of subjects in each dose level, so we can see that the chance of being cured generally increases to a maximum and then decreases, but the beahviour of males is different to that for females.

To try to fit this data, we choose a logistic regression model with a quadratic predictor using dose, and allow the predictor to be different for each group – the complicated part of this is to decide to choose a Binomial error, in which case, you need to specify the Binomial n-variable to be nvar.

As you can see the model is moderately satisfactory in explaining the data. If details of the model fit are required, then you can use the two tip fields at the top of the model specification form to output information:-


oostatshelp: Output of Information from OOStats

Output of Information from OOStats

Clearly, it is important to be able to extract information from a session using OOStats. There are two ways in which this may be done.

Session Printer File

Unless you decide otherwise, all output is automatically sent to a session print file whose name is stored in the variable #.PrintFile and is by default oostats\prtfile.dcf. This can be printed at the end of a session. If you wish to save the output for future reference, the Causeway viewer gives you the option of saving as a Direct PostScript fie (*.ps) – if such a file is opened using the Adobe Reader, then the latter will convert it to a *.pdf file.

Copying via the the clipboard

Any text output may be copied via the clipboard to a Word document. Use a fixed font to preserve the layout of tables. Similarly, any graph my be copied from the Causeway viewer of the graph (see the View menu)


oostatshelp: Simple Time Series Analyis

Simple Time Series Analyis

This facility includes some simple time-series statistics and simple Box-Jenkins model fitting.


oostatshelp: Introduction

Introduction

The topic of time-series is in some ways the most complicated and controversial of all topics in Statistics. There are some very sophisticated modelling techniques such as Bayesian Time Series analysis that are beyond the scope of this software. However, we do provide calculations of autocorrelations, partial autocorrelations, a time-series plot and some simple Box-Jenjkins analysis programmes. More may be added ata later date.


oostatshelp: Autocorrelations

Autocorrelations

A first step analysis of a time-series would be to plot it, calculate autocorrelations for different lags, and also partial autocorrelations. We illustrate these facilities using Box-Jenkins Series A.

Open 'c:\oostats\BJSA.adb'
Object 'db' has been created using s_db from file c:\oostats\BJSA.adb
      db.TimeSeries 'bjsa'
Sub-object s created using s_ts
      db.s.Plot

The tryptich consists of the time-series itself, and bar-charts with 95% confidence bounds for the autocorrelations and partial-autocorrelations.

These may be obtained as a table with the commands:-

Tab db.s.Acf 10
 Lag  Autocorrelation
   1         0.570165
   2         0.495061
   3         0.397952
   4         0.355696
   5         0.326883
   6         0.349762
   7         0.391886
   8         0.321503
   9         0.304133
  10         0.254874

or

Tab db.s.Pacf 10
 Lag  Partial Autocorrelation
   1               0.570165
   2               0.251845
   3               0.0683106
   4               0.0692777
   5               0.0657869
   6               0.123656
   7               0.156279
   8              ¯0.0317185
   9               0.00976372
  10              ¯0.0163838


oostatshelp: Box-Jenkins Models

Box-Jenkins Models

Some simple Box-Jenkins models may be fitted using simple commands.

For an auto-regressive model (AR), use the command:-

     Tab db.s.ARModel 1
 Parameter   Estimate  Std Error
 MU         17.0267    0.0509527
 ⌽1          0.550446  0.0598582
      db.s.VarEst
Variance Estimate=         0.09253

where the right argument specifies the maximum lag in the autoregressiive model to be used.

For a moviing average model (MA):-

     Tab db.s.MAModel 1
 Parameter   Estimate  Std Error
 MU         17.0089    0.0328137
 ⊖1         ¯0.344605  0.0669888
     db.s.VarEst
Variance Estimate=         0.10211

and for an auto-regressive moving average model:-

      Tab db.s.ARMAModel 1 1
 Parameter   Estimate  Std Error
 MU         17.0039    0.106075
 ⌽1          0.931162  0.0358897
 ⊖1          0.649752  0.0757908

     db.s.VarEst
Variance Estimate=         0.07759

Here the right argument specifies the order of the auto-regressive part and moving average part in that order.


oostatshelp: Extending OOStats

Extending OOStats

This chapter discusses the basic structure of OOStats to help you to consider adding/extending it.


oostatshelp: How to add to OOStats

How to add to OOStats

All statistical object codes are stored with names begiining with s_. The database code is stored in s_db and the gui wrap in s_guidb. Within s_db there are statistical methods which create sub-objects db.s. For example, the statistcal method db.TimeSeries consists of the code:-

    ∇ r←TimeSeries vn;c;f;data
      :Access Public
    ⍝ simple univariate time series analysis
      r←'' ⋄ #.ETON
      :If vn≡''
          vn←#.gui.GetVarFromList VarNames
      :EndIf
      :If vn≡''
          →0
      :EndIf
      c←VarNames⍳⊂vn
      #.EM←(c>⍴VarNames)/#.Error 3 ⋄ →(#.E)/0
      f←(Filter,VarNames[c])∧_CSel
      :If 0<+/f=0
          #.EM←'Error:- Variable contains missing values' ⋄ →(#.E)/0
      :EndIf
      :If IsNonNumeric f/c⊃Vars
      :EndIf
      s←⎕NEW #.s_ts((c⊃Vars)(c⊃VarNames))
      →E2/0
      r←'Sub-object s created using s_ts'
    ∇

A crucial remit of this code is to filter out any missing values; in addition, some obvious errors, such as a variable not existing, are tested for and reported back. This works by returning a text result of the form'Error:- ...' which is tested for in the statement→#.E/0.

Writing the new statistical method code

This is basically straightforward, remembering that anything that you want the user to have access to must be declared public. Once you have established the constructor and one or two methods/fields, you can test it on some data.

If a method returns a table of results, this should be a two element vector, consisting of a vector of column headings and amatrixof results.

For graphical methods, construct a ‘PG’ vector using Adrian Smith’s ch namespace and return this postscp vector as a shy result. Since graphs are exhibited strraight from a console command or from within the gui environment, use the structure as exemplified by the Rankitplotin s_unistats:-

    ∇ {res}←Rankitplot;o;y;x;bds;f
      :Access Public
      cs←ChartSize⊃#.chartsize
      o←⍋y←(Values-Mean)÷StDev ⋄ y←y[o] ⋄ f←Freq[o] ⋄ x←#.Freq.Normquantile((+\f)-0.375)÷(+/f)-0.25
      pgr←cs'Rankit Plot with 1 in 20 Bounds' 'Rankits of Residuals' ' '#.Freq.∆rankitplot x(f/y)(((+/f),1)⍴1)
      :If PGVec
          res←pgr
      :Else
          cs #.gui.gform1'#.rp' 'Rankit plot of residuals'
      ⍝ have to establish menubars here
          ('#.rp.m')⎕WC'Menubar' ⋄ ('#.rp.m.v')⎕WC'MenuItem' '&View'('Event' 'Select' 'Viewr')
          '#.rp'#.gui.gform2 pgr
      :EndIf

Here, PGVecequals 1 if the graphics command postscript vector is to be passed on, whereasPGVec=0 indicates it is to be sent directly to a form.

When the new method has been established, you need to create annotated output to add words of explanation to the output. This is done through a Script nested matrix stored in #.Ed. For exanple, the time-series script matrix is:-

#.Ed.ts
1 1  Heading                   1   2  Heading
1 1  Acf        No lags←10     1   2  'Autocorrelation Table'
                               1   4  Acf ra
1 1  Pacf       No lags←10      1  2  'Partial Autoccorrelation table'
                               1   4  Pacf ra
1 0  ARModel    ar←1           1   2  'Autoregressive Model fit'
                               1   4  ARModel ra
                               1   3  VarEst
1 0  MAModel    ma←1           1   2  'Moving Average Model Fit'
                               1   4  MAModel ra
                               1   3  VarEst
1 0  ARMAModel  ar ma←1 1      1   2  'Autoregressive/MovingAverage ModelFit'
                               1   4  ARMAModel ra
                               1   3  VarEst
1 1  Plot                      PGVec   5  Plot
                               ~PGVec  0  Plot

Each row corresponds to a method or field from the statistical object. The first element is currently always set to 1, whereas the second element is 1 or 0 depending on whether you want this to be a default choice when using the command#.Explore db.s. Next comes a label corresponding (exactly – my choice) to the method it is to invoke in db.s. The next field specifies text indicating the right argument to the method – leave blank if thiere isn’t one. I usually give some indication what this right argument is by some text and even a default value, such as for the Ttest in the Unistats object where I have hv←0 to indicate that the user has to specify a hypothesis value which may be zero. Left arguments, if they exist are a set of options, specified by a string with commas to separate the options such as, for example, in the Hist method we have

'Normal,Exponential,Gamma,Lognormal,Density,Density Only'

The final element of a row is itself a nested matrix, each row of which consists of:-

ane xecutable condition

a choice of type of object

code to be executed (so text to be printed must be in quotes)

Since this is rather complicated, a special nested matrix editor is provide in the namespace Ed. To use it, type:-

)Cs Ed
#.Ed
      q←Edit ''

Use the button in the last column to enter the matrix details for that row:-

Having established that your new statistical method works adequately using #.Explore, the final step is to make the new method available from the gui wrap. You will need to add to the Menu structure, and provide code that provides a gui sub-form to select the variables to create db.s. For example, for the TwoSampleMeans method, the appropriate code in s_guidb is as follows:-

:Case 'tst'  ⍝ two sample t
              #.mf.l.tc.a.Caption←'Two-sample analysis'
              '#.mf.l.tc.app.l'⎕WC'label' 'Starred fields are mandatory'(2 5)
              '#.mf.l.tc.app.lv'⎕WC'label' '*  Choose the target variable'(8 2)
              '#.mf.l.tc.app.v'⎕WC'Combo'('Items'(VarNames))('size'(20 40))('posn'(12 2))
              '#.mf.l.tc.app.l1'⎕WC'label' '* Define group 1'('posn' 18 2)
              '#.mf.l.tc.app.g1'⎕WC'Edit'('posn' 22 2)('size' 4 60)('Font'caus)
              ListVars'#.mf.l.tc.app.g1'
              '#.mf.l.tc.app.l2'⎕WC'label' '* Define group 2'('posn' 28 2)
              '#.mf.l.tc.app.g2'⎕WC'Edit'('posn' 32 2)('size' 4 60)('Font'caus)
              '#.mf.l.tc.app.g2'⎕WS'Event' 'Select' 'CreateTwoSampleObject'
              ListVars'#.mf.l.tc.app.g2'
              '#.mf.l.tc.app.b'⎕WC'button'('Analyse')('posn' 95 75)('Size' 5 25)('Event' 'Select' 'CreateTwoSampleObject')
               CloseButton

within the DoMenu method

and

    ∇ CreateTwoSampleObject;c;gp1;gp2;q;yvarname
      #.ETON
      c←#.mf.l.tc.app.v.SelItems
      EM←(0=+/c)/#.Error 1 ⋄ →#.E/0
      yvarname←⊃('#.mf.l.tc.app.v'⎕WG'SelItems')/VarNames
      gp1←'#.mf.l.tc.app.g1'⎕WG'text'
      gp2←'#.mf.l.tc.app.g2'⎕WG'text'
      q←TwoSampleMeans yvarname gp1 gp2
      →E2/0
      OptionForm
    ∇

to create the actual object.