Produce Cutpoint Multinomial Data
makemultdata.RdChange data into a matrix of multinomial counts using the cutpoint method and generate EM algorithm starting values for a k-component mixture of multinomials.
Arguments
- ...
Either vectors (possibly of different lengths) of raw data or an nxm matrix (or data frame) of data. If
...are vectors of varying length, thenmakemultdatawill create a matrix of size nxm where n is the sample size and m is the length of the vector with maximum length. Those vectors with length less than m will haveNAs to make the corresponding row in the matrix of length m. If...is a matrix (or data frame), then the rows must correspond to the sample and the columns the repeated measures.- cuts
A vector of cutpoints. This vector is sorted by the algorithm.
Value
makemultdata returns an object which is a list with components:
- x
An nxm matrix of the raw data.
- y
An nxp matrix of the discretized data where p is one more than the number of cutpoints. Each row is a multinomial vector of counts. In particular, each row should sum to the number of repeated measures for that sample.
Details
The (i, j)th entry of the matrix y (for j < p)
is equal to the number of entries
in the ith column of x that are less than or equal to cuts[j].
The (i, p)th entry is equal to the number of entries greater than
cuts[j].
References
Elmore, R. T., Hettmansperger, T. P. and Xuan, F. (2004) The Sign Statistic, One-Way Layouts and Mixture Models, Statistical Science 19(4), 579–587.
Examples
## Randomly generated data.
set.seed(100)
y <- matrix(rpois(70, 6), 10, 7)
cuts <- c(2, 5, 7)
out1 <- makemultdata(y, cuts = cuts)
out1
#> $x
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] 5 7 6 6 5 5 6
#> [2,] 4 9 7 10 9 4 7
#> [3,] 6 4 6 5 8 4 11
#> [4,] 2 5 8 10 8 4 7
#> [5,] 6 8 5 7 6 6 5
#> [6,] 6 7 4 9 6 4 5
#> [7,] 8 4 8 4 8 3 6
#> [8,] 5 5 9 7 9 4 5
#> [9,] 6 5 6 12 4 6 4
#> [10,] 4 7 4 3 5 4 7
#>
#> $y
#> [,1] [,2] [,3] [,4]
#> [1,] 0 3 4 0
#> [2,] 0 2 2 3
#> [3,] 0 3 2 2
#> [4,] 1 2 1 3
#> [5,] 0 2 4 1
#> [6,] 0 3 3 1
#> [7,] 0 3 1 3
#> [8,] 0 4 1 2
#> [9,] 0 3 3 1
#> [10,] 0 5 2 0
#>
## The sulfur content of the coal seams in Texas.
A <- c(1.51, 1.92, 1.08, 2.04, 2.14, 1.76, 1.17)
B <- c(1.69, 0.64, .9, 1.41, 1.01, .84, 1.28, 1.59)
C <- c(1.56, 1.22, 1.32, 1.39, 1.33, 1.54, 1.04, 2.25, 1.49)
D <- c(1.3, .75, 1.26, .69, .62, .9, 1.2, .32)
E <- c(.73, .8, .9, 1.24, .82, .72, .57, 1.18, .54, 1.3)
out2 <- makemultdata(A, B, C, D, E,
cuts = median(c(A, B, C, D, E)))
out2
#> $x
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> [1,] 1.51 1.92 1.08 2.04 2.14 1.76 1.17 NA NA NA
#> [2,] 1.69 0.64 0.90 1.41 1.01 0.84 1.28 1.59 NA NA
#> [3,] 1.56 1.22 1.32 1.39 1.33 1.54 1.04 2.25 1.49 NA
#> [4,] 1.30 0.75 1.26 0.69 0.62 0.90 1.20 0.32 NA NA
#> [5,] 0.73 0.80 0.90 1.24 0.82 0.72 0.57 1.18 0.54 1.3
#>
#> $y
#> [,1] [,2]
#> [1,] 2 5
#> [2,] 4 4
#> [3,] 1 8
#> [4,] 6 2
#> [5,] 8 2
#>
## The reaction time data.
data(RTdata)
out3 <- makemultdata(RTdata, cuts =
100*c(5, 10, 12, 14, 16, 20, 25, 30, 40, 50))
dim(out3$y)
#> [1] 197 11
out3$y[1:10,]
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
#> [1,] 0 0 0 0 2 2 1 1 0 0 0
#> [2,] 0 0 0 1 1 1 2 0 1 0 0
#> [3,] 0 0 0 3 1 1 1 0 0 0 0
#> [4,] 0 0 0 0 0 5 0 0 1 0 0
#> [5,] 0 0 0 1 1 2 2 0 0 0 0
#> [6,] 0 0 0 0 0 1 3 1 1 0 0
#> [7,] 0 0 0 1 0 1 1 0 1 2 0
#> [8,] 0 0 0 0 3 2 0 1 0 0 0
#> [9,] 0 0 0 1 1 0 1 2 0 1 0
#> [10,] 0 0 0 1 2 2 0 0 1 0 0