# Chi-square command in ds.table gives error

**URL:** <https://datashield.discourse.group/t/chi-square-command-in-ds-table-gives-error/455>\
**Category:** Analyst Support\
**Created:** [28 September 2021 14:51 UTC](https://datashield.discourse.group/t/chi-square-command-in-ds-table-gives-error/455 "2021-09-28T14:51:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabriella\_m](https://avatars.discourse-cdn.com/v4/letter/g/5e9695/32.png) [@gabriella\_m](https://datashield.discourse.group/u/gabriella_m)\
**Post date:** [28 September 2021 14:51 UTC](https://datashield.discourse.group/t/chi-square-command-in-ds-table-gives-error/455/1 "2021-09-28T14:51:10Z")

</div>

Hello all, I am getting an error when asking the computation of the chi-square, any suggestion please?

- 

```
     ds.table(rvar="ext_pcbin_df$prepreg_dep",

```

- 

```
     cvar="ext_pcbin_df$eusilc_income_quintiles",

```

- 

```
     report.chisq.tests = TRUE,

```

- 

```
     exclude =c("NaN", "NA"), 

```

- 

```
     useNA= "no")

```

Data in all studies were valid

Study 1 : No errors reported from this study Study 2 : No errors reported from this study Study 3 : No errors reported from this study Study 4 : No errors reported from this study Study 5 : No errors reported from this study Study 6 : No errors reported from this study Study 7 : No errors reported from this study

- Error in stats::chisq.test(input.array.source.specific) : at least one entry of ‘x’ must be positive

Thanks

---

<div class="post-metadata">

**Author:** ![swheater](https://yyz2.discourse-cdn.com/free1/user_avatar/datashield.discourse.group/swheater/32/182_2.png) [@swheater](https://datashield.discourse.group/u/swheater)\
**Post date:** [28 September 2021 15:53 UTC](https://datashield.discourse.group/t/chi-square-command-in-ds-table-gives-error/455/2 "2021-09-28T15:53:42Z")

</div>

Hi Gabriella,

Could you let us know which version of dsBase and dsBaseClient you are using?

Regards, Stuart

---

<div class="post-metadata">

**Author:** ![gabriella\_m](https://avatars.discourse-cdn.com/v4/letter/g/5e9695/32.png) [@gabriella\_m](https://datashield.discourse.group/u/gabriella_m)\
**Post date:** [28 September 2021 16:27 UTC](https://datashield.discourse.group/t/chi-square-command-in-ds-table-gives-error/455/3 "2021-09-28T16:27:28Z")

</div>

Hi Stuart,

I have the following:

dsBaseClient\_6.1.0  
DSOpal\_1.1.0 DSI\_1.1.0  
R6\_2.4.0  
progress\_1.2.2  
opalr\_1.4.1  
httr\_1.4.2

but cannot see dsBase…

Thanks, Gabriella

---

<div class="post-metadata">

**Author:** ![demetris.avraam](https://avatars.discourse-cdn.com/v4/letter/d/439d5e/32.png) [@demetris.avraam](https://datashield.discourse.group/u/demetris.avraam)\
**Post date:** [28 September 2021 17:12 UTC](https://datashield.discourse.group/t/chi-square-command-in-ds-table-gives-error/455/4 "2021-09-28T17:12:53Z")

</div>

Hi Gabriella,

Here are the 1D tables for each one of those variables:

```auto
                  study
nonrep$prepreg_dep 1 2 3 4 5 6 7 8
                0 7057 96911 0 0 0 0 0 11458
                1 237 6791 0 0 0 0 0 1136
                NA 348 2343 96825 1678 18329 2868 2270 3051

```

```auto
                           study
nonrep$eusilc_income_quintiles 1 2 3 4 5 6 7 8
                            1 1402 18249 16368 308 2708 0 383 2158
                            2 1402 18058 16470 304 2709 0 387 2166
                            3 1402 17436 16370 304 2709 0 387 2152
                            4 1401 19287 16417 304 2709 0 385 2187
                            5 1404 0 16417 303 2709 0 385 2126
                            NA 631 33015 14783 155 4785 2868 343 4856

```

As you can see prepreg\_dep includes only NAs in studies 3 to 7 (those are dnbc, chop, elfe, raine, and inma in that order). So if you do a 2D table of the two variables for the other 3 studies (ninfea, moba and alspac) you can then get the results of the chi-squared test:

```auto
$chisq.tests
$chisq.tests$chisq.test_TABLE.STUDY.1_counts

	Pearson's Chi-squared test

data: input.array.source.specific
X-squared = 16.747, df = 4, p-value = 0.002165

$chisq.tests$chisq.test_TABLE.STUDY.2_counts

	Pearson's Chi-squared test

data: input.array.source.specific
X-squared = NaN, df = 4, p-value = NA

$chisq.tests$chisq.test_TABLE.STUDY.3_counts

	Pearson's Chi-squared test

data: input.array.source.specific
X-squared = 231.13, df = 4, p-value < 2.2e-16

$chisq.tests$chisq.test_TABLES.COMBINED_all.sources_counts

	Pearson's Chi-squared test

data: combine.array.all.sources
X-squared = 154.81, df = 4, p-value < 2.2e-16

$validity.message
[1] "Data in all studies were valid"

```

---

<div class="post-metadata">

**Author:** ![gabriella\_m](https://avatars.discourse-cdn.com/v4/letter/g/5e9695/32.png) [@gabriella\_m](https://datashield.discourse.group/u/gabriella_m)\
**Post date:** [28 September 2021 17:17 UTC](https://datashield.discourse.group/t/chi-square-command-in-ds-table-gives-error/455/5 "2021-09-28T17:17:09Z")

</div>

Great, thanks! I thought I was factoring out NAs through the commands exclude and useNA, but nope! Thanks again

---

<div class="post-metadata">

**Author:** ![alexsunny123](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@alexsunny123](https://datashield.discourse.group/u/alexsunny123)\
**Post date:** [13 December 2021 12:10 UTC](https://datashield.discourse.group/t/chi-square-command-in-ds-table-gives-error/455/6 "2021-12-13T12:10:27Z")

</div>

thanks for the awesome information.
