This function uses the tinytable package to give a display of collinearity diagnostics with
shaded backgrounds indicating the severity of collinearity in the dimensions of the data
and the proportions of variance related to each variable in these dimensions. It gives
a table version of the graphic shown by tableplot, but something that
can be rendered in HTML, PDF and other formats.
Arguments
- x
A
"colldiag"object created from a linear model- digits
Number of digits to use when printing; set to 0 when
percent = TRUE- fuzz
Variance decomposition proportions less than fuzz are printed as fuzzchar
- descending
Logical;
TRUEprints the values in descending order of condition indices- percent
Logical; if
TRUE, the variance proportions are printed as percents, 0-100- prop.col
A vector of colors used for the variance proportions. The default is
c("white", "pink", "red").- cond.col
A vector of colors used for the condition indices, according to
cond.breaks- prop.breaks
Scale breaks for the variance proportions, a vector of length one more than the number of
prop.col, whose values are between 0 and 1.- cond.breaks
Scale breaks for the condition indices a vector of length one more than the number of
cond.col- font.scale
Controls font size scaling for variance proportions. Either a single numeric value (no scaling) or a vector of length 2 specifying the minimum and maximum font sizes in
emunits. Default is1(no scaling). Usec(1, 1.5)to scale font sizes from 1em to 1.5em based on variance proportion values, making larger proportions more visually prominent.- ...
arguments to be passed on to or from other methods (unused)
Details
The "tinytable" object returned can be customized using other functions from
the tinytable package. For example, for HTML output, you can change the font family used in the output via theme_html(), as in:
tt(cd) |>
theme_html(css = "font-family: Arial, sans-serif;")The present version, when run in an RStudio editor window, renders the graphic result in the Viewer panel. There is still some difficulty
in producing this output in .Rmd and .qmd documents directy via the tinytable print() method. A work-around is to save the
result to a graphic file and use knitr::include_graphics(). For example, in a code chunk you can use:
tt(cd) |>
save_tt("myfig.png")
knitr::include_graphics("myfig.png")Examples
library(VisCollin)
library(tinytable)
#> Warning: package 'tinytable' was built under R version 4.5.2
data(cars, package = "VisCollin")
cars.mod <- lm (mpg ~ cylinder + engine + horse + weight + accel + year,
data = cars)
cd <- colldiag(cars.mod, center=TRUE)
# show all values, in same order as `cd`
tt(cd)
#>
#> +------------+----------+--------+-------+--------+-------+------+
#> | Cond
#> +------------+----------+--------+-------+--------+-------+------+
#> index | cylinder | engine | horse | weight | accel | year |
#> +============+==========+========+=======+========+=======+======+
#> | 1.00 | 0.00 | 0.00 | 0.01 | 0.00 | 0.01 | 0.01 |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 2.25 | 0.00 | 0.00 | 0.00 | 0.01 | 0.02 | 0.79 |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 2.52 | 0.00 | 0.00 | 0.00 | 0.01 | 0.42 | 0.14 |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 5.66 | 0.31 | 0.01 | 0.31 | 0.09 | 0.06 | 0.01 |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 8.34 | 0.12 | 0.00 | 0.65 | 0.72 | 0.47 | 0.05 |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 10.82 | 0.56 | 0.98 | 0.03 | 0.18 | 0.01 | 0.00 |
#> +------------+----------+--------+-------+--------+-------+------+
# show results in percent
tt(cd, percent = TRUE)
#>
#> +------------+----------+--------+-------+--------+-------+------+
#> | Cond
#> +------------+----------+--------+-------+--------+-------+------+
#> index | cylinder | engine | horse | weight | accel | year |
#> +============+==========+========+=======+========+=======+======+
#> | 1.00 | 0 | 0 | 1 | 0 | 1 | 1 |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 2.25 | 0 | 0 | 0 | 1 | 2 | 79 |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 2.52 | 0 | 0 | 0 | 1 | 42 | 14 |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 5.66 | 31 | 1 | 31 | 9 | 6 | 1 |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 8.34 | 12 | 0 | 65 | 72 | 47 | 5 |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 10.82 | 56 | 98 | 3 | 18 | 1 | 0 |
#> +------------+----------+--------+-------+--------+-------+------+
# try descending & fuzz
tt(cd, descending = TRUE, fuzz = 0.3)
#>
#> +------------+----------+--------+-------+--------+-------+------+
#> | Cond
#> +------------+----------+--------+-------+--------+-------+------+
#> index | cylinder | engine | horse | weight | accel | year |
#> +============+==========+========+=======+========+=======+======+
#> | 10.82 | 0.56 | 0.98 | | | | |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 8.34 | | | 0.65 | 0.72 | 0.47 | |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 5.66 | 0.31 | | 0.31 | | | |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 2.52 | | | | | 0.42 | |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 2.25 | | | | | | 0.79 |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 1.00 | | | | | | |
#> +------------+----------+--------+-------+--------+-------+------+
# vary font size from 1em to 1.5em based on variance proportions
tt(cd, font.scale = c(1, 1.5))
#>
#> +------------+----------+--------+-------+--------+-------+------+
#> | Cond
#> +------------+----------+--------+-------+--------+-------+------+
#> index | cylinder | engine | horse | weight | accel | year |
#> +============+==========+========+=======+========+=======+======+
#> | 1.00 | 0.00 | 0.00 | 0.01 | 0.00 | 0.01 | 0.01 |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 2.25 | 0.00 | 0.00 | 0.00 | 0.01 | 0.02 | 0.79 |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 2.52 | 0.00 | 0.00 | 0.00 | 0.01 | 0.42 | 0.14 |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 5.66 | 0.31 | 0.01 | 0.31 | 0.09 | 0.06 | 0.01 |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 8.34 | 0.12 | 0.00 | 0.65 | 0.72 | 0.47 | 0.05 |
#> +------------+----------+--------+-------+--------+-------+------+
#> | 10.82 | 0.56 | 0.98 | 0.03 | 0.18 | 0.01 | 0.00 |
#> +------------+----------+--------+-------+--------+-------+------+
