% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tmfast.R
\name{fit_varimax}
\alias{fit_varimax}
\title{Given a (rank \code{n}) PCA fit, return a rank \code{k < n} varimax fit}
\usage{
fit_varimax(
  k,
  pca,
  feature_names,
  obs_names,
  varimax_fn = stats::varimax,
  varimax_opts = NULL,
  positive_skew = TRUE,
  x = NULL
)
}
\arguments{
\item{k}{Desired rank of the fitted varimax model}

\item{pca}{Fitted PCA model or \code{varimaxes} object}

\item{feature_names}{Names of the features (eg, data columns)}

\item{obs_names}{Names of the observations (eg, data rows)}

\item{varimax_fn}{Function to use for varimax rotation}

\item{varimax_opts}{Options passed to \code{varimax_fn}}

\item{positive_skew}{Should negative-skewed factors be flipped to have positive skew?}

\item{x}{PCA scores matrix (n_obs x max_k), as returned by \code{predict(fitted, newdata)}. Used when the fitted \code{pca} object does not contain scores.}
}
\value{
List with components
- \code{loadings}: Rotated feature loadings
- \code{rotmat}:  Rotation matrix
- \code{scores}:  Rotated observation scores
}
\description{
Given a (rank \code{n}) PCA fit, return a rank \code{k < n} varimax fit
}
\details{
After the initial rotation, factors with negative skew (left tails) are flipped
\code{pca} must contain \verb{$rotation} (feature loadings matrix) and \verb{$sdev} (standard deviations
per PC); \verb{$x} (PC scores matrix) is also required unless \code{x} is supplied directly.
}
\examples{
\donttest{
set.seed(42)
theta  = rdirichlet(50, 1, k = 3)
phi    = rdirichlet(3, 0.1, k = 20)
corpus = draw_corpus(rep(50L, 50), theta, phi)
dtm    = tidytext::cast_sparse(corpus, doc, word, n)
pca    = irlba::prcomp_irlba(dtm, n = 5)
fit_varimax(k = 3, pca = pca,
            feature_names = colnames(dtm),
            obs_names = rownames(dtm))
}
}
