Skip to content

object 'predictor' not found & object 'contingencyTable' not found #2

Open
@zebrazoo

Description

@zebrazoo

Hi!
I'm using Andy Field's code and data from his stat book here, because it should be infallible. My session info is below using the R 4.5.0 console directly. The latest gmodels package 2.19.1 appears to be loaded in my system while getting these errors at the beginning of the tutorial, just after building the dataframe. This tutorial requires MASS and gmodels, but MASS_7.3-65 requires R 4.40 or greater and a newer version of Matrix. Thanks for looking into this!

CrossTable(predictor, outcome, fisher = TRUE, chisq = TRUE, expected = TRUE)
Error: object 'predictor' not found

CrossTable(contingencyTable, fisher = TRUE, chisq = TRUE, expected = TRUE)
Error: object 'contingencyTable' not found

Then, this line of code worked, although it appears to be missing values for Count - Std Residual in the top portion of the output:

CrossTable(catsData$Training, catsData$Dance, fisher = TRUE, chisq = TRUE, expected = TRUE, prop.c = FALSE, prop.t = FALSE, prop.chisq = FALSE, sresid = TRUE, format = "SPSS")
Cell Contents
|-------------------------|
| Count |
| Expected Values |
| Row Percent |
| Std Residual |
|-------------------------|

Total Observations in Table: 200

                             | catsData$Dance 

catsData$Training | No | Yes | Row Total |
------------------ --|-----------|-----------|-----------|
Affection as Reward | 114 | 48 | 162 |
| 100.440 | 61.560 | |
| 70.370% | 29.630% | 81.000% |
| 1.353 | -1.728 | |
--------------------|-----------|-----------|-----------|
Food as Reward | 10 | 28 | 38 |
| 23.560 | 14.440 | |
| 26.316% | 73.684% | 19.000% |
| -2.794 | 3.568 | |
--------------------|-----------|-----------|-----------|
Column Total | 124 | 76 | 200 |
--------------------|-----------|-----------|-----------|

Statistics for All Table Factors
Pearson's Chi-squared test

Chi^2 = 25.35569 d.f. = 1 p = 4.767434e-07
Pearson's Chi-squared test with Yates' continuity correction

Chi^2 = 23.52028 d.f. = 1 p = 1.236041e-06

Fisher's Exact Test for Count Data

Sample estimate odds ratio: 6.579265
Alternative hypothesis: true odds ratio is not equal to 1
p = 1.311709e-06
95% confidence interval: 2.837773 16.42969
Alternative hypothesis: true odds ratio is less than 1
p = 0.9999999
95% confidence interval: 0 14.25436
Alternative hypothesis: true odds ratio is greater than 1
p = 7.7122e-07
95% confidence interval: 3.193221 Inf

   Minimum expected frequency: 14.44 

SESSION INFO:
R version 4.5.0 (2025-04-11 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 26100)

Matrix products: default
LAPACK version 3.12.1

locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] MASS_7.3-65 gmodels_2.19.1

loaded via a namespace (and not attached):
[1] vctrs_0.6.5 cli_3.6.4 rlang_1.1.6 gdata_3.0.1 generics_0.1.3 gtools_3.9.5
[7] glue_1.8.0 colorspace_2.1-1 glmnet_4.1-8 scales_1.3.0 grid_4.5.0 munsell_0.5.1
[13] tibble_3.2.1 foreach_1.5.2 lifecycle_1.0.4 compiler_4.5.0 dplyr_1.1.4 codetools_0.2-20
[19] Rcpp_1.0.14 pkgconfig_2.0.3 lattice_0.22-6 R6_2.6.1 tidyselect_1.2.1 pillar_1.10.2
[25] splines_4.5.0 shape_1.4.6.1 magrittr_2.0.3 Matrix_1.7-3 tools_4.5.0 gtable_0.3.6
[31] iterators_1.0.14 survival_3.8-3 ggplot2_3.5.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions