File: get_scores.Rd

package info (click to toggle)
r-cran-parameters 0.24.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,852 kB
  • sloc: sh: 16; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,751 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils_pca_efa.R
\name{get_scores}
\alias{get_scores}
\title{Get Scores from Principal Component Analysis (PCA)}
\usage{
get_scores(x, n_items = NULL)
}
\arguments{
\item{x}{An object returned by \code{\link[=principal_components]{principal_components()}}.}

\item{n_items}{Number of required (i.e. non-missing) items to build the sum
score. If \code{NULL}, the value is chosen to match half of the number of
columns in a data frame.}
}
\value{
A data frame with subscales, which are average sum scores for all
items from each component.
}
\description{
\code{get_scores()} takes \code{n_items} amount of items that load the most
(either by loading cutoff or number) on a component, and then computes their
average.
}
\details{
\code{get_scores()} takes the results from \code{\link[=principal_components]{principal_components()}} and
extracts the variables for each component found by the PCA. Then, for each
of these "subscales", row means are calculated (which equals adding up the
single items and dividing by the number of items). This results in a sum
score for each component from the PCA, which is on the same scale as the
original, single items that were used to compute the PCA.
}
\examples{
if (require("psych")) {
  pca <- principal_components(mtcars[, 1:7], n = 2, rotation = "varimax")

  # PCA extracted two components
  pca

  # assignment of items to each component
  closest_component(pca)

  # now we want to have sum scores for each component
  get_scores(pca)

  # compare to manually computed sum score for 2nd component, which
  # consists of items "hp" and "qsec"
  (mtcars$hp + mtcars$qsec) / 2
}
}