| Title: | Configural Frequencies Analysis Using Log-Linear Modeling |
|---|---|
| Description: | Offers several functions for Configural Frequencies Analysis (CFA), which is a useful statistical tool for the analysis of multiway contingency tables. CFA was introduced by G. A. Lienert as 'Konfigurations Frequenz Analyse - KFA'. Lienert, G. A. (1971). Die Konfigurationsfrequenzanalyse: I. Ein neuer Weg zu Typen und Syndromen. Zeitschrift für Klinische Psychologie und Psychotherapie, 19(2), 99–115. |
| Authors: | Joerg-Henrik Heine [aut, cre, com], Rainer W. Alexandrowicz [aut] (Developed functions for the Stirling test), Luciana Diaconescu [aut] (Developed functions for the determination coefficient Q), Mark Stemmler [rev, dtc] (Comprehensive package testing) |
| Maintainer: | Joerg-Henrik Heine <[email protected]> |
| License: | GPL-3 |
| Version: | 1.7.0-7 |
| Built: | 2026-11-23 16:51:06 UTC |
| Source: | https://github.com/cran/confreq |
Keep cell-level weight attributes aligned when selecting or reordering rows of a Pfreq object.
## S3 method for class 'Pfreq' x[i, j, drop]## S3 method for class 'Pfreq' x[i, j, drop]
x |
A |
i, j
|
Row and column selections, as for |
drop |
Passed to the data-frame method if supplied. Otherwise its ordinary default applies. |
The row attributes wgtfreq, WGT, wgtfreq2
and wgtpositive follow the selected rows, including named rows.
A row permutation retains the original individual-weight provenance
attribute wgtdat; selecting fewer configurations removes it because
the remaining individual weights cannot be reconstructed from cell totals.
The Pfreq class is retained only for nonempty selections of unique,
existing rows that keep all configuration columns exactly once and the
original frequency column last. Other data-frame results lose the Pfreq
class and weight attributes. No automatic marginalization is performed
when configuration columns are removed. Vector results follow the ordinary
data-frame dropping rules. This method does not protect arbitrary editing
by [<-, $<-, [[<- or manual attribute replacement.
An incomplete selection of unique configurations remains a frequency table, but is not necessarily suitable for CFA, which needs a complete grid. The corresponding analysis input checks should be respected.
The selected object, with aligned weight attributes if it remains a Pfreq object; otherwise an ordinary data frame or dropped vector.
d <- data.frame(A = factor(c("a", "b", "a")), B = factor(c("x", "x", "y"))) pf <- dat2fre(d, wgt = c(1, 2, 3)) sorted <- pf[rev(seq_len(nrow(pf))), ] attr(sorted, "wgtfreq")d <- data.frame(A = factor(c("a", "b", "a")), B = factor(c("x", "x", "y"))) pf <- dat2fre(d, wgt = c(1, 2, 3)) sorted <- pf[rev(seq_len(nrow(pf))), ] attr(sorted, "wgtfreq")
S3 anova method for object of class"CFA".
## S3 method for class 'CFA' anova(object, ..., test = "Chisq")## S3 method for class 'CFA' anova(object, ..., test = "Chisq")
object |
object of class |
... |
additional objects of the same type. |
test |
Character string specifying the statistical test
used for model comparison. See |
Model descriptions use the CFA specification stored in
used.formula, including functional patterns and covariates.
The model fits and comparison statistics are not changed. With a single
object, the complete design matrix is treated as one GLM term; the table
does not decompose the individual CFA main effects or interactions.
This (generic) function returns an object of class anova.
Calculates the (exact) binomial test based on obseved, expected frequencies an the total number of observations.
binomial_test_cfa(observed, expected, ntotal = sum(observed))binomial_test_cfa(observed, expected, ntotal = sum(observed))
observed |
a vector giving the observed frequencies. |
expected |
a vector giving the expected frequencies. |
ntotal |
optional a numeric giving the total number of observations. By default ntotal is calculated as |
No details
a numeric giving the p-value.
No references in the moment
####################################### # first calculate expected counts for LienertLSD data example. designmatrix<-design_cfg_cfa(kat=c(2,2,2)) # generate an designmatrix (only main effects) data(LienertLSD) # load example data observed<-LienertLSD[,4] # extract observed counts expected<-expected_cfa(des=designmatrix, observed=observed) # calculation of expected counts binomial_test_cfa(observed,expected) ############################################################################## # first calculate expected counts for LienertLSD data example. designmatrix<-design_cfg_cfa(kat=c(2,2,2)) # generate an designmatrix (only main effects) data(LienertLSD) # load example data observed<-LienertLSD[,4] # extract observed counts expected<-expected_cfa(des=designmatrix, observed=observed) # calculation of expected counts binomial_test_cfa(observed,expected) #######################################
Calculates various coefficients for the Configural Frequencies Analysis (CFA) defining main- and (optional) interaction effects. The core principle is to use glm in package stats to calculate the expected counts considering a designmatrix, which is constructed based on an formula definition given in argument form.
CFA( patternfreq, alpha = 0.05, form = NULL, ccor = FALSE, family = poisson(), intercept = FALSE, method = "log", blank = NULL, cova = NULL, bintest = TRUE, ... )CFA( patternfreq, alpha = 0.05, form = NULL, ccor = FALSE, family = poisson(), intercept = FALSE, method = "log", blank = NULL, cova = NULL, bintest = TRUE, ... )
patternfreq |
an object of class |
alpha |
a numeric giving the alpha level for testing (default set to |
form |
either a character expression which can be coerced into a model formula with the function |
ccor |
either a logical (TRUE / FALSE) determining whether to apply a continuity correction or not for the Binomial Approximation to the z-Test. When set to |
family |
argument passed to |
intercept |
deprecated argument currently ignored – former was passed to |
method |
character defining the estimation method for expected frequencies with default set to |
blank |
can be used to indicate which pattern (configurations) are declared as structural cells (configurations) for functional CFA. Should be either (1) a character vector defining the pattern (with spaces between variable categories), which will be ignored for calculation of expected frequencies; or (2) a numeric vector defining the (row) positions of the pattern in an object of class |
cova |
a matrix (possibly with one or more columns) holding the covariate (mean) values for each pattern (configurations) see function |
bintest |
a logical with default set to |
... |
additional parameters passed through to other functions. |
This is the main function of the package. It internal calls several functions of the package confreq-package which are also available as single functions. For classification of the observed patterns into 'Types' and 'Antitypes' according to Lienert (1971), a S3 summary method for the resulting object of class "CFA" can be applied - see summary.CFA. An S3 plot method is useful for visualization of the contingency table and the 'Types' and 'Antitypes' – see plot.CFA. Since version 1.6.0-1 of confreq survey weights are supported when tabluating a data set with function dat2fre. In case that for the resulting tabulated data in the object of class c("data.frame","Pfreq") survey weights were used the function CFA will take into account those weigts for estimation of the expected counts – currently only when method="log".
Input must contain a complete, nonduplicated configuration grid in
canonical category order. Invalid input is rejected before fitting, rather
than silently pairing frequencies with the wrong design-matrix rows.
After selecting or sorting rows, recreate canonical input and align any
covariates or custom design matrix explicitly. Weighted input is detected
from a valid wgtfreq attribute, not from an arbitrary comment.
Weighted method="margins" is rejected because the historical margin
calculation uses raw frequencies. The existing weighted log-linear path is
retained; it is not a new design-based survey-variance implementation.
an object of class CFA with results.
Lienert, G. A. (1971). Die Konfigurationsfrequenzanalyse: I. Ein neuer Weg zu Typen und Syndromen. Zeitschrift für Klinische Psychologie und Psychotherapie, 19(2), 99-115.
Glück, J., & Von Eye, A. (2000). Including covariates in Configural Frequency Analysis. Psychologische Beitrage, 42, 405–417.
Victor, N. (1989). An Alternativ Approach to Configural Frequency Analysis. Methodika, 3, 61–73.
Stemmler, M. (2020). Person-Centered Methods. Cham: Springer International Publishing.
####################################### data(LienertLSD) LienertLSD res1 <- CFA(LienertLSD) summary(res1) plot(res1) coef(res1) ## testing independence conditional on structural pattern number 8 (functional approach) res1_f8 <- CFA(LienertLSD,blank = 8) summary(res1_f8) plot(res1_f8) coef(res1_f8) ## testing with (full) interactions res2 <- CFA(LienertLSD,form="~ C + T + A + C:T + C:A + T:A + C:T:A") summary(res2) plot(res2) coef(res2) #' ## testing the null model res3 <- CFA(LienertLSD,form="null") summary(res3) plot(res3) coef(res3) ####################### data(suicide) suicide # suicide data is in non tabulated data representation - so it must be tabulated ! res4 <- CFA(dat2fre(suicide)) summary(res4) plot(res4) coef(res4)####################################### data(LienertLSD) LienertLSD res1 <- CFA(LienertLSD) summary(res1) plot(res1) coef(res1) ## testing independence conditional on structural pattern number 8 (functional approach) res1_f8 <- CFA(LienertLSD,blank = 8) summary(res1_f8) plot(res1_f8) coef(res1_f8) ## testing with (full) interactions res2 <- CFA(LienertLSD,form="~ C + T + A + C:T + C:A + T:A + C:T:A") summary(res2) plot(res2) coef(res2) #' ## testing the null model res3 <- CFA(LienertLSD,form="null") summary(res3) plot(res3) coef(res3) ####################### data(suicide) suicide # suicide data is in non tabulated data representation - so it must be tabulated ! res4 <- CFA(dat2fre(suicide)) summary(res4) plot(res4) coef(res4)
Calculates the local chi-square test based on obseved and expected frequencies.
chi_local_test_cfa(observed, expected)chi_local_test_cfa(observed, expected)
observed |
a vector giving the observed frequencies. |
expected |
a vector giving the expected frequencies. |
No details in the moment.
a list with chi-square statistic and corresponding degrees of freedom an p-value.
No references in the moment
####################################### # first calculate expected counts for LienertLSD data example. designmatrix<-design_cfg_cfa(kat=c(2,2,2)) # generate an designmatrix (only main effects) data(LienertLSD) # load example data observed<-LienertLSD[,4] # extract observed counts expected<-expected_cfa(des=designmatrix, observed=observed) # calculation of expected counts chi_local_test_cfa(observed,expected) ############################################################################## # first calculate expected counts for LienertLSD data example. designmatrix<-design_cfg_cfa(kat=c(2,2,2)) # generate an designmatrix (only main effects) data(LienertLSD) # load example data observed<-LienertLSD[,4] # extract observed counts expected<-expected_cfa(des=designmatrix, observed=observed) # calculation of expected counts chi_local_test_cfa(observed,expected) #######################################
S3 coefficients method for object of class"CFA".
## S3 method for class 'CFA' coef(object, ...)## S3 method for class 'CFA' coef(object, ...)
object |
object of class |
... |
other parameters passed trough. |
Coefficients extracted from the model object of class"CFA".
The package confreq offers some functions for Configural Frequencies Analysis (CFA) proposed by G.A. Lienert as an analysis of types and antitypes of persons or objects grouped according to their characteristic (response) pattern. The core principle in the package confreq is to use the function glm to compute the expected counts based on a model (design) matrix. The main functions are CFA and S2CFA (see details).
The simplest entry to the package confreq is to use the main function CFA, which will compute several coefficients of Configural Frequencies Analysis at once.
More sophisticated control can be achieved by using the several single functions like expected_cfa, design_cfg_cfa, chi_local_test_cfa , stirling_cfa , etc. ...
Two-Sample-CFA, to detect discriminating pattern between two (sub-) samples, can be performed with the function S2CFA
For further description see description of the respective functions.
A good introduction into the theory and applications of Configural Frequencies Analysis is given in the Textbook 'Person-Centered Methods' by Mark Stemmler (see references).
Additional Information:
Some users running R on 'Linux like' OS distributions (like e.g. Ubuntu – and in rare cases MAC OS) might report trouble during installation of confreq due to the package dependency gmp, which is used in confreq to perform the exact binomial test.
This (miss-)behavior can usually traced back to a missing of 'the GNU Multiple Precision Arithmetic Library' in the respective OS installation. To fix this, users might consider to run the following Ubuntu Linux command in a terminal to install the latest GMP Library:
'sudo apt-get install libgmp3-dev'.
For additional information see also https://www.mathemagix.org/www/mmdoc/doc/html/external/gmp.en.html and https://gmplib.org/.
Annotation: The foundations for this R-Package were established and discussed in Rothenberge (2011) and (finally) in Klagenfurt at FGME 2013 with Rainer Alexandrowicz and Mark Stemmler ...
Joerg-Henrik Heine <[email protected]>
R.W. Alexandrowicz (function stirling_cfa())
von Eye, A. (2002). Configural Frequency Analysis. Methods, Models, and Applications. Mahwah, NJ, LEA.
Krauth, J., & Lienert, G. A. (1973). Die Konfigurationsfrequenzanalyse (KFA) und ihre Anwendung in Psychologie und Medizin: ein multivariates nichtparametrisches Verfahren zur Aufdeckung von Typen und Syndromen; mit 70 Tabellen. Freiburg; München: Alber Karl.
Lazarsfeld, P. F., & Henry, N. W. (1968). Latent structure analysis. Boston: Houghton Mifflin.
Lienert, G. A. (1978). Verteilungsfreie Methoden in der Biostatistik (Band II) [Non-parametrical methods in the field of biometrics (Vol. II)]. Meisenheim am Glan, Germany: Hain.
Lienert, G. A. (1971). Die Konfigurationsfrequenzanalyse: I. Ein neuer Weg zu Typen und Syndromen. Zeitschrift für Klinische Psychologie und Psychotherapie, 19(2), 99-115.
Stemmler, M. (2020). Person-Centered Methods – Configural Frequency Analysis (CFA) and Other Methods for the Analysis of Contingency Tables. Cham Heidelberg New York Dordrecht London: Springer.
Stemmler, M., & Hammond, S. (1997). Configural frequency analysis of dependent samples for intra-patient treatment comparisons. Studia Psychologica, 39, 167–175.
####################################### ######### some examples ######## data(LienertLSD) LienertLSD CFA(LienertLSD) ## testing with (full) interactions CFA(LienertLSD,form="~ C + T + A + C:T + C:A + T:A + C:T:A") ## testing the null model CFA(LienertLSD,form="null") ####################### data(suicide) suicide # suicide data is in non tabulated data representation # so it must be tabulated ! CFA(dat2fre(suicide))####################################### ######### some examples ######## data(LienertLSD) LienertLSD CFA(LienertLSD) ## testing with (full) interactions CFA(LienertLSD,form="~ C + T + A + C:T + C:A + T:A + C:T:A") ## testing the null model CFA(LienertLSD,form="null") ####################### data(suicide) suicide # suicide data is in non tabulated data representation # so it must be tabulated ! CFA(dat2fre(suicide))
Compute one numeric summary per covariate and configuration, in the
order of the corresponding complete pattern-frequency table.
Given a dataset x, this function returns summary values for some (numeric) covariate variables in x for each pattern (configuration) defined by a set of factor variables in x.
dat2cov( x, FUN = "mean", ..., notobs = 0, katorder = FALSE, caseorder = TRUE, wgt = NULL, variables = NULL, covariates = NULL )dat2cov( x, FUN = "mean", ..., notobs = 0, katorder = FALSE, caseorder = TRUE, wgt = NULL, variables = NULL, covariates = NULL )
x |
A data frame or matrix containing configuration variables and numeric covariates. |
FUN |
A function or function name returning one numeric value per
group and covariate. Defaults to |
... |
Additional arguments passed to |
notobs |
Numeric replacement for unobserved configurations.
Defaults to zero. Supply one value for all covariates or one value per
selected covariate, in the order of |
katorder |
Logical; see |
caseorder |
Logical; see |
wgt |
Optional vector of finite, nonnegative case weights, one per input row. Zero weights are allowed. |
variables |
Optional character vector of configuration column names.
By default, all factor columns of |
covariates |
Optional character vector of numeric covariate column
names. By default, all numeric columns not selected in |
At least one configuration variable and one numeric covariate are required. Explicit selection allows numeric or character configuration variables without first converting them to factors. Factor levels can specify unobserved categories. Configuration and covariate selections must be disjoint and contain distinct existing column names.
notobs applies only when no input record belongs to a configuration.
Missing or undefined summaries in observed groups remain NA or
NaN; their handling is controlled by FUN and its arguments.
A group containing records with zero weights is still observed, even if
its weighted mean is undefined. Missing configuration values are excluded
according to the default dat2fre() behavior.
Names passed to variables and covariates must be written in
full because these arguments follow .... For use with CFA(),
use the same configuration columns and ordering options in dat2fre().
A data frame of class c("data.frame", "Pcov"), containing
the covariate summaries. The configurations attribute stores the
corresponding configuration columns. Row names are readable labels made
unique if necessary, not keys used for internal matching.
d <- data.frame(A = factor(c("yes", "yes", "no")), B = factor(c("low", "low", "high")), Age = c(20, 40, 60), Weight = c(1, 3, 2)) cov <- dat2cov(d, variables = c("A", "B"), covariates = "Age", wgt = d$Weight, notobs = NA_real_) cov attr(cov, "configurations")d <- data.frame(A = factor(c("yes", "yes", "no")), B = factor(c("low", "low", "high")), Age = c(20, 40, 60), Weight = c(1, 3, 2)) cov <- dat2cov(d, variables = c("A", "B"), covariates = "Age", wgt = d$Weight, notobs = NA_real_) cov attr(cov, "configurations")
Tabulate individual records as a complete table of configurations, including configurations with zero observed frequency. Given a dataset this function returns a (response) pattern frequencies table representation of it.
dat2fre( x, katorder = FALSE, caseorder = TRUE, kat = NULL, codes = NULL, wgt = NULL, ... )dat2fre( x, katorder = FALSE, caseorder = TRUE, kat = NULL, codes = NULL, wgt = NULL, ... )
x |
A data frame containing factor, character, numeric or logical
columns, or a numeric matrix of positive integer category codes.
Column names must be unique; |
katorder |
Logical. Reorder variables by increasing number of
categories? Defaults to |
caseorder |
Logical. If |
kat |
For numeric matrices only: a vector specifying the number
of categories per column. Codes must be in |
codes |
For numeric matrices only: a list with one entry per column and one unique label per category. For named entries, names are used as labels; otherwise, entry values are used as labels. |
wgt |
Optional numeric vector of finite, nonnegative case weights, one per input row. Zero weights are allowed. |
... |
Named options passed to |
For data frames, factor levels define available categories and
their order, including unused levels. Other columns use observed categories
in the order determined by table(). Use factor levels to specify
additional categories. The arguments kat and codes are
rejected for data frames rather than silently ignored.
Numeric matrices retain the historical assumption of codes starting at
one. Use a data frame for other coding schemes or character labels.
Missing matrix codes are rejected. For data frames, the default table
options exclude missing categories; useNA = "ifany" includes them.
The Freq column always contains unweighted counts. If weights are
supplied, wgtfreq stores cell sums of weights, WGT stores
the mean weight per observed cell (one for unobserved cells), and
wgtdat stores the original weight vector. A comment marks the object
as weighted for compatibility with CFA().
The additional attributes wgtfreq2 (cell sums of squared weights)
and wgtpositive (cell counts of positive-weight records) support
the independent-unit survey variance calculation in S2CFA().
Both attributes follow exactly the row order of the frequency table.
Use the default caseorder = TRUE for CFA() and use identical
variable selection and ordering options when preparing covariates.
A data frame of class c("Pfreq", "data.frame"), with one
factor column per configuration variable and a final Freq column.
Weighted inputs additionally produce the attributes described above.
No references in the moment
fre2dat, dat2cov,
fre2tab, CFA, S2CFA
####################################### d <- data.frame(A = factor(c("yes", "no", "yes")), B = factor(c("low", "low", "high"))) pf <- dat2fre(d) pf weighted <- dat2fre(d, wgt = c(1, 2, 3)) attr(weighted, "wgtfreq") ######################################## data(suicide)# loading data in data frame (702 cases) representation dat2fre(suicide) # converting it into a pattern frequencies table ########### ####################################### data(LienertLSD)# loading example pattern frequencies table .. test<-fre2dat(LienertLSD)# and coverting it into a simple (data) matrix test<-test[sample(c(1:65),65),] # making a messy order ############ dat2fre(test) # making a proper ordered pattern frequencies table again ##### try it with a data.frame too! ############################################################################## d <- data.frame(A = factor(c("yes", "no", "yes")), B = factor(c("low", "low", "high"))) pf <- dat2fre(d) pf weighted <- dat2fre(d, wgt = c(1, 2, 3)) attr(weighted, "wgtfreq") ######################################## data(suicide)# loading data in data frame (702 cases) representation dat2fre(suicide) # converting it into a pattern frequencies table ########### ####################################### data(LienertLSD)# loading example pattern frequencies table .. test<-fre2dat(LienertLSD)# and coverting it into a simple (data) matrix test<-test[sample(c(1:65),65),] # making a messy order ############ dat2fre(test) # making a proper ordered pattern frequencies table again ##### try it with a data.frame too! #######################################
Calculates the designmatrix corresponding to a dataset with length(kat) columns (variables).
design_cfg_cfa( kat, form = paste("~", paste(paste("V", 1:length(kat), sep = ""), collapse = " + ")), ... )design_cfg_cfa( kat, form = paste("~", paste(paste("V", 1:length(kat), sep = ""), collapse = " + ")), ... )
kat |
a numerical vector containing kardinal numbers, giving the number of categories for each variable of a dataset (in the respective order of the variables in such a dataset) which corresponds to the requested designmatrix. So the length of this numerical vector represents the number of variables. |
form |
a character string which can be coerced into a model formulae with the function A special Case is to define a null-model or rather a cfa model of order zero. In such a model no (main) effects are considered. This can be achieved bei passing the character expression |
... |
additional parameters passed through to function |
This function internaly calls the function pos_cfg_cfa.
For further information on designmatrices see decription on function model.matrix in the package stats.
A designmatrix - an object of class c("matrix","design_cfg_cfa") - for the formula therm given in argumentform.
No references in the moment
####################################### # designmatrix with three main effects. # three variables with two categories each. design_cfg_cfa(kat=c(2,2,2)) # two variables with two categories each and one variable # with 7 categories (Lienert LSD example). design_cfg_cfa(kat=c(2,2,7)) ########### # designmatrix with three main effects an three interactions. # three variables with two categories each. design_cfg_cfa(kat=c(2,2,2),form="~ V1 + V2 + V3 + V1:V2 + V1:V3 + V2:V3") # two variables with two categories each and one variable # with 7 categories (e.g. The Krauth & Lienert suicide Data). design_cfg_cfa(kat=c(2,2,7),form="~ V1 + V2 + V3 + V1:V2 + V1:V3 + V2:V3") ############################################################################## # designmatrix with three main effects. # three variables with two categories each. design_cfg_cfa(kat=c(2,2,2)) # two variables with two categories each and one variable # with 7 categories (Lienert LSD example). design_cfg_cfa(kat=c(2,2,7)) ########### # designmatrix with three main effects an three interactions. # three variables with two categories each. design_cfg_cfa(kat=c(2,2,2),form="~ V1 + V2 + V3 + V1:V2 + V1:V3 + V2:V3") # two variables with two categories each and one variable # with 7 categories (e.g. The Krauth & Lienert suicide Data). design_cfg_cfa(kat=c(2,2,7),form="~ V1 + V2 + V3 + V1:V2 + V1:V3 + V2:V3") #######################################
Calculates the degrees of freedom based on an designmatrix for a (log liniear) CFA model.
df_des_cfa(des)df_des_cfa(des)
des |
a designmatrix (object of class "matrix") as returned by function |
No details
An object of class "integer" giving the degrees of freedom for the designmatrix defined in argument des.
No references in the moment
####################################### # degrees of freedom for designmatrix with three main effects. # three variables with two categories each. df_des_cfa(design_cfg_cfa(kat=c(2,2,2))) # two variables with two categories each and one variable # with 7 categories (e.g. The Krauth & Lienert suicide Data). df_des_cfa(design_cfg_cfa(kat=c(2,2,7))) ########### # degrees of freedom for designmatrix with three main effects # and three 'two by two'interactions. # and tripple interaction --> saturated model --> df=0 # three variables with two categories each. df_des_cfa(design_cfg_cfa(kat=c(2,2,2),form="~ V1 + V2 + V3 + V1:V2 + V1:V3 + V2:V3 + V1:V2:V3")) ############################################################################## # degrees of freedom for designmatrix with three main effects. # three variables with two categories each. df_des_cfa(design_cfg_cfa(kat=c(2,2,2))) # two variables with two categories each and one variable # with 7 categories (e.g. The Krauth & Lienert suicide Data). df_des_cfa(design_cfg_cfa(kat=c(2,2,7))) ########### # degrees of freedom for designmatrix with three main effects # and three 'two by two'interactions. # and tripple interaction --> saturated model --> df=0 # three variables with two categories each. df_des_cfa(design_cfg_cfa(kat=c(2,2,2),form="~ V1 + V2 + V3 + V1:V2 + V1:V3 + V2:V3 + V1:V2:V3")) #######################################
Calculates the expected frequencies of counts using log liniear model.
expected_cfa(des, observed, family = poisson(), intercept = FALSE, ...)expected_cfa(des, observed, family = poisson(), intercept = FALSE, ...)
des |
a designmatrix (object of class |
observed |
a integer vector with |
family |
argument passed to |
intercept |
argument passed to |
... |
aditional arguments optional passed to |
No details
An vector object giving the expected counts.
No references in the moment
####################################### # expected counts for LienertLSD data example. designmatrix<-design_cfg_cfa(kat=c(2,2,2)) # generate an designmatrix (only main effects) data(LienertLSD) # load example data observed<-LienertLSD[,4] # extract observed counts expected_cfa(des=designmatrix, observed=observed) # calculation of expected counts ############################################################################## # expected counts for LienertLSD data example. designmatrix<-design_cfg_cfa(kat=c(2,2,2)) # generate an designmatrix (only main effects) data(LienertLSD) # load example data observed<-LienertLSD[,4] # extract observed counts expected_cfa(des=designmatrix, observed=observed) # calculation of expected counts #######################################
Calculates the expected frequencies of counts based on the margins of the k-dimensional contingency table.
expected_margin_cfa(Pfreq, blank = NULL)expected_margin_cfa(Pfreq, blank = NULL)
Pfreq |
Object of class "Pfreq" (see. function |
blank |
Either (1) character vector defining the pattern (with spaces between variable categories), which will be ignored for calculation of expected frequencies; or (2) a numeric vector defining the position(s) of the pattern in object of class |
only main effects are considered.
An vector object giving the expected counts.
No references in the moment
####################################### # expected counts for LienertLSD data example. data(LienertLSD) # load example data expected_margin_cfa(Pfreq = LienertLSD) # calculation of expected counts (only main effects). ############################################################################## # expected counts for LienertLSD data example. data(LienertLSD) # load example data expected_margin_cfa(Pfreq = LienertLSD) # calculation of expected counts (only main effects). #######################################
Given a (response) pattern frequencies table this function returns a dataset representation of it.
fre2dat(x, fact = TRUE, ...)fre2dat(x, fact = TRUE, ...)
x |
A pattern-frequency data frame or matrix, with configuration variables in all but the last column. The last column must contain finite, nonnegative integer frequencies. |
fact |
Logical. If |
... |
Arguments passed to WARNING using this option will only work correct when all 'pattern' columns (variables) in the frequencies table share the same number of categories |
The order of configurations in the input is retained; each row
is repeated according to its frequency. Zero-frequency rows produce no
records, and incomplete configuration tables can be expanded directly.
With fact = TRUE and no additional factor arguments, existing
factor levels and labels are retained. Other columns are converted to
factors. Additional factor arguments apply to every column, so a shared
labels argument must be appropriate for all variables.
Weighted-frequency attributes are not expanded into individual weights. Expansion always uses the final frequency column. Fractional frequencies are rejected rather than rounded. A round trip need not restore the original individual row order.
A data frame with factor columns or a numeric matrix, according
to fact, with one row per reconstructed individual record.
No references in the moment
####################################### pf <- data.frame(A = factor(c("yes", "no")), B = factor(c("low", "high")), Freq = c(2, 1)) fre2dat(pf) fre2dat(pf, fact = FALSE) dat2fre(fre2dat(pf)) ################################## data(LienertLSD)# loading example pattern frequencies table fre2dat(LienertLSD)# coverting it into a (data) matrix # for a matrix without colnames colnames(LienertLSD)<-NULL # first removing the colnames fre2dat(LienertLSD) # conversion with automatic new colnames # requesting a data.frame using factor levels fre2dat(LienertLSD,fact=TRUE,labels=c("yes","no"))####################################### pf <- data.frame(A = factor(c("yes", "no")), B = factor(c("low", "high")), Freq = c(2, 1)) fre2dat(pf) fre2dat(pf, fact = FALSE) dat2fre(fre2dat(pf)) ################################## data(LienertLSD)# loading example pattern frequencies table fre2dat(LienertLSD)# coverting it into a (data) matrix # for a matrix without colnames colnames(LienertLSD)<-NULL # first removing the colnames fre2dat(LienertLSD) # conversion with automatic new colnames # requesting a data.frame using factor levels fre2dat(LienertLSD,fact=TRUE,labels=c("yes","no"))
Given data as pattern frequencies (object of class class c("data.frame","Pfreq", see function dat2fre) this function returns a typical array representation (class "table" , see table) of it.
fre2tab(patternfreq, form = NULL, weighted = FALSE)fre2tab(patternfreq, form = NULL, weighted = FALSE)
patternfreq |
an object of class c("data.frame","Pfreq") |
form |
a formula object with possibly both left and right hand sides specifying the order of the variables in the resulting table. At default ( |
weighted |
Logical. If |
This function was introduced in order to connect the typical confreq data representation in the objects of the class c("data.frame","Pfreq"), see function dat2fre, to the R-typical array representation as it exists in objects of the "table" class, see table. This array representation of multi-dimensional contingency tables is used more universally in R – e.g. also in the R package vcd, see the examples section below.
It is assumed, that the last column of the object patternfreq represents the frequencies of the (response) pattern represented by the other columns in patternfreq.
Unused factor levels are retained. Duplicate configurations
are summed. Missing configuration categories are retained as table levels.
No Pfreq class assignment is needed for ordinary frequency data.
The choice of weighted affects only this conversion; it does not
change the handling of weights by CFA() or S2CFA().
An object of class "table", with named dimensions in
the input order or the order specified by form.
An object of class "table", with named dimensions in
the input order or the order specified by form; see table.
No references at the moment
######################################### d <- data.frame(A = factor(c("yes", "no", "yes")), B = factor(c("low", "low", "high"))) pf <- dat2fre(d, wgt = c(1, 2, 3)) fre2tab(pf) fre2tab(pf, weighted = TRUE) fre2tab(pf, form = ~ B + A) fre2tab(pf, form = A ~ B) fre2tab(pf, form = Freq ~ A + B) fre2tab(pf, form = ~ A) ######### data(LienertLSD)# loading example pattern frequencies table fre2tab(LienertLSD)# coverting it into a table ### examples using functions from package vcd data(Lienert1978)# loading example pattern frequencies table fre2tab(Lienert1978)# coverting it into a table strucplot(fre2tab(Lienert1978))# plotting data with 'vcd' structable(fre2tab(Lienert1978),direction = "v")# flatten table (vertical) with 'vcd' # changing the vertical grouping when flattening the table by unsing a 'formula': structable(fre2tab(Lienert1978, form=~Group + Student + Teacher),direction = "v")# flatten table######################################### d <- data.frame(A = factor(c("yes", "no", "yes")), B = factor(c("low", "low", "high"))) pf <- dat2fre(d, wgt = c(1, 2, 3)) fre2tab(pf) fre2tab(pf, weighted = TRUE) fre2tab(pf, form = ~ B + A) fre2tab(pf, form = A ~ B) fre2tab(pf, form = Freq ~ A + B) fre2tab(pf, form = ~ A) ######### data(LienertLSD)# loading example pattern frequencies table fre2tab(LienertLSD)# coverting it into a table ### examples using functions from package vcd data(Lienert1978)# loading example pattern frequencies table fre2tab(Lienert1978)# coverting it into a table strucplot(fre2tab(Lienert1978))# plotting data with 'vcd' structable(fre2tab(Lienert1978),direction = "v")# flatten table (vertical) with 'vcd' # changing the vertical grouping when flattening the table by unsing a 'formula': structable(fre2tab(Lienert1978, form=~Group + Student + Teacher),direction = "v")# flatten table
Function tabulating (answer) categories in X.
ftab(X, catgories = NULL, na.omit = FALSE)ftab(X, catgories = NULL, na.omit = FALSE)
X |
Data as a |
catgories |
optional a vector ( |
na.omit |
logical (default: |
X can either be a ("numeric" or "character") "matrix" containing response vectors of persons (rows) or a "data.frame" containing "numeric", "character" or "factor" variables (columns).
a "matrix" with category frequencies
######## data(suicide) ftab(suicide)######## data(suicide) ftab(suicide)
data example by Lazarsfeld and Henry (1968) where n = 1000 subjects need to solve questions or problems (i.e., A,B, and C). They either ‘1’ = solved or ‘2’ = did not solve the problems. The data is in pattern frequencies table representation (object of class c("data.frame", "Pfreq" )). This data example is used in the textbook by Mark Stemmler (2020, Table 6.6, p. 81).
data(lazar)data(lazar)
A matrix with 4 columns and 8 rows. The last column gives the frequencies for the (response) pattern in column 1:3.
No detail in the moment
Lazarsfeld, P. F., & Henry, N. W. (1968). Latent structure analysis. Boston: Houghton Mifflin.
Stemmler, M. (2020). Person-Centered Methods – Configural Frequency Analysis (CFA) and Other Methods for the Analysis of Contingency Tables. Cham Heidelberg New York Dordrecht London: Springer.
############################################################## data(lazar) dim(lazar) ############################################################################################################################ data(lazar) dim(lazar) ##############################################################
Data used as an example for two-sample CFA in the textbook by Mark Stemmler (2020, Table 7.7, p.97) taken from Lienert (1978, p. 978). The data is in pattern frequencies table representation (object of class c("data.frame", "Pfreq" )).
data(Lienert1978)data(Lienert1978)
A data frame (object of class c("data.frame", "Pfreq") ) with 4 columns and 12 rows. The last column gives the frequencies for the (response) pattern in column 1:2 of the respective 'Group' given in column 3.
no details at the moment ...
Lienert, G. A. (1978). Verteilungsfreie Methoden in der Biostatistik (Band II) [Non-parametrical 168 methods in the field of biometrics (Vol. II)]. Meisenheim am Glan, Germany: Hain.
Stemmler, M. (2020). Person-Centered Methods – Configural Frequency Analysis (CFA) and Other Methods for the Analysis of Contingency Tables. Cham Heidelberg New York Dordrecht London: Springer.
data(Lienert1978) dim(Lienert1978) ############################################################## colnames(Lienert1978) # show all variable names of Lienert1978data(Lienert1978) dim(Lienert1978) ############################################################## colnames(Lienert1978) # show all variable names of Lienert1978
Data from the classical Lienert LSD trial as an example for CFA (see Lienert, 1971, p. 103, ’Tabelle 1’). The data is in pattern frequencies table representation (object of class c("data.frame", "Pfreq" )).
data(LienertLSD)data(LienertLSD)
A data frame (object of class c("data.frame", "Pfreq") ) with 4 columns and 8 rows. The last column gives the frequencies for the observed pattern of the psychotoxic basic syndrome (in column 1:3) due to the intake of lysergic acid diethylamide (LSD).
The first three columns are named C, T and A which are abbreviations for the observed symptoms after taking LSD:
C = narrowed consciousness
T = thought disturbance
A = affective disturbance
The coding of the observations is for all symptoms: present='+' and absent='-'
Lienert, G. A. (1971). Die Konfigurationsfrequenzanalyse: I. Ein neuer Weg zu Typen und Syndromen. Zeitschrift für Klinische Psychologie und Psychotherapie, 19(2), 99-115.
data(LienertLSD) dim(LienertLSD) ############################################################## colnames(LienertLSD) # show all variable names of matrix LienertLSDdata(LienertLSD) dim(LienertLSD) ############################################################## colnames(LienertLSD) # show all variable names of matrix LienertLSD
Calculates the likelihod ratio chi-square statistic based on observed and expected counts.
lr(observed, expected)lr(observed, expected)
observed |
a vector giving the observed frequencies. |
expected |
a vector giving the expected frequencies. |
No details in the moment.
numeric giving the likelihood ratio chi-square statistic.
Stemmler, M. (2014). Person-Centered Methods – Configural Frequency Analysis (CFA) and Other Methods for the Analysis of Contingency Tables. Cham Heidelberg New York Dordrecht London: Springer.
####################################### ######### some examples ######## data(newborns) newborns designmatrix <- design_cfg_cfa(kat=c(2,2)) # generate an designmatrix (only main effects) observed <- newborns[,3] # extract observed counts expected <- expected_cfa(des=designmatrix, observed=observed) # calculation of expected counts lr(observed,expected) # calculation of the likelihood ratio chi-square statistic####################################### ######### some examples ######## data(newborns) newborns designmatrix <- design_cfg_cfa(kat=c(2,2)) # generate an designmatrix (only main effects) observed <- newborns[,3] # extract observed counts expected <- expected_cfa(des=designmatrix, observed=observed) # calculation of expected counts lr(observed,expected) # calculation of the likelihood ratio chi-square statistic
data example by Stemmler (2020, table 4.1, p. 33) where n = 56 newborns 'with seizures' = 1 or 'without seizures' = 2 (coded in the in first column named 'A') were tested with an intelligence test while they attended kindergarten. Children’s intelligence was divided into 'average or above' = 1 and 'below average' = 2 (coded in the in second column named 'B'). The third column gives the frequencies of the respective pattern.
data(newborns)data(newborns)
A data.frame with 3 columns and 4 rows. The last column gives the frequencies for the observed pattern in column 1:2. The data is in pattern frequencies table representation (object of class c("data.frame", "Pfreq"))
No detail in the moment
Stemmler, M. (2020). Person-Centered Methods – Configural Frequency Analysis (CFA) and Other Methods for the Analysis of Contingency Tables. Cham Heidelberg New York Dordrecht London: Springer.
############################################################## data(newborns) dim(newborns) newborns ############################################################################################################################ data(newborns) dim(newborns) newborns ##############################################################
S3 plot method for object of class"CFA"
## S3 method for class 'CFA' plot( x, type = "z.pChi", fill = c("red", "blue", "grey"), adjalpha = "bonferroni", ... )## S3 method for class 'CFA' plot( x, type = "z.pChi", fill = c("red", "blue", "grey"), adjalpha = "bonferroni", ... )
x |
object of class |
type |
character indicating which test to use for visualizing whether the observed pattern are 'Types', 'Antitypes' or not significant at all. Possible options for |
fill |
a vector of (three) colors defining the coloring of significant 'Types' (default "red"), 'Antitypes' (default "blue") or not significant cells (default "grey") in the plot. |
adjalpha |
Adjustment method: |
... |
other parameters passed trough |
Plot frequencies use the same raw or weighted frequency basis as
the CFA result. The existing CFA inferential calculations are unchanged;
this plotting correction does not supply a design-based survey variance.
Additional adjustment methods are "hochberg",
"hommel", "BH", "BY" and "fdr" (an alias
for "BH"). These methods use p.adjust on
computable p-values only, following the same test-family rule as Holm.
Hochberg and Hommel require appropriate dependence assumptions; BH and BY
control the false discovery rate rather than the family-wise error rate.
See p.adjust for assumptions and statistical interpretation.
The historical Bonferroni denominator and the "none" behavior are
retained. In particular, the reduced test-family rule for Holm and the new
methods is not silently applied to the existing Bonferroni decisions.
With adjalpha = "holm", decisions use
stats::p.adjust(p, method = "holm") on the non-missing p-values
only. Missing values (NA/NaN) do not contribute to the number
of comparisons. The historical strict rule, adjusted p-value less than
alpha, is retained. Decisions use full precision before rounding.
Only finite values in [0, 1] are computable p-values. Other numeric
values are excluded with a warning and treated as missing decisions.
Missing decisions are drawn using the neutral fill color.
Functional cells are excluded from the Holm test family and retain
their "b" label. Other pre-existing adjustment methods retain their decisions.
a plot visualizing the results.
Holm, S. (1979). A simple sequentially rejective multiple test procedure. Scandinavian Journal of Statistics, 6(2), 65–70.
Bonferroni, C. E. (1935). Il calcolo delle assicurazioni su gruppi di teste. In S.O. Carboni (Ed.), Studi in Onore del Professore Salvatore Ortu Carboni (S. 13–60). Roma, Tipografia del Senato: Bardi.
data(LienertLSD) res <- CFA(LienertLSD, bintest = FALSE) plot(res, type = "pChi", adjalpha = "BH")data(LienertLSD) res <- CFA(LienertLSD, bintest = FALSE) plot(res, type = "pChi", adjalpha = "BH")
S3 plot method for object of class"S2CFA"
## S3 method for class 'S2CFA' plot( x, type = "ex.fisher.test", fill = c("red", "grey"), adjalpha = "bonferroni", ... )## S3 method for class 'S2CFA' plot( x, type = "ex.fisher.test", fill = c("red", "grey"), adjalpha = "bonferroni", ... )
x |
object of class |
type |
Test column: |
fill |
a vector of (two) colors defining the coloring of discriminating 'Types' (default "red"), or not discriminating cells (default "grey") in the plot. |
adjalpha |
Adjustment method: |
... |
other parameters passed trough. |
Survey-weighted frequencies and Wald p-values are taken from
the weighted S2CFA() result; no integer rounding is performed.
The test assumes independent sampling units, without cluster or stratum
information. Non-computable p-values do not contribute to the Holm and
additional p.adjust test families. Summary and plot select the same test.
Additional adjustment methods are "hochberg",
"hommel", "BH", "BY" and "fdr" (an alias
for "BH"). These methods use p.adjust on
computable p-values only, following the same test-family rule as Holm.
Hochberg and Hommel require appropriate dependence assumptions; BH and BY
control the false discovery rate rather than the family-wise error rate.
See p.adjust for assumptions and statistical interpretation.
The historical Bonferroni denominator and the "none" behavior are
retained. In particular, the reduced test-family rule for Holm and the new
methods is not silently applied to the existing Bonferroni decisions.
With adjalpha = "holm", decisions use
stats::p.adjust(p, method = "holm") on the non-missing p-values
only. Missing values (NA/NaN) do not contribute to the number
of comparisons. The historical strict rule, adjusted p-value less than
alpha, is retained. Decisions use full precision before rounding.
Only finite values in [0, 1] are computable p-values. Other numeric
values are excluded with a warning and treated as missing decisions.
Missing decisions are drawn using the neutral fill color.
Draws a plot and invisibly returns a list containing the table,
fill array, significance decisions, configuration mapping, and
additional entries p.adj and adjalpha.
Holm, S. (1979). A simple sequentially rejective multiple test procedure. Scandinavian Journal of Statistics, 6(2), 65–70.
Bonferroni, C. E. (1935). Il calcolo delle assicurazioni su gruppi di teste. In S.O. Carboni (Ed.), Studi in Onore del Professore Salvatore Ortu Carboni (S. 13–60). Roma, Tipografia del Senato: Bardi.
data(Lienert1978) res <- S2CFA(Lienert1978) plot(res, adjalpha = "BY")data(Lienert1978) res <- S2CFA(Lienert1978) plot(res, adjalpha = "BY")
Calculates all possible configuartions for some variables with different numbers of categories.
pos_cfg_cfa(kat, fact = FALSE)pos_cfg_cfa(kat, fact = FALSE)
kat |
a numerical vector containing kardinal numbers, giving the number of categories for each variable. So the length of this numerical vector represents the number of variables. |
fact |
logical, default is |
No details
An object of class "matrix" or "data.frame" (depending on the argument fact) containing all possible configurations for lenght(kat) variables with the respective number of categories given as kardinal numbers in the vector kat.
No references in the moment
####################################### # possible configurations for ... # three variables with two categories each (Lienert LSD example). pos_cfg_cfa(kat=c(2,2,2)) ############################################################################## # possible configurations for ... # three variables with two categories each (Lienert LSD example). pos_cfg_cfa(kat=c(2,2,2)) #######################################
S3 print method for object of class"Pfreq"
## S3 method for class 'Pfreq' print( x, ..., digits = NULL, quote = FALSE, right = TRUE, row.names = TRUE, max = NULL )## S3 method for class 'Pfreq' print( x, ..., digits = NULL, quote = FALSE, right = TRUE, row.names = TRUE, max = NULL )
x |
object of class |
... |
further arguments passed to or from other methods. |
digits |
minimal number of significant digits, see |
quote |
logical, indicating whether or not strings should be printed with surrounding quotes. |
right |
logical, indicating whether or not strings should be right aligned. |
row.names |
logical (or character vector), indicating whether (or what) row names should be printed. |
max |
numeric or |
output printed to the console
Calculates the theoretical upper bound of the local determination coefficient Q for a table with T variables (dimensions), following Theorem 1 in Betzin & Bollmann-Sdorra (2003).
Q_determination_bound_cfa(D)Q_determination_bound_cfa(D)
D |
a numeric vector giving the number of variables (dimensions) of the table(s), |
For a -dimensional table (i.e. cells) the empirical value of the determination coefficient Q_determination_cfa is bounded by
and this bound is sharp (attained in the limit, for any a table configuration exists that gets arbitrarily close to it).
The bound increases with T but stays clearly below 1 even for moderately large T (e.g. ~0.682 for T = 4, ~0.866 for T = 10, ~0.986 for T = 100).
The authors explicitly warn against using this bound to *normalize* Q (see Section 4 / Example 1 (p. 409) of the paper, where normalizing even reverses the ranking of two Q values from tables of different dimension).
Comparisons of Q across tables of different dimension therefore remain problematic even after normalization.
a numeric vector (same length as T) with the upper bound for Q.
Betzin, J., & Bollmann-Sdorra, P. (2003). On the determination coefficient in CFA. Psychology Science, 45(2), 400-420.
####################################### # reproduces Table 1 of Betzin & Bollmann-Sdorra (2003) T <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 50, 75, 100) round(Q_determination_bound_cfa(D = T), 3)####################################### # reproduces Table 1 of Betzin & Bollmann-Sdorra (2003) T <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 50, 75, 100) round(Q_determination_bound_cfa(D = T), 3)
Calculates Lienert's local determination coefficient (Q) for each cell of a contingency table, based on the observed and expected cell frequencies. The coefficient quantifies how strongly a single cell deviates from the independence model, relative to the largest deviation that is theoretically possible for that cell.
Q_determination_cfa(observed, expected, n = sum(observed))Q_determination_cfa(observed, expected, n = sum(observed))
observed |
numeric vector of observed (absolute) cell frequencies |
expected |
numeric vector of expected (absolute) cell frequencies |
n |
a numeric defining the sample size with default set to |
The determination coefficient for a cell is defined (Betzin & Bollmann-Sdorra, 2003, eq. 1; going back to Lienert, 1971) as
where is the observed and the expected (absolute) frequency of cell , and is the total sample size.
In relative frequencies (, ) this is equivalent to
lies between -1 and 1 for a single cell and coincides with Lienert's (1971) original formula whenever .
Note that values of from tables of different dimension are not directly comparable, even after normalizing by the bound – see Q_determination_bound_cfa.
a numeric vector with the local determination coefficient for each cell, in the same order as observed / expected.
Betzin, J., & Bollmann-Sdorra, P. (2003). On the determination coefficient in CFA. Psychology Science, 45(2), 400-420.
Lienert, G. A. (1971). Die Konfigurationsfrequenzanalyse.Zeitschrift für Klinische Psychologie und Psychotherapie, 19, 99-115.
####################################### # first calculate expected counts for the LienertLSD data example. # designmatrix with three main effects designmatrix <- design_cfg_cfa(kat = c(2, 2, 2)) # load example data data(LienertLSD) # extract observed counts observed <- LienertLSD[, 4] expected <- expected_cfa(des = designmatrix, observed = observed) Q_determination_cfa(observed, expected) ####################################### # an easy, hand-checkable 2x2 example: # margins: row totals e1. = 60 and e2. = 40, # column totals e.1 = 50 and e.2 = 50, n = 100 -> e11 = 30 Q_determination_cfa(observed = 45, expected = 30, n = 100) # (45-30) / max(30, 70) = 0.2142857####################################### # first calculate expected counts for the LienertLSD data example. # designmatrix with three main effects designmatrix <- design_cfg_cfa(kat = c(2, 2, 2)) # load example data data(LienertLSD) # extract observed counts observed <- LienertLSD[, 4] expected <- expected_cfa(des = designmatrix, observed = observed) Q_determination_cfa(observed, expected) ####################################### # an easy, hand-checkable 2x2 example: # margins: row totals e1. = 60 and e2. = 40, # column totals e.1 = 50 and e.2 = 50, n = 100 -> e11 = 30 Q_determination_cfa(observed = 45, expected = 30, n = 100) # (45-30) / max(30, 70) = 0.2142857
Calculates coefficients for the two-sample CFA. Instead of differentiating between 'Types' and 'Antitypes', two-sample CFA looks for discrimination types, that is configurations with significant differences in frequencies between two sub samples.
S2CFA(patternfreq, alpha = 0.05, ccor = FALSE, ..., weighted = NULL)S2CFA(patternfreq, alpha = 0.05, ccor = FALSE, ..., weighted = NULL)
patternfreq |
an object of class |
alpha |
a numeric giving the alpha level for testing (default set to |
ccor |
For unweighted analysis only; TRUE is rejected for survey weights. A logical (TRUE / FALSE) determining whether to apply a continuity correction or not. When set to |
... |
Reserved for compatibility; not used by this implementation. |
weighted |
Logical or NULL. By default, use survey weights if the
|
With survey weights, observed and expected frequencies use sums of weights, without rounding. Inference compares the two weighted proportions by an asymptotic Wald chi-squared test (one degree of freedom) using a linearized variance for independent sampling units, with replacement. No clustering, stratification, calibration or finite-population correction can be incorporated from the weight vector alone.
The influence for record i in group g is
w_i * (I_i - p_g) / sum(w_g). The two group contributions are
disjoint. Their squared influences are summed and multiplied by
n / (n - 1), where n counts all positive-weight records in both
groups. The variance is obtained from wgtfreq2 and
wgtpositive, stored by the revised dat2fre().
Zero-variance configurations are not tested and have an NA p-value.
For old weighted objects without these attributes, only weighted descriptive
results are returned with a warning; recreate them with dat2fre().
The weighted p-value is p.wald, not a Fisher exact test and not a
Pearson test on population expansion totals. Classical test columns remain
NA in weighted results. Multiplying all weights by a common positive
factor leaves the Wald statistic and p-value unchanged.
The unweighted statistical calculation retains its historical behavior.
Both groups are paired by categories, even after a row permutation.
Incomplete or duplicated configuration grids are rejected explicitly.
An object of class S2CFA. Weighted results additionally
contain weighted = TRUE and a weighting description.
The first ten local result columns retain the historical layout; survey
columns are Wald, df.wald, p.wald, prop.diff
and SE.diff. Frequencies in weighted results are sums of weights.
Stemmler, M. (2020). Person-Centered Methods – Configural Frequency Analysis (CFA) and Other Methods for the Analysis of Contingency Tables. Cham Heidelberg New York Dordrecht London: Springer.
Stemmler, M., & Hammond, S. (1997). Configural frequency analysis of dependent samples for intra-patient treatment comparisons. Studia Psychologica, 39, 167–175.
####################################### ############### some examples ######### ######### example from Marks Textbook data(Lienert1978) res1 <- S2CFA(Lienert1978) summary(res1) res2 <- S2CFA(Lienert1978, ccor=TRUE) # with continuity correction summary(res2) ######### example with biger numbers data(suicide) ftab(suicide) # 'Epoche' may divide the sample into 2 subsamples suicide_2s <- suicide[, c(1,3,2) ] # reorder data that 'Epoche' is the last column ftab(suicide_2s) # check reordering suicide_2s_fre <- dat2fre(suicide_2s) res3 <- S2CFA(suicide_2s_fre) summary(res3) res4 <- S2CFA(suicide_2s_fre, ccor=TRUE) # with continuity correction summary(res4)####################################### ############### some examples ######### ######### example from Marks Textbook data(Lienert1978) res1 <- S2CFA(Lienert1978) summary(res1) res2 <- S2CFA(Lienert1978, ccor=TRUE) # with continuity correction summary(res2) ######### example with biger numbers data(suicide) ftab(suicide) # 'Epoche' may divide the sample into 2 subsamples suicide_2s <- suicide[, c(1,3,2) ] # reorder data that 'Epoche' is the last column ftab(suicide_2s) # check reordering suicide_2s_fre <- dat2fre(suicide_2s) res3 <- S2CFA(suicide_2s_fre) summary(res3) res4 <- S2CFA(suicide_2s_fre, ccor=TRUE) # with continuity correction summary(res4)
Calculates the binomial aproximation using stirling's formula (Version of function: V 1.0 - November 2013)
stirling_cfa( observed, expected = NULL, n = sum(observed), p = NULL, cum = T, verb = T )stirling_cfa( observed, expected = NULL, n = sum(observed), p = NULL, cum = T, verb = T )
observed |
a integer vector with observed freqencies |
expected |
a vector giving the expected frequencies. expected can be set to |
n |
number of trials (scalar) default is |
p |
a vector of cell probabilities. If p is not NULL the argument |
cum |
a logical - computation of cumulative density. If |
verb |
logical - verbose results: If |
Vector p must be of same length as observed _or_ p may be a scalar (e.g. in case of the zero-order CFA).
The routine autoselects the upper or lower tail:
if obs > exp then sum obs:n
else sum 0:obs
The stirling approximation cannot be evaluated if the observed frequency is 0 or n. Therefore, the proposal of A. von Eye (20xx) is adopted, taking the sum up to 1 or n-1, respectively.
R.W. Alexandrowicz
von Eye, A. (2002). Configural Frequency Analysis. Methods, Models, and Applications. Mahwah, NJ, LEA.
Data from the Krauth & Lienert suicide example for CFA (see Tables 39a and 39b; Krauth & Lienert, 1973). The data describe suicide patterns in pre- and post-WWII Germany – see von Eye, A., (2002); p. 385.
data(suicide)data(suicide)
A data.frame with 3 columns (as factors). The data is in data list representation – each row represents one case.
The three columns are named 'Geschlecht', 'Epoche' and 'Suizidart' which is 'gender', 'epoch' and 'type od suicide'. each of the variables are factors with the following levels:
Geschlecht: 'm' = 1 (male); 'w' = 2 (female)
Epoche: '44' = 1 (the epoch 1944); '52' = 2 (the epoch 1952)
Suizidart: 'Eh' = 1(hang); 'Es' = 2 (shoot); 'Et' = 3(drown); 'G' = 4(gas); 'H' = 5(crashing down); 'P' = 6(open vein); 'S' = 7(barbiturate);
Krauth, J., & Lienert, G. A. (1973). Die Konfigurationsfrequenzanalyse (KFA) und ihre Anwendung in Psychologie und Medizin: ein multivariates nichtparametrisches Verfahren zur Aufdeckung von Typen und Syndromen; mit 70 Tabellen. Freiburg; München: Alber Karl.
von Eye, A. (2002). Configural Frequency Analysis: Methods, models, and applications. Mahwah, N.J.: Lawrence Erlbaum Associates.
############################################################## data(suicide) # to load the data.frame included in the package class(suicide) dim(suicide) str(suicide)############################################################## data(suicide) # to load the data.frame included in the package class(suicide) dim(suicide) str(suicide)
S3 summary method for object of class"CFA"
## S3 method for class 'CFA' summary( object, digits = 3, type = "z.pChi", sorton = NULL, decreasing = FALSE, showall = TRUE, holm = FALSE, wide = FALSE, adjalpha = "bonferroni", ... )## S3 method for class 'CFA' summary( object, digits = 3, type = "z.pChi", sorton = NULL, decreasing = FALSE, showall = TRUE, holm = FALSE, wide = FALSE, adjalpha = "bonferroni", ... )
object |
object of class |
digits |
integer rounds the values to the specified number of decimal places, default is |
type |
character indicating which test to use for inference whether the observed pattern are 'Types', 'Antitypes' or not significant at all. Possible options for |
sorton |
sort results of local test by any column. By default the output is not sorted. Other options may be |
decreasing |
logical. Should the sort be increasing or decreasing? see |
showall |
logical with default |
holm |
logical with default |
wide |
logical with default |
adjalpha |
Adjustment method: |
... |
other parameters passed trough. |
Additional adjustment methods are "hochberg",
"hommel", "BH", "BY" and "fdr" (an alias
for "BH"). These methods use p.adjust on
computable p-values only, following the same test-family rule as Holm.
Hochberg and Hommel require appropriate dependence assumptions; BH and BY
control the false discovery rate rather than the family-wise error rate.
See p.adjust for assumptions and statistical interpretation.
The historical Bonferroni denominator and the "none" behavior are
retained. In particular, the reduced test-family rule for Holm and the new
methods is not silently applied to the existing Bonferroni decisions.
The final column p.adj contains the selected adjusted p-values
(raw p-values for "none"); old columns keep their positions.
Existing Holm.adj, Holm.crit and, where applicable,
Holland.adj remain available. Classification precedes rounding.
With adjalpha = "holm", decisions use
stats::p.adjust(p, method = "holm") on the non-missing p-values
only. Missing values (NA/NaN) do not contribute to the number
of comparisons. The historical strict rule, adjusted p-value less than
alpha, is retained. Decisions use full precision before rounding.
Only finite values in [0, 1] are computable p-values. Other numeric
values are excluded with a warning and treated as missing decisions.
The additional column Holm.adj contains adjusted p-values.
The existing Holm.crit column is retained as a diagnostic value:
alpha / (m - r + 1), where m is the number of tested values
and r is their rank (minimum rank for ties). A row-wise comparison
with this column alone does not implement the sequential Holm procedure.
Missing decisions are displayed as NA and are omitted when
showall = FALSE. The existing Holm columns retain their positions.
Functional cells are excluded from the Holm test family and retain
their "b" label. Other pre-existing adjustment methods retain their decisions.
A data frame of local results, with printed explanatory output.
Includes a final p.adj column. For Holm adjustment, includes Holm.crit and Holm.adj.
Holm, S. (1979). A simple sequentially rejective multiple test procedure. Scandinavian Journal of Statistics, 6(2), 65–70.
Bonferroni, C. E. (1935). Il calcolo delle assicurazioni su gruppi di teste. In S.O. Carboni (Ed.), Studi in Onore del Professore Salvatore Ortu Carboni (S. 13–60). Roma, Tipografia del Senato: Bardi.
Holland, B. S., & Copenhaver, M. D. (1987). An Improved Sequentially Rejective Bonferroni Test Procedure. Biometrics, 43(2), 417. https://doi.org/10.2307/2531823
data(LienertLSD) res <- CFA(LienertLSD, bintest = FALSE) summary(res, type = "pChi", adjalpha = "BH")data(LienertLSD) res <- CFA(LienertLSD, bintest = FALSE) summary(res, type = "pChi", adjalpha = "BH")
S3 summary method for object of class"S2CFA"
## S3 method for class 'S2CFA' summary( object, digits = 3, type = "ex.fisher.test", sorton = NULL, decreasing = FALSE, showall = TRUE, adjalpha = "bonferroni", ... )## S3 method for class 'S2CFA' summary( object, digits = 3, type = "ex.fisher.test", sorton = NULL, decreasing = FALSE, showall = TRUE, adjalpha = "bonferroni", ... )
object |
object of class |
digits |
integer rounds the values to the specified number of decimal places, default is |
type |
Test column: |
sorton |
sort results of local test by any column. By default the output is not sorted. Other options may be |
decreasing |
logical. Should the sort be increasing or decreasing? see |
showall |
logical with default |
adjalpha |
Adjustment method: |
... |
other parameters passed trough. |
Survey-weighted frequencies and Wald p-values are taken from
the weighted S2CFA() result; no integer rounding is performed.
The test assumes independent sampling units, without cluster or stratum
information. Non-computable p-values do not contribute to the Holm and
additional p.adjust test families. Summary and plot select the same test.
Additional adjustment methods are "hochberg",
"hommel", "BH", "BY" and "fdr" (an alias
for "BH"). These methods use p.adjust on
computable p-values only, following the same test-family rule as Holm.
Hochberg and Hommel require appropriate dependence assumptions; BH and BY
control the false discovery rate rather than the family-wise error rate.
See p.adjust for assumptions and statistical interpretation.
The historical Bonferroni denominator and the "none" behavior are
retained. In particular, the reduced test-family rule for Holm and the new
methods is not silently applied to the existing Bonferroni decisions.
The final column p.adj contains the selected adjusted p-values
(raw p-values for "none"); old columns keep their positions.
Existing Holm.adj, Holm.crit and, where applicable,
Holland.adj remain available. Classification precedes rounding.
With adjalpha = "holm", decisions use
stats::p.adjust(p, method = "holm") on the non-missing p-values
only. Missing values (NA/NaN) do not contribute to the number
of comparisons. The historical strict rule, adjusted p-value less than
alpha, is retained. Decisions use full precision before rounding.
Only finite values in [0, 1] are computable p-values. Other numeric
values are excluded with a warning and treated as missing decisions.
The additional column Holm.adj contains adjusted p-values.
The existing Holm.crit column is retained as a diagnostic value:
alpha / (m - r + 1), where m is the number of tested values
and r is their rank (minimum rank for ties). A row-wise comparison
with this column alone does not implement the sequential Holm procedure.
Missing decisions are displayed as NA and are omitted when
showall = FALSE. The existing Holm columns retain their positions.
A data frame of local results, with printed explanatory output.
Includes a final p.adj column. For Holm adjustment, includes Holm.crit and Holm.adj.
Holm, S. (1979). A simple sequentially rejective multiple test procedure. Scandinavian Journal of Statistics, 6(2), 65–70.
Bonferroni, C. E. (1935). Il calcolo delle assicurazioni su gruppi di teste. In S.O. Carboni (Ed.), Studi in Onore del Professore Salvatore Ortu Carboni (S. 13–60). Roma, Tipografia del Senato: Bardi.
data(Lienert1978) res <- S2CFA(Lienert1978) summary(res, adjalpha = "BY")data(Lienert1978) res <- S2CFA(Lienert1978) summary(res, adjalpha = "BY")
Calculates the Chi-square approximation to the z-test and the binomial approximation to the z-test.
z_tests_cfa(observed, expected, ccor = FALSE, ntotal = sum(observed))z_tests_cfa(observed, expected, ccor = FALSE, ntotal = sum(observed))
observed |
a vector giving the observed frequencies. |
expected |
a vector giving the expected frequencies. |
ccor |
either a logical (TRUE / FALSE) determining wether to apply a continuity correction or not to the Binomial Approximation of the z-Test. When set to |
ntotal |
optional a numeric giving the total number of observations. By default ntotal is calculated as |
An continuity correction can be applied to the binomial approximation – see argument ccor.
a list with z and p-values.
No references in the moment
####################################### # expected counts for LienertLSD data example. designmatrix<-design_cfg_cfa(kat=c(2,2,2)) # generate an designmatrix (only main effects) data(LienertLSD) # load example data observed<-LienertLSD[,4] # extract observed counts expected<-expected_cfa(des=designmatrix, observed=observed) # calculation of expected counts z_tests_cfa(observed,expected) ############################################################################## # expected counts for LienertLSD data example. designmatrix<-design_cfg_cfa(kat=c(2,2,2)) # generate an designmatrix (only main effects) data(LienertLSD) # load example data observed<-LienertLSD[,4] # extract observed counts expected<-expected_cfa(des=designmatrix, observed=observed) # calculation of expected counts z_tests_cfa(observed,expected) #######################################