After using `eh_test_subtype()`

to obtain a model fit, if factor variables are involved in the analysis it will be of interest to obtain overall p-values testing for differences across subtypes across all levels of the factor variable.

The `posthoc_factor_test()`

function allows for post-hoc testing of a factor variable.

```
# Load needed packages
library(riskclustr)
library(dplyr)
```

```
# create a new example dataset that contains a factor variable
<-
factor_data %>%
subtype_data mutate(
x4 = cut(
x1,breaks = c(-3.4, -0.4, 0.3, 1.1, 3.8),
include.lowest = T,
labels = c("1st quart",
"2nd quart",
"3rd quart",
"4th quart")
) )
```

```
# Fit the model using x4 in place of x1
<- eh_test_subtype(
mod1 label = "subtype",
M = 4,
factors = list("x4", "x2", "x3"),
data = factor_data,
digits = 2
)
```

After we have the model fit, we can obtain the p-value testing all levels of `x4`

simulaneously.

```
<- posthoc_factor_test(
mypval fit = mod1,
factor = "x4",
nlevels = 4
)
```

The function returns both a formatted and unformatted p-value. The formatted p-value can be accessed as `pval`

:

```
$pval
mypval#> [,1]
#> [1,] "<.001"
```

The unformatted p-value can be accessed as `pval_raw`

:

```
$pval_raw
mypval#> [,1]
#> [1,] 0
```