ComputeA: Computes the marginal matrix A and margins vector m of an...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/utils.R

Description

Given a set of marginal target constraints and the dimension of the array X to wich the targets relate to, this function computes the matrix A of full rank and vector m such that

t(A) * p = t(c(m, 1))

where vector m contains all components but one of every target and p is a vector of the (unknow) components of X.

Usage

1
ComputeA(dim.arr, target.list, target.data)

Arguments

dim.arr

The dimension of the array X to which the margins are applied.

target.list

A list of the target margins provided in target.data. Each component of the list is an array whose cells indicates which dimension the corresponding margin relates to.

target.data

A list containing the data of the target margins. Each component of the list is an array storing a margin. The list order must follow the one defined in target.list. Note that the cells of the arrays must be non-negative.

Value

A list whose elements are defined below.

marginal.matrix

The marginal matrix.

margins

A vector containing the margins associated with A.

df

The degree of freedom of the problem.

Author(s)

Johan Barthelemy

Maintainer: Johan Barthelemy <johan@uow.edu.au>.

See Also

MarginalMatrix.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# loading the data
data(spnamur, package = "mipfp")
# subsetting the data frame, keeping only the first 3 variables
spnamur.sub <- subset(spnamur, select = Household.type:Prof.status)
# true table
true.table <- table(spnamur.sub)
# extracting the margins
tgt.v1        <- apply(true.table, 1, sum)
tgt.v1.v2     <- apply(true.table, c(1,2), sum)
tgt.v2.v3     <- apply(true.table, c(2,3), sum)
tgt.list.dims <- list(1, c(1,2), c(2,3))
tgt.data      <- list(tgt.v1, tgt.v1.v2, tgt.v2.v3)
# creating the seed, a 10 pct sample of spnamur
seed.df <- spnamur.sub[sample(nrow(spnamur), round(0.10*nrow(spnamur))), ]
seed.table <- table(seed.df)
# computing the associated marginal matrix and margins vector
res.marg <- ComputeA(dim(seed.table), tgt.list.dims, tgt.data)
print(res.marg)

Example output

Loading required package: cmm
Loading required package: Rsolnp
Loading required package: numDeriv
$marginal.matrix
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
 [1,]    1    0    0    0    0    0    0    0    0     0     0     0
 [2,]    1    0    0    0    0    0    0    0    1     0     0     0
 [3,]    1    0    0    0    0    0    0    0    0     1     0     0
 [4,]    1    0    0    0    1    0    0    0    0     0     1     0
 [5,]    1    0    0    0    1    0    0    0    0     0     0     1
 [6,]    1    0    0    0    1    0    0    0    0     0     0     0
 [7,]    1    1    0    0    0    1    0    0    0     0     0     0
 [8,]    1    1    0    0    0    1    0    0    1     0     0     0
 [9,]    1    1    0    0    0    1    0    0    0     1     0     0
[10,]    1    1    0    0    0    0    0    0    0     0     1     0
[11,]    1    1    0    0    0    0    0    0    0     0     0     1
[12,]    1    1    0    0    0    0    0    0    0     0     0     0
[13,]    1    0    1    0    0    0    1    0    0     0     0     0
[14,]    1    0    1    0    0    0    1    0    1     0     0     0
[15,]    1    0    1    0    0    0    1    0    0     1     0     0
[16,]    1    0    1    0    0    0    0    0    0     0     1     0
[17,]    1    0    1    0    0    0    0    0    0     0     0     1
[18,]    1    0    1    0    0    0    0    0    0     0     0     0
[19,]    1    0    0    1    0    0    0    1    0     0     0     0
[20,]    1    0    0    1    0    0    0    1    1     0     0     0
[21,]    1    0    0    1    0    0    0    1    0     1     0     0
[22,]    1    0    0    1    0    0    0    0    0     0     1     0
[23,]    1    0    0    1    0    0    0    0    0     0     0     1
[24,]    1    0    0    1    0    0    0    0    0     0     0     0

$margins
                    F          I          N                                  
1.00000000 0.49821374 0.14805982 0.12890506 0.11227767 0.24842277 0.08295645 
                                                       
0.07862382 0.11447248 0.25914982 0.20471648 0.11465301 

$df
[1] 12

mipfp documentation built on May 2, 2019, 6:01 a.m.