| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/polca.R |
| 3 |
\name{tidy.poLCA} |
| 4 |
\alias{tidy.poLCA} |
| 5 |
\alias{poLCA_tidiers} |
| 6 |
\title{Tidy a(n) poLCA object} |
| 7 |
\usage{ |
| 8 |
\method{tidy}{poLCA}(x, ...) |
| 9 |
} |
| 10 |
\arguments{ |
| 11 |
\item{x}{A \code{poLCA} object returned from \code{\link[poLCA:poLCA]{poLCA::poLCA()}}.} |
| 12 |
|
| 13 |
\item{...}{Additional arguments. Not used. Needed to match generic |
| 14 |
signature only. \strong{Cautionary note:} Misspelled arguments will be |
| 15 |
absorbed in \code{...}, where they will be ignored. If the misspelled |
| 16 |
argument has a default value, the default value will be used. |
| 17 |
For example, if you pass \code{conf.lvel = 0.9}, all computation will |
| 18 |
proceed using \code{conf.level = 0.95}. Two exceptions here are: |
| 19 |
\itemize{ |
| 20 |
\item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if |
| 21 |
it will be ignored. |
| 22 |
\item \code{augment()} methods will warn when supplied a \code{newdata} argument if it |
| 23 |
will be ignored. |
| 24 |
}} |
| 25 |
} |
| 26 |
\description{ |
| 27 |
Tidy summarizes information about the components of a model. |
| 28 |
A model component might be a single term in a regression, a single |
| 29 |
hypothesis, a cluster, or a class. Exactly what tidy considers to be a |
| 30 |
model component varies across models but is usually self-evident. |
| 31 |
If a model has several distinct types of components, you will need to |
| 32 |
specify which components to return. |
| 33 |
} |
| 34 |
\examples{ |
| 35 |
\dontshow{if (rlang::is_installed(c("poLCA", "ggplot2"))) withAutoprint(\{ # examplesIf} |
| 36 |
|
| 37 |
# load libraries for models and data |
| 38 |
library(poLCA) |
| 39 |
library(dplyr) |
| 40 |
|
| 41 |
# generate data |
| 42 |
data(values) |
| 43 |
|
| 44 |
f <- cbind(A, B, C, D) ~ 1 |
| 45 |
|
| 46 |
# fit model |
| 47 |
M1 <- poLCA(f, values, nclass = 2, verbose = FALSE) |
| 48 |
|
| 49 |
M1 |
| 50 |
|
| 51 |
# summarize model fit with tidiers + visualization |
| 52 |
tidy(M1) |
| 53 |
augment(M1) |
| 54 |
glance(M1) |
| 55 |
|
| 56 |
library(ggplot2) |
| 57 |
|
| 58 |
ggplot(tidy(M1), aes(factor(class), estimate, fill = factor(outcome))) + |
| 59 |
geom_bar(stat = "identity", width = 1) + |
| 60 |
facet_wrap(~variable) |
| 61 |
|
| 62 |
# three-class model with a single covariate. |
| 63 |
data(election) |
| 64 |
|
| 65 |
f2a <- cbind( |
| 66 |
MORALG, CARESG, KNOWG, LEADG, DISHONG, INTELG, |
| 67 |
MORALB, CARESB, KNOWB, LEADB, DISHONB, INTELB |
| 68 |
) ~ PARTY |
| 69 |
|
| 70 |
nes2a <- poLCA(f2a, election, nclass = 3, nrep = 5, verbose = FALSE) |
| 71 |
|
| 72 |
td <- tidy(nes2a) |
| 73 |
td |
| 74 |
|
| 75 |
ggplot(td, aes(outcome, estimate, color = factor(class), group = class)) + |
| 76 |
geom_line() + |
| 77 |
facet_wrap(~variable, nrow = 2) + |
| 78 |
theme(axis.text.x = element_text(angle = 90, hjust = 1)) |
| 79 |
|
| 80 |
au <- augment(nes2a) |
| 81 |
|
| 82 |
au |
| 83 |
|
| 84 |
count(au, .class) |
| 85 |
|
| 86 |
# if the original data is provided, it leads to NAs in new columns |
| 87 |
# for rows that weren't predicted |
| 88 |
au2 <- augment(nes2a, data = election) |
| 89 |
|
| 90 |
au2 |
| 91 |
|
| 92 |
dim(au2) |
| 93 |
\dontshow{\}) # examplesIf} |
| 94 |
} |
| 95 |
\seealso{ |
| 96 |
\code{\link[=tidy]{tidy()}}, \code{\link[poLCA:poLCA]{poLCA::poLCA()}} |
| 97 |
|
| 98 |
Other poLCA tidiers: |
| 99 |
\code{\link{augment.poLCA}()}, |
| 100 |
\code{\link{glance.poLCA}()} |
| 101 |
} |
| 102 |
\concept{poLCA tidiers} |
| 103 |
\value{ |
| 104 |
A \code{\link[tibble:tibble]{tibble::tibble()}} with columns: |
| 105 |
\item{class}{The class under consideration.} |
| 106 |
\item{outcome}{Outcome of manifest variable.} |
| 107 |
\item{std.error}{The standard error of the regression term.} |
| 108 |
\item{variable}{Manifest variable} |
| 109 |
\item{estimate}{Estimated class-conditional response probability} |
| 110 |
|
| 111 |
} |