View source: R/plot.chisqtest.R

plotchisqtest | R Documentation |

`\chi^2`

test graphically.This function plots the density probability distribution of a `\chi^2`

statistic, with a vertical cutline at the observed `\chi^2`

value specified. The p-value and the observed `\chi^2`

value are plotted. Although largely customizable, only two arguments are required (the observed `\chi^2`

and the degrees of freedom).

```
plotchisqtest(
chisq,
df = chisq$parameter,
blank = FALSE,
xmax = "auto",
title = parse(text = expression(chi^2 ~ "Test")),
xlabel = parse(text = expression(chi^2)),
ylabel = "Density of probability\nunder the null hypothesis",
fontfamily = "serif",
colorleft = "aliceblue",
colorright = "firebrick3",
colorleftcurve = "black",
colorrightcurve = "black",
colorcut = "black",
colorplabel = colorright,
theme = "default",
signifdigitschisq = 3,
curvelinesize = 0.4,
cutlinesize = curvelinesize
)
```

`chisq` |
A numeric value indicating the observed |

`df` |
A numeric value indicating the degrees of freedom. This argument is optional if you are using an |

`blank` |
A logical that indicates whether to hide ( |

`xmax` |
A numeric including the maximum for the x-axis. Defaults to |

`title` |
A character or expression indicating a custom title for the plot (optional). |

`xlabel` |
A character or expression indicating a custom title for the x axis (optional). |

`ylabel` |
A character or expression indicating a custom title for the y axis (optional). |

`fontfamily` |
A character indicating the font family of all the titles and labels (e.g. |

`colorleft` |
A character indicating the color for the "left" area under the curve (optional). |

`colorright` |
A character indicating the color for the "right" area under the curve (optional). |

`colorleftcurve` |
A character indicating the color for the "left" part of the curve (optional). |

`colorrightcurve` |
A character indicating the color for the "right" part of the curve (optional). By default, for color consistency, this color is also passed to the label, but this can be changed by providing an argument for the |

`colorcut` |
A character indicating the color for the cut line at the observed test statistic (optional). |

`colorplabel` |
A character indicating the color for the label of the p-value (optional). By default, for color consistency, this color is the same as color of |

`theme` |
A character indicating one of the predefined color themes. The themes are |

`signifdigitschisq` |
A numeric indicating the number of desired significant figures reported for the |

`curvelinesize` |
A numeric indicating the size of the curve line (optional). |

`cutlinesize` |
A numeric indicating the size of the cut line (optional). By default, the size of the curve line is used. |

A plot with the density of probability of `\chi^2`

under the null hypothesis, annotated with the observed test statistic and the p-value.

Nils Myszkowski <nmyszkowski@pace.edu>

```
#Making a chi-squared plot with Chi-squared of 8 and df of 4
plotchisqtest(chisq = 8, df = 4)
#Note that the same can be obtained even quicker with:
plotchisqtest(8,4)
#The same plot without the Chi-Squared or p value
plotchisqtest(8,4, blank = TRUE)
#Plot using a chisq.test()
test <- chisq.test(c(A = 37, B = 18, C = 25))
plotchisqtest(test)
#Plot from anova() model comparison
set.seed(1)
y <- rbinom(10, 1, .4) ; x <- 2*y + rnorm(10)
fit1 <- glm(y ~ 1, family = binomial)
fit2 <- glm(y ~ x, family = binomial)
comp <- anova(fit1, fit2, test = "Chisq")
plotchisqtest(comp)
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.