4 Replies Latest reply on Aug 31, 2016 10:50 AM by Sam Cheadle

Comparison of test statistic with critical value (chi squared test)

Hello,

I am aiming to carry out a chi-squared test within Tableau (without using the R link up), and have followed this useful method....

However, this method stops short of providing a test result. Once the test statistic has been calculated (chi-squared value in my case), this needs to be compared with a critical value, determining whether the result is statistical significant or not. This critical value is dependent on the degrees of freedom or DF (for chi squared, related to the number of rows and columns of the test data).

Is it possible to link to a separate data-source containing the critical values for a range of DFs (linked based on the DF value)? Testing this so far has failed, I believe because the DF value is a measure (calculated field), rather than a dimension.

I think the only other option is to calculate the critical value directly, based on the chi-squared distribution. However, a factorial function is necessary for this, which is not currently available in Tableau.

Many thanks,

Sam

• 1. Re: Comparison of test statistic with critical value (chi squared test)

Your first idea (linking the separate data source) would be the way I would go. You can just right click the DF field and convert it to a dimension to use it as a linking field.

The other (more laborious) option would be to create a calculated field like

IF [DF]=5 THEN X critical value

ELSEIF [DF]=6 THEN Y critical value

ELSEIF [DF]=7 THEN Z critical value

.

.

.

etc.
END

• 2. Re: Comparison of test statistic with critical value (chi squared test)

I kind of like your second suggestion. Copying a table into excel and concatenating some text takes about 30 seconds.

Example for p=.1

if [DF] = 1 then 2.706

elseif [DF] = 2 then 4.605

elseif [DF] = 3 then 6.251

elseif [DF] = 4 then 7.779

elseif [DF] = 5 then 9.236

elseif [DF] = 6 then 10.645

elseif [DF] = 7 then 12.017

elseif [DF] = 8 then 13.362

elseif [DF] = 9 then 14.684

elseif [DF] = 10 then 15.987

elseif [DF] = 11 then 17.275

elseif [DF] = 12 then 18.549

elseif [DF] = 13 then 19.812

elseif [DF] = 14 then 21.064

elseif [DF] = 15 then 22.307

elseif [DF] = 16 then 23.542

elseif [DF] = 17 then 24.769

elseif [DF] = 18 then 25.989

elseif [DF] = 19 then 27.204

elseif [DF] = 20 then 28.412

elseif [DF] = 21 then 29.615

elseif [DF] = 22 then 30.813

elseif [DF] = 23 then 32.007

elseif [DF] = 24 then 33.196

elseif [DF] = 25 then 34.382

elseif [DF] = 26 then 35.563

elseif [DF] = 27 then 36.741

elseif [DF] = 28 then 37.916

elseif [DF] = 29 then 39.087

elseif [DF] = 30 then 40.256

elseif [DF] = 31 then 41.422

elseif [DF] = 32 then 42.585

elseif [DF] = 33 then 43.745

elseif [DF] = 34 then 44.903

elseif [DF] = 35 then 46.059

elseif [DF] = 36 then 47.212

elseif [DF] = 37 then 48.363

elseif [DF] = 38 then 49.513

elseif [DF] = 39 then 50.66

elseif [DF] = 40 then 51.805

elseif [DF] = 41 then 52.949

elseif [DF] = 42 then 54.09

elseif [DF] = 43 then 55.23

elseif [DF] = 44 then 56.369

elseif [DF] = 45 then 57.505

elseif [DF] = 46 then 58.641

elseif [DF] = 47 then 59.774

elseif [DF] = 48 then 60.907

elseif [DF] = 49 then 62.038

elseif [DF] = 50 then 63.167

elseif [DF] = 51 then 64.295

elseif [DF] = 52 then 65.422

elseif [DF] = 53 then 66.548

elseif [DF] = 54 then 67.673

elseif [DF] = 55 then 68.796

elseif [DF] = 56 then 69.919

elseif [DF] = 57 then 71.04

elseif [DF] = 58 then 72.16

elseif [DF] = 59 then 73.279

elseif [DF] = 60 then 74.397

elseif [DF] = 61 then 75.514

elseif [DF] = 62 then 76.63

elseif [DF] = 63 then 77.745

elseif [DF] = 64 then 78.86

elseif [DF] = 65 then 79.973

elseif [DF] = 66 then 81.085

elseif [DF] = 67 then 82.197

elseif [DF] = 68 then 83.308

elseif [DF] = 69 then 84.418

elseif [DF] = 70 then 85.527

elseif [DF] = 71 then 86.635

elseif [DF] = 72 then 87.743

elseif [DF] = 73 then 88.85

elseif [DF] = 74 then 89.956

elseif [DF] = 75 then 91.061

elseif [DF] = 76 then 92.166

elseif [DF] = 77 then 93.27

elseif [DF] = 78 then 94.374

elseif [DF] = 79 then 95.476

elseif [DF] = 80 then 96.578

elseif [DF] = 81 then 97.68

elseif [DF] = 82 then 98.78

elseif [DF] = 83 then 99.88

elseif [DF] = 84 then 100.98

elseif [DF] = 85 then 102.079

elseif [DF] = 86 then 103.177

elseif [DF] = 87 then 104.275

elseif [DF] = 88 then 105.372

elseif [DF] = 89 then 106.469

elseif [DF] = 90 then 107.565

elseif [DF] = 91 then 108.661

elseif [DF] = 92 then 109.756

elseif [DF] = 93 then 110.85

elseif [DF] = 94 then 111.944

elseif [DF] = 95 then 113.038

elseif [DF] = 96 then 114.131

elseif [DF] = 97 then 115.223

elseif [DF] = 98 then 116.315

elseif [DF] = 99 then 117.407

elseif [DF] = 100 then 118.498

elseif [DF] = 101 then 119.589

elseif [DF] = 102 then 120.679

elseif [DF] = 103 then 121.769

elseif [DF] = 104 then 122.858

elseif [DF] = 105 then 123.947

elseif [DF] = 106 then 125.035

elseif [DF] = 107 then 126.123

elseif [DF] = 108 then 127.211

elseif [DF] = 109 then 128.298

elseif [DF] = 110 then 129.385

elseif [DF] = 111 then 130.472

elseif [DF] = 112 then 131.558

elseif [DF] = 113 then 132.643

elseif [DF] = 114 then 133.729

elseif [DF] = 115 then 134.813

elseif [DF] = 116 then 135.898

elseif [DF] = 117 then 136.982

elseif [DF] = 118 then 138.066

elseif [DF] = 119 then 139.149

elseif [DF] = 120 then 140.233

elseif [DF] = 121 then 141.315

elseif [DF] = 122 then 142.398

elseif [DF] = 123 then 143.48

elseif [DF] = 124 then 144.562

elseif [DF] = 125 then 145.643

elseif [DF] = 126 then 146.724

elseif [DF] = 127 then 147.805

elseif [DF] = 128 then 148.885

elseif [DF] = 129 then 149.965

elseif [DF] = 130 then 151.045

elseif [DF] = 131 then 152.125

elseif [DF] = 132 then 153.204

elseif [DF] = 133 then 154.283

elseif [DF] = 134 then 155.361

elseif [DF] = 135 then 156.44

elseif [DF] = 136 then 157.518

elseif [DF] = 137 then 158.595

elseif [DF] = 138 then 159.673

elseif [DF] = 139 then 160.75

elseif [DF] = 140 then 161.827

elseif [DF] = 141 then 162.904

elseif [DF] = 142 then 163.98

elseif [DF] = 143 then 165.056

elseif [DF] = 144 then 166.132

elseif [DF] = 145 then 167.207

elseif [DF] = 146 then 168.283

elseif [DF] = 147 then 169.358

elseif [DF] = 148 then 170.432

elseif [DF] = 149 then 171.507

elseif [DF] = 150 then 172.581

elseif [DF] = 151 then 173.655

elseif [DF] = 152 then 174.729

elseif [DF] = 153 then 175.803

elseif [DF] = 154 then 176.876

elseif [DF] = 155 then 177.949

elseif [DF] = 156 then 179.022

elseif [DF] = 157 then 180.094

elseif [DF] = 158 then 181.167

elseif [DF] = 159 then 182.239

elseif [DF] = 160 then 183.311

elseif [DF] = 161 then 184.382

elseif [DF] = 162 then 185.454

elseif [DF] = 163 then 186.525

elseif [DF] = 164 then 187.596

elseif [DF] = 165 then 188.667

elseif [DF] = 166 then 189.737

elseif [DF] = 167 then 190.808

elseif [DF] = 168 then 191.878

elseif [DF] = 169 then 192.948

elseif [DF] = 170 then 194.017

elseif [DF] = 171 then 195.087

elseif [DF] = 172 then 196.156

elseif [DF] = 173 then 197.225

elseif [DF] = 174 then 198.294

elseif [DF] = 175 then 199.363

elseif [DF] = 176 then 200.432

elseif [DF] = 177 then 201.5

elseif [DF] = 178 then 202.568

elseif [DF] = 179 then 203.636

elseif [DF] = 180 then 204.704

elseif [DF] = 181 then 205.771

elseif [DF] = 182 then 206.839

elseif [DF] = 183 then 207.906

elseif [DF] = 184 then 208.973

elseif [DF] = 185 then 210.04

elseif [DF] = 186 then 211.106

elseif [DF] = 187 then 212.173

elseif [DF] = 188 then 213.239

elseif [DF] = 189 then 214.305

elseif [DF] = 190 then 215.371

elseif [DF] = 191 then 216.437

elseif [DF] = 192 then 217.502

elseif [DF] = 193 then 218.568

elseif [DF] = 194 then 219.633

elseif [DF] = 195 then 220.698

elseif [DF] = 196 then 221.763

elseif [DF] = 197 then 222.828

elseif [DF] = 198 then 223.892

elseif [DF] = 199 then 224.957

elseif [DF] = 200 then 226.021

elseif [DF] = 201 then 227.085

elseif [DF] = 202 then 228.149

elseif [DF] = 203 then 229.213

elseif [DF] = 204 then 230.276

elseif [DF] = 205 then 231.34

elseif [DF] = 206 then 232.403

elseif [DF] = 207 then 233.466

elseif [DF] = 208 then 234.529

elseif [DF] = 209 then 235.592

elseif [DF] = 210 then 236.655

elseif [DF] = 211 then 237.717

elseif [DF] = 212 then 238.78

elseif [DF] = 213 then 239.842

elseif [DF] = 214 then 240.904

elseif [DF] = 215 then 241.966

elseif [DF] = 216 then 243.028

elseif [DF] = 217 then 244.09

elseif [DF] = 218 then 245.151

elseif [DF] = 219 then 246.213

elseif [DF] = 220 then 247.274

elseif [DF] = 221 then 248.335

elseif [DF] = 222 then 249.396

elseif [DF] = 223 then 250.457

elseif [DF] = 224 then 251.517

elseif [DF] = 225 then 252.578

elseif [DF] = 226 then 253.638

elseif [DF] = 227 then 254.699

elseif [DF] = 228 then 255.759

elseif [DF] = 229 then 256.819

elseif [DF] = 230 then 257.879

elseif [DF] = 231 then 258.939

elseif [DF] = 232 then 259.998

elseif [DF] = 233 then 261.058

elseif [DF] = 234 then 262.117

elseif [DF] = 235 then 263.176

elseif [DF] = 236 then 264.235

elseif [DF] = 237 then 265.294

elseif [DF] = 238 then 266.353

elseif [DF] = 239 then 267.412

elseif [DF] = 240 then 268.471

elseif [DF] = 241 then 269.529

elseif [DF] = 242 then 270.588

elseif [DF] = 243 then 271.646

elseif [DF] = 244 then 272.704

elseif [DF] = 245 then 273.762

elseif [DF] = 246 then 274.82

elseif [DF] = 247 then 275.878

elseif [DF] = 248 then 276.935

elseif [DF] = 249 then 277.993

elseif [DF] = 250 then 279.05

else null end

• 3. Re: Comparison of test statistic with critical value (chi squared test)

Here is an example of the factorial function in Tableau, using Table Calc's, that may or may not help.

Regards,

Gerardo

• 4. Re: Comparison of test statistic with critical value (chi squared test)

Thanks very much for the replies.

I'm not able to convert the DF field into a dimension (possibly because it is a calculated field?), so I am unable to link the critical value data-source.

I like the idea of a calculated field with a series of if else statements. That would work.

Thanks also for also for the factorial function info!

Cheers

Sam