Language Reference |
evaluates marginal totals in a multiway contingency table
The matrix table must conform in size to the contingency table specified in dim. In particular, if table is , the product of the entries in the dim vector must equal . In addition, there must be some integer such that the product of the first entries in dim equals . See the description of the IPF function for more information about specifying table.
For example, consider the three-dimensional table discussed in the IPF call, based on data appearing in Christensen (1997). The table presents data on a person's self-esteem for people classified according to their religion and their father's educational level.
Father's Educational Level | ||||||
Self- | Not HS | HS | Some | Coll | Post | |
Religion | Esteem | Grad | Grad | Coll | Grad | Coll |
High | 575 | 388 | 100 | 77 | 51 | |
Catholic | ||||||
Low | 267 | 153 | 40 | 37 | 19 | |
High | 117 | 102 | 67 | 87 | 62 | |
Jewish | ||||||
Low | 48 | 35 | 18 | 12 | 13 | |
High | 359 | 233 | 109 | 197 | 90 | |
Protestant | ||||||
Low | 159 | 173 | 47 | 82 | 32 |
As explained in the IPF documentation, the father's education level is Variable 1, self-esteem is Variable 2, and religion is Variable 3.
The following program encodes this table, uses the MARG call to compute a 2-way marginal table by summing over the third variable and a 1-way marginal by summing over the first two variables.
dim={5 2 3}; table={ /* Father's Education: NotHSGrad HSGrad Col ColGrad PostCol Self- Relig Esteem */ /* Cath- Hi */ 575 388 100 77 51, /* olic Lo */ 267 153 40 37 19, /* Jew- Hi */ 117 102 67 87 62, /* ish Lo */ 48 35 18 12 13, /* Prote- Hi */ 359 233 109 197 90, /* stant Lo */ 159 173 47 82 32 };
config = { 1 3, 2 0 }; call marg(locmar, marginal, dim, table, config); print locmar, marginal; /* Examine marginals: The name indicates the variable(s) that are NOT summed over. The locmar variable tells where to index into the marginal variable. */ Var12_Marg = marginal[1:(locmar[2]-1)]; Var12_Marg = shape(Var12_Marg,dim[2],dim[1]); Var3_Marg = marginal[locMar[2]:ncol(marginal)];
The results of this program are as follows:
LOCMAR 1 11 MARGINAL COL1 COL2 COL3 COL4 COL5 COL6 COL7 ROW1 1051 723 276 361 203 474 361 MARGINAL COL8 COL9 COL10 COL11 COL12 COL13 ROW1 105 131 64 1707 561 1481
VAR12_MARG 1051 723 276 361 203 474 361 105 131 64 VAR3_MARG 1707 561 1481
The first marginal total is contained in locations 1 through 10 of the marginal vector. It represents the results of summing table over the religion variable. The first entry of marginal is the number of subjects with high self-esteem whose fathers did not graduate from high school (). The second entry is the number of subjects with high self-esteem whose fathers were high school graduates (). The tenth entry is the number of subjects with low self-esteem whose fathers had some post-collegiate education ().
The second marginal is contained in locations 11 through 13 of the marginal vector. It represents the results of summing table over the education and self-esteem variables. The eleventh entry of the marginal vector is the number of Catholics in the study. The thirteenth entry is the number of Protestants.
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.