Skip to contents

Compute the standardized Pearson residuals for a given \(I \times J\) contingency table.

Usage

get_std_pearson_res(contin_table)

Arguments

contin_table

A matrix of an \(I \times J\) contingency table.

Value

A matrix of the standardized Pearson residuals of the input contingency table.

Examples

# Create a 6 by 4 data matrix
set.seed(42)
dat_mat <- matrix(rpois(6 * 4, 20), nrow = 6)
dat_mat
#>      [,1] [,2] [,3] [,4]
#> [1,]   26   19   25   18
#> [2,]   17   29   24   12
#> [3,]   20   19   23   27
#> [4,]   15   25   22   21
#> [5,]   19   30   24   21
#> [6,]   26   13   16   18

# Check the format of the data matrix and assign row and column names
# to the data matrix
contin_table <- check_and_fix_contin_table(dat_mat)
contin_table
#>      drug_1 drug_2 drug_3 drug_4
#> AE_1     26     19     25     18
#> AE_2     17     29     24     12
#> AE_3     20     19     23     27
#> AE_4     15     25     22     21
#> AE_5     19     30     24     21
#> AE_6     26     13     16     18

# Compute the standardized Pearson residuals
get_std_pearson_res(contin_table)
#>          drug_1    drug_2      drug_3     drug_4
#> AE_1  1.2964248 -1.152311  0.48785428 -0.6206598
#> AE_2 -0.7929358  1.980521  0.66049322 -1.9625894
#> AE_3 -0.4107602 -1.217290 -0.11400275  1.8144605
#> AE_4 -1.4173509  0.811626  0.04067809  0.5479210
#> AE_5 -0.9913254  1.311559 -0.19363617 -0.1648137
#> AE_6  2.4694917 -1.822336 -0.92405981  0.3666991