lib: reliability, agreement, correlations, bootstrap¶
The user guide of this module: lib.
- apatools.lib.average_correlations(r, n, conf_level=0.95, method='two-tailed')[source]¶
Pool correlations from several samples (fixed-effect meta-analysis on Fisher’s z scale).
The correlations are Fisher-transformed (
z = atanh(r)), averaged with the inverse-variance weightsn - 3(the variance ofzis1 / (n - 3)), tested against zero and back-transformed. The model assumes one common population correlation: heterogeneity between the samples is neither tested nor modelled (use a random-effects model for that).- Parameters:
r (array-like of float) – Correlations, one per sample.
n (array-like of int) – Sample sizes, same length as
r.conf_level (float) – Confidence level of the interval, e.g. 0.95 (not a significance level). With
method="one-tailed"both limits use the one-sided critical value for this level.method ({"two-tailed", "one-tailed"}) – Two- or one-tailed p-value (one-tailed: half of the two-tailed value).
- Returns:
dict –
r_meanpooled correlation,z_meanpooled Fisher z,seits standard error,ztest statistic (z_mean / se),p-value,cil/cirlimits of the confidence interval of the pooled correlation.
References
Hedges, L. V., & Olkin, I. (1985). Statistical Methods for Meta-Analysis. Academic Press. Borenstein, M., Hedges, L. V., Higgins, J. P. T., & Rothstein, H. R. (2009). Introduction to Meta-Analysis. Wiley (ch. 6: correlations on Fisher’s z scale; ch. 11: fixed-effect model). https://doi.org/10.1002/9780470743386
- apatools.lib.bootstrap(*args, func=<function mean>, conf_level=0.95, n_rep=1000, seed=13)[source]¶
Percentile bootstrap confidence interval for a statistic.
- Parameters:
*args (array-like) – One or more equally long samples (resampled jointly by row).
func (callable) – Statistic computed on the resampled arrays, called as
func(*samples).conf_level (float) – Confidence level (e.g. 0.95), not a significance level.
n_rep (int) – Number of bootstrap replications.
seed (int, optional) – Seed of the random generator used for the resampling (a local generator: numpy’s global random state is not touched).
Nonegives different resamples on every call.
- Returns:
numpy.ndarray –
[lower, median, upper]percentiles of the bootstrap distribution.
Notes
The percentile method is simple but can be biased and too narrow for small samples or skewed statistics; the interval is taken from the non-missing replications (
nanpercentile).References
Efron, B., & Tibshirani, R. J. (1993). An Introduction to the Bootstrap. Chapman & Hall. https://doi.org/10.1007/978-1-4899-4541-9
- apatools.lib.cronbachs_alpha(data, bootstrap_iter=None, conf_level=0.95, seed=13)[source]¶
Cronbach’s alpha with a confidence interval.
alpha = k / (k - 1) * (1 - sum(item variances) / variance of the sum score)forkitems, computed from the sample covariance matrix. Alpha equals the reliability of the sum score only if the items are tau-equivalent (equal loadings on one factor) and their errors are uncorrelated; otherwise it underestimates the reliability (usemcdonald_omega(), which does not assume equal loadings). Kelley and Pornprasertmanit (2016) therefore advise against alpha as an estimate of population reliability and, if alpha is required, to report it along with a more appropriate coefficient; see also Sijtsma (2009). Alpha is computed from the raw covariances, so it changes when single items are rescaled (it does not change when all items are shifted or rescaled by the same factor).Two confidence intervals are available:
Analytic (default,
bootstrap_iter=None):alpha ± z * ASEwith the asymptotic standard error of alpha under normal theory (van Zyl et al., 2000; Duhachek & Iacobucci, 2004), which does not assume equal item variances or covariances. The upper limit is capped at 1. It relies on normally distributed items: for clearly non-normal items (skewed, few categories, heavy tails) or small samples usebootstrap_iter, see Padilla et al. (2012).Percentile bootstrap (
bootstrap_iter= number of resamples of respondents).
Items must be keyed in the same direction: a warning is given if alpha is negative, which means that the items correlate negatively on average (e.g. reverse-keyed items that were not recoded).
- Parameters:
data (pandas.DataFrame or array-like) – Item scores, one row per respondent and one column per item (at least 2 items and more respondents than items). Rows with missing values are dropped (listwise).
bootstrap_iter (int, optional) – Number of bootstrap resamples. If None, the analytic interval is used.
conf_level (float) – Confidence level of the interval, e.g. 0.95 (not a significance level).
seed (int, optional) – Seed of the random generator used for the bootstrap (local; numpy’s global random state is not touched).
Nonegives different resamples on every call.
- Returns:
alpha, lower, upper (float) – The estimate from the original sample and the limits of its confidence interval. All are
nan(with a warning) if the sum score has no variance; the limits arenanif the analytic standard error cannot be computed.- Raises:
ValueError – For data that are not two-dimensional or numeric, fewer than 2 items, not more respondents than items, constant items, or invalid
bootstrap_iter/conf_level.
References
Cronbach, L. J. (1951). Coefficient alpha and the internal structure of tests. Psychometrika, 16(3), 297-334. https://doi.org/10.1007/BF02310555
van Zyl, J. M., Neudecker, H., & Nel, D. G. (2000). On the distribution of the maximum likelihood estimator of Cronbach’s alpha. Psychometrika, 65(3), 271-280. https://doi.org/10.1007/BF02296146
Duhachek, A., & Iacobucci, D. (2004). Alpha’s standard error (ASE): An accurate and precise confidence interval estimate. Journal of Applied Psychology, 89(5), 792-808. https://doi.org/10.1037/0021-9010.89.5.792
Padilla, M. A., Divers, J., & Newton, M. (2012). Coefficient alpha bootstrap confidence interval under nonnormality. Applied Psychological Measurement, 36, 331-348. https://doi.org/10.1177/0146621612445470
Sijtsma, K. (2009). On the use, the misuse, and the very limited usefulness of Cronbach’s alpha. Psychometrika, 74(1), 107-120. https://doi.org/10.1007/s11336-008-9101-0
Kelley, K., & Pornprasertmanit, S. (2016). Confidence intervals for population reliability coefficients: Evaluation of methods, recommendations, and software for composite measures. Psychological Methods, 21(1), 69-92. https://doi.org/10.1037/a0040086
- apatools.lib.dependent_correlations(xy, xz, yz, n, method='steiger', twotailed=True, conf_level=0.95)[source]¶
Compare two dependent (overlapping) correlations, r(x, y) and r(x, z), from one sample.
- Parameters:
xy (float) – The two correlations to compare; they share the variable x.
xz (float) – The two correlations to compare; they share the variable x.
yz (float) – Correlation between y and z.
n (int) – Number of observations (the same for all three correlations).
method ({"steiger", "zou"}) –
"steiger": Williams’ (1959) t test as given by Steiger (1980), df = n - 3."zou": confidence interval of the difference (Zou, 2007).twotailed (bool) – Two- or one-tailed p-value; only used by
"steiger".conf_level (float) – Confidence level of the interval, e.g. 0.95 (not a significance level); only used by
"zou".
- Returns:
(t, p) for
"steiger", (lower, upper) limit of the differencexy - xzfor"zou".
- apatools.lib.fleiss_kappa(df, return_per_item_agreement=False, method='two-tailed')[source]¶
Fleiss’ kappa for the agreement of several raters, with a test against chance agreement.
- Parameters:
df (pandas.DataFrame) – One row per rated item, one column per rater, the category of each rating as value. Every item has to be rated by the same number of raters (Fleiss, 1971): items with a missing rating (NaN / None) are left out completely (listwise deletion, as in the R package
irr) because treating “missing” as a category would inflate agreement.return_per_item_agreement (bool) – Also return the agreement
P_iof every item (NaN for the items that were left out).method ({"two-tailed", "one-tailed"}) – p-value of the z test of H0: kappa = 0 (one-tailed: agreement better than chance).
- Returns:
kappa, z, p (and the per-item agreement as a Series if requested) –
kappa = (mean(P_i) - P_e) / (1 - P_e)(Fleiss, 1971).z = kappa / SE0whereSE0is the standard error of kappa under H0 (all ratings independent, Fleiss, Nee & Landis, 1979; the formula ofirr::kappam.fleiss):Var0(kappa) = 2 / (N n (n - 1)) * [(sum p_j q_j)^2 - sum p_j q_j (q_j - p_j)] / (sum p_j q_j)^2
with
Nitems,nraters,p_jthe proportion of all ratings in categoryjandq_j = 1 - p_j.zandpare NaN if kappa is undefined (all ratings in one category).
Notes
Landis & Koch (1977) call kappa < 0 poor, .00-.20 slight, .21-.40 fair, .41-.60 moderate, .61-.80 substantial and .81-1.00 almost perfect agreement. The z test only tells whether agreement exceeds chance, not how large it is.
References
Fleiss, J. L. (1971). Measuring nominal scale agreement among many raters. Psychological Bulletin, 76(5), 378-382. https://doi.org/10.1037/h0031619 Fleiss, J. L., Nee, J. C. M., & Landis, J. R. (1979). Large sample variance of kappa in the case of different sets of raters. Psychological Bulletin, 86(5), 974-977. https://doi.org/10.1037/0033-2909.86.5.974 Landis, J. R., & Koch, G. G. (1977). The measurement of observer agreement for categorical data. Biometrics, 33(1), 159-174. https://doi.org/10.2307/2529310
- apatools.lib.gini(values, drop_zeros=False, tolerance=1e-06)[source]¶
Gini coefficient of inequality of a sample of non-negative values.
G = sum_i (2 i - n - 1) x_(i) / (n * sum(x))for the sorted valuesx_(1) <= ... <= x_(n): 0 means perfect equality, values near 1 mean that one unit holds almost everything (the maximum for a sample ofnis(n - 1) / n). This is the sample Gini without then / (n - 1)small-sample correction, identical toineq::Gini(x, corr=FALSE)in R.- Parameters:
values (iterable of float) – The values (e.g. incomes); flattened, all treated alike.
drop_zeros (bool) – Leave values below
tolerance(zeros) out of the calculation instead of counting them as units with (almost) nothing.tolerance (float) – Values below it count as zero. If any value is below it, all values are shifted up by the absolute minimum so that none is negative (the Gini coefficient is not defined for negative values; the shift changes the result, so negative input should be avoided). Unless
drop_zeros,toleranceis then added to every value so that no value is exactly zero (a bias of the order oftolerance).
- Returns:
float
References
Gini, C. (1912). Variabilità e mutabilità. Bologna: Tipografia di Paolo Cuppini. Lorenz, M. O. (1905). Methods of measuring the concentration of wealth. Publications of the American Statistical Association, 9(70), 209-219. https://doi.org/10.1080/15225437.1905.10503443 Sen, A. (1973). On Economic Inequality. Oxford: Clarendon Press.
- apatools.lib.gini_from_percentiles(values, percentiles, values_are_shares=False)[source]¶
Gini coefficient from grouped data: points of the Lorenz curve (e.g. income deciles).
The Lorenz curve is interpolated linearly between the points (and from the origin to the first point) and
G = 1 - 2 * area under the curveis computed with the trapezoid rule. Because the true Lorenz curve is convex, the straight segments lie above it: the result is a lower bound of the Gini coefficient of the underlying data and gets closer with more points.- Parameters:
values (array-like) – The cumulative amount held by the poorest
percentilespercent of the population: cumulative shares in percent (values_are_shares=True, e.g.[1.5, 5.0, ..., 100]) or cumulative amounts (e.g.[100, 150, 350, ..., 1200], divided by their maximum, so the last point has to be the total).percentiles (array-like) – Cumulative share of the population in percent, increasing, ending at 100 (e.g.
[10, 20, ..., 100]). A starting point at 0 is added if missing.values_are_shares (bool) –
valuesare cumulative shares in percent (divided by 100) instead of cumulative amounts.
- Returns:
float – Gini coefficient between 0 (equality) and 1.
References
Lorenz, M. O. (1905). Methods of measuring the concentration of wealth. Publications of the American Statistical Association, 9(70), 209-219. https://doi.org/10.1080/15225437.1905.10503443 Gini, C. (1912). Variabilità e mutabilità. Bologna: Tipografia di Paolo Cuppini.
- apatools.lib.htmt_ratio(data, construct_a, construct_b, method='spearman')[source]¶
Heterotrait-monotrait (HTMT) ratio of correlations, a criterion of discriminant validity.
HTMT = mean(|r| between the items of A and the items of B) / sqrt(mean(|r| among the items of A) * mean(|r| among the items of B)): the similarity of items of different constructs (heterotrait) relative to the similarity of items of the same construct (monotrait). Values near 1 mean that the two constructs are not empirically distinct.Henseler et al. (2015) propose a threshold of .85 (Kline, 2011; conservative) or .90 (Gold et al., 2001; liberal); an HTMT significantly below the threshold (bootstrap confidence interval, not provided here) supports discriminant validity. The ratio needs at least two items per construct (otherwise it is NaN).
- Parameters:
data (pandas.DataFrame) – Item scores, one column per item. Rows with a missing value in any of the items are dropped.
construct_a (list of str) – Column names of the items of constructs A and B.
construct_b (list of str) – Column names of the items of constructs A and B.
method ({"spearman", "pearson"}) – Correlation coefficient (
DataFrame.corr); Henseler et al. use Pearson correlations, Spearman is more robust for ordinal items.
- Returns:
float
References
Henseler, J., Ringle, C. M., & Sarstedt, M. (2015). A new criterion for assessing discriminant validity in variance-based structural equation modeling. Journal of the Academy of Marketing Science, 43(1), 115-135. https://doi.org/10.1007/s11747-014-0403-8 Kline, R. B. (2011). Principles and Practice of Structural Equation Modeling (3rd ed.). Guilford. Gold, A. H., Malhotra, A., & Segars, A. H. (2001). Knowledge management: An organizational capabilities perspective. Journal of Management Information Systems, 18(1), 185-214. https://doi.org/10.1080/07421222.2001.11045669
- apatools.lib.independent_correlations(xy, ab, n1, n2=None, method='fisher', twotailed=True, conf_level=0.95)[source]¶
Compare two independent correlations (from different samples).
- Parameters:
xy (float) – The two correlations.
ab (float) – The two correlations.
n1 (int) – Sample sizes of
xyandab;n2defaults ton1.n2 (int) – Sample sizes of
xyandab;n2defaults ton1.method ({"fisher", "zou"}) –
"fisher": z test on the Fisher-transformed correlations."zou": confidence interval of the difference (Zou, 2007).twotailed (bool) – Two- or one-tailed p-value; only used by
"fisher".conf_level (float) – Confidence level of the interval, e.g. 0.95 (not a significance level); only used by
"zou".
- Returns:
(z, p) for
"fisher"(z is the absolute value), (lower, upper) limit ofxy - abfor"zou".
- apatools.lib.krippendorffs_alpha(df, measurement='nominal', return_per_item_agreement=False, return_bootstraped_z_score=True, n_iter_for_bootstrap=100, bootstrap_seed=13, method='two-tailed')[source]¶
Krippendorff’s alpha, a permutation z-score and p-value, and optionally the agreement per item.
Alpha is
1 - D_o / D_e: the observed disagreement relative to the disagreement expected if the ratings were paired by chance. It is 1 for perfect agreement, about 0 for chance agreement and negative for systematic disagreement. It works with any number of raters, with missing ratings (they are excluded, not counted as a category; units with fewer than two ratings are ignored) and for four levels of measurement. Krippendorff recommends alpha >= .80 for firm conclusions and alpha >= .667 for tentative ones.- Parameters:
df (pandas.DataFrame or array-like) – Ratings with one row per unit (item) and one column per rater (the transpose of the layout of the
krippendorffpackage). Missing ratings are NaN/None.measurement ({"nominal", "ordinal", "interval", "ratio"}) – Level of measurement, i.e. which differences between two ratings are counted.
nominal: equal or not (ratings may be of any type);ordinal: depends on the ranks and frequencies of the categories between the two ratings;interval: squared difference of the values;ratio: squared relative difference((a - b) / (a + b))**2(non-negative values). Ordinal, interval and ratio ratings must be numeric: the values are used (for ordinal, their order), not the position of a category.return_per_item_agreement (bool) – Also return the share of the ratings of each item that equals its most frequent rating (
nanfor items with fewer than two ratings).return_bootstraped_z_score (bool) – Compute
zandp. Otherwise they arenan.n_iter_for_bootstrap (int) – Number of permutations for the null distribution.
bootstrap_seed (int, optional) – Seed of the (local) random generator; numpy’s global random state is not touched.
method ({"two-tailed", ...}) –
"two-tailed"doubles the p-value, anything else gives the one-sided value.
- Returns:
alpha, z, p (float) –
z = (alpha - mean) / sdof the null distribution of alpha, obtained by permuting the ratings of every rater among the units that rater rated (so the design, i.e. who rated what, and the distribution of each rater’s ratings are kept);pfrom the normal distribution. Null hypothesis: agreement is due to chance.alphaisnanif all ratings are identical (undefined).per_item_agreement (pandas.Series) – Only if
return_per_item_agreementis True (as fourth element).
- Raises:
ValueError – For an unknown
measurement, fewer than 2 raters, no unit with two ratings, or non-numeric ratings with the ordinal, interval and ratio levels.
References
Krippendorff, K. (2011). Computing Krippendorff’s alpha-reliability. Annenberg School for Communication Departmental Papers. https://repository.upenn.edu/asc_papers/43
- apatools.lib.log_transform(values)[source]¶
Signed pseudo-logarithm
sign(x) * log10(1 + |x|).Defined for zero and negative values (
log_transform(0) == 0), odd (f(-x) == -f(x)) and close tolog10(x)for large|x|; useful for skewed data that contain zeros or negative numbers (e.g. changes, balances). The shift by 1 makes the transform depend on the unit of measurement.- Parameters:
values (iterable of float) – Flattened to one dimension.
- Returns:
numpy.ndarray – Transformed values, same length.
- apatools.lib.mcdonald_omega(data, bootstrap_iter=None, conf_level=0.95, seed=13, robust=False, varphi=0.1, standardized=True)[source]¶
McDonald’s omega (omega total) with a confidence interval: the reliability of the sum score of a scale under a one-factor model with unequal loadings (congeneric items).
omega = (sum(loadings))**2 / ((sum(loadings))**2 + sum(uniquenesses))with the loadings and uniquenesses of a one-factor model estimated by maximum likelihood (multivariate normal theory). For a scale with subscales (several factors) usemcdonald_omega_bifactor(). Unlike Cronbach’s alpha, omega does not assume equal loadings: for equal loadings (tau-equivalent items) they coincide, otherwise alpha is lower.By default omega is that of the standardized items, which does not change when items are rescaled or shifted. With
standardized=Falseit is the reliability of the sum score of the items as they are (loadings and uniquenesses in the metric of the items), the definition of Zhang & Yuan (2016) and of the R packages lavaan / semTools; the two differ when the items have different variances.With
robust=Truethe covariance matrix of the items is replaced by a Huber-type M-estimate that gives cases far from the center (in the Mahalanobis distance) weights below one (Yuan & Bentler, 1998; Zhang & Yuan, 2016), so that a few outlying respondents cannot drive omega.varphiis the share of the cases that is downweighted under normality (0.1: a tenth). The delta-method interval then uses the sandwich covariance matrix of the estimator (Yuan & Bentler, 2002; Zhang & Yuan, 2016), which is also valid for non-normal data.varphi=0keeps the sample covariance matrix but gives this distribution-free (robust) standard error.Two confidence intervals are available:
Delta method (default,
bootstrap_iter=None): omega is a smooth function of the model parameters, so its standard error follows from the asymptotic covariance matrix of the ML estimates (Raykov, 2002; for the structural equation modelling formulation see Raykov & Shrout, 2002). The interval is computed on the logit scale and transformed back, so that it stays within (0, 1); Kelley and Pornprasertmanit (2016) found that a logistic transformation improved the coverage of standard-error based intervals. Withoutrobustthe interval relies on normally distributed items. In their simulations, normal-theory intervals did not perform well for non-normal items, and they recommend bootstrap intervals when coefficient omega is used: usebootstrap_iterfor items that are clearly not normal (skewed, few categories, heavy tails) or for small samples.Percentile bootstrap (
bootstrap_iter= number of resamples of respondents; withrobustthe robust estimate is recomputed in every resample).
Assumptions: the items measure a single factor (unidimensional scale) and are continuous (for ordinal items with few categories, polychoric correlations would be needed), and are keyed in the same direction. Reverse-keyed items must be recoded before: a warning is given if the loadings have different signs, and omega is then too low. The one-factor model is assumed to fit; with population model error omega no longer equals the reliability and its intervals cover less often (Kelley & Pornprasertmanit, 2016).
- Parameters:
data (pandas.DataFrame or array-like) – Item scores, one row per respondent and one column per item (at least 3 items and more respondents than items). Rows with missing values are dropped (listwise).
bootstrap_iter (int, optional) – Number of bootstrap resamples. If None, the delta-method interval is used.
conf_level (float) – Confidence level of the interval, e.g. 0.95 (not a significance level).
seed (int, optional) – Seed of the random generator used for the bootstrap (local; numpy’s global random state is not touched).
Nonegives different resamples on every call.robust (bool, default False) – Use the Huber-type M-estimate of the covariance matrix and the sandwich standard error.
varphi (float, default 0.1) – Share of cases downweighted under normality, in [0, 1) (only used with
robust; 0 is the sample covariance matrix with the distribution-free standard error).standardized (bool, default True) – Omega of the standardized items (True) or of the raw sum score (False).
- Returns:
omega, lower, upper (float) – The estimate from the original sample and the limits of its confidence interval. The limits are
nan(with a warning) if the delta method cannot be used, i.e. for a Heywood case (a uniqueness on its lower bound of .005) or a singular information matrix.- Raises:
ValueError – For data that are not two-dimensional or numeric, fewer than 3 items, not more respondents than items, constant items, or invalid
bootstrap_iter/conf_level/varphi.
References
Raykov, T. (2002). Analytic estimation of standard error and confidence interval for scale reliability. Multivariate Behavioral Research, 37(1), 89-103. https://doi.org/10.1207/s15327906mbr3701_04
Raykov, T., & Shrout, P. E. (2002). Reliability of scales with general structure: Point and interval estimation using a structural equation modeling approach. Structural Equation Modeling: A Multidisciplinary Journal, 9(2), 195-212. https://doi.org/10.1207/S15328007SEM0902_3
Kelley, K., & Pornprasertmanit, S. (2016). Confidence intervals for population reliability coefficients: Evaluation of methods, recommendations, and software for composite measures. Psychological Methods, 21(1), 69-92. https://doi.org/10.1037/a0040086
Flora, D. B. (2020). Your coefficient alpha is probably wrong, but which coefficient omega is right? A tutorial on using R to obtain better reliability estimates. Advances in Methods and Practices in Psychological Science, 3(4), 484-501. https://doi.org/10.1177/2515245920951747
Yuan, K.-H., & Bentler, P. M. (1998). Structural equation modeling with robust covariances. Sociological Methodology, 28(1), 363-396. https://doi.org/10.1111/0081-1750.00052
Yuan, K.-H., & Bentler, P. M. (2002). On robustness of the normal-theory based asymptotic distributions of three reliability coefficient estimates. Psychometrika, 67(2), 251-259. https://doi.org/10.1007/BF02294845
Zhang, Z., & Yuan, K.-H. (2016). Robust coefficients alpha and omega and confidence intervals with outlying observations and missing data: Methods and software. Educational and Psychological Measurement, 76(3), 387-411. https://doi.org/10.1177/0013164415594658
- apatools.lib.mcdonald_omega_bifactor(data, groups, bootstrap_iter=None, conf_level=0.95, seed=13, robust=False, varphi=0.1, standardized=True)[source]¶
Omega hierarchical, omega total and subscale omegas of a scale with subscales, from a bifactor model.
A confirmatory bifactor model is fitted by maximum likelihood: every item loads on a general factor and on the group factor of its subscale; all factors are uncorrelated. With the loadings
gon the general factor,s_kon the group factorkand the uniquenessesuof the items (standardized, or in the metric of the items withstandardized=False), and the total varianceV = (sum g)^2 + sum_k (sum_{i in k} s_ki)^2 + sum uof the sum score:omega_h=(sum g)^2 / V: the share of the variance of the total score that is due to the general factor (omega hierarchical; McDonald, 1999; Zinbarg et al., 2005): the reliability of the total score as a measure of the general construct. Compare it withomega_t: the closer they are, the less the group factors contribute to the total score.omega_t=((sum g)^2 + sum_k (sum s_k)^2) / V: the reliability of the total score, general and group factors together (omega total of a multidimensional scale).ecv: the explained common variance,sum g^2 / (sum g^2 + sum s^2): the share of the common variance of the items that is due to the general factor (Rodriguez et al., 2016).omega_s[k]=((sum_k g)^2 + (sum_k s)^2) / V_kandomega_hs[k]=(sum_k s)^2 / V_kfor the subscalekwith the varianceV_kof its sum score: the reliability of the subscale score, and its reliability after removing the general factor, i.e. the reliable variance that is specific to the subscale (Reise, 2012; Rodriguez et al., 2016). A lowomega_hsmeans that the subscale adds little beyond the total score.
Items that are not listed in
groupsload only on the general factor.Confidence intervals: with
bootstrap_iter=Nonethe sandwich (delta-method) interval of the ML estimates on the logit scale (normal theory; withrobustthe covariance matrix of the M-estimator is used, as inmcdonald_omega()), otherwise the percentile bootstrap. Bifactor models often give improper solutions (a uniqueness at zero, a group factor without loadings) in small samples or when the subscales are not distinct: the analytic interval is then not available (nanwith a warning) and the bootstrap is the alternative. The estimates assume that the bifactor model fits; omega_h and the subscale coefficients are sensitive to model misfit.- Parameters:
data (pandas.DataFrame or array-like) – Item scores, one row per respondent and one column per item (more respondents than items). Rows with missing values are dropped (listwise).
groups (dict or list of lists) – The items of the subscales:
{"name": ["item1", "item2", ...], ...}or a list of lists of column names (positions for arrays), at least two groups of at least three items each. An item may belong to one group only. Items must be keyed in the same direction.bootstrap_iter – As in
mcdonald_omega().conf_level – As in
mcdonald_omega().seed – As in
mcdonald_omega().robust – As in
mcdonald_omega().varphi – As in
mcdonald_omega().standardized – As in
mcdonald_omega().
- Returns:
pandas.DataFrame – One row per coefficient (
omega_h,omega_t,ecv, thenomega_s[name]andomega_hs[name]of every group) with the columnsestimate,lowerandupper.- Raises:
ValueError – For invalid
groups(unknown or repeated items, fewer than two groups or fewer than three items in a group) or data and options as inmcdonald_omega().
References
McDonald, R. P. (1999). Test Theory: A Unified Treatment. Lawrence Erlbaum. https://doi.org/10.4324/9781410601087
Zinbarg, R. E., Revelle, W., Yovel, I., & Li, W. (2005). Cronbach’s alpha, Revelle’s beta, and McDonald’s omega h: Their relations with each other and two alternative conceptualizations of reliability. Psychometrika, 70(1), 123-133. https://doi.org/10.1007/s11336-003-0974-7
Revelle, W., & Zinbarg, R. E. (2009). Coefficients alpha, beta, omega, and the glb: Comments on Sijtsma. Psychometrika, 74(1), 145-154. https://doi.org/10.1007/s11336-008-9102-z
Reise, S. P. (2012). The rediscovery of bifactor measurement models. Multivariate Behavioral Research, 47(5), 667-696. https://doi.org/10.1080/00273171.2012.715555
Rodriguez, A., Reise, S. P., & Haviland, M. G. (2016). Evaluating bifactor models: Calculating and interpreting statistical indices. Psychological Methods, 21(2), 137-150. https://doi.org/10.1037/met0000045
Browne, M. W. (1984). Asymptotically distribution-free methods for the analysis of covariance structures. British Journal of Mathematical and Statistical Psychology, 37(1), 62-83. https://doi.org/10.1111/j.2044-8317.1984.tb00789.x
Zhang, Z., & Yuan, K.-H. (2016). Robust coefficients alpha and omega and confidence intervals with outlying observations and missing data: Methods and software. Educational and Psychological Measurement, 76(3), 387-411. https://doi.org/10.1177/0013164415594658
- apatools.lib.rho_rxy_rxz(rxy, rxz, ryz)[source]¶
Estimated correlation between two overlapping correlations
rxyandrxz.Needed for the confidence interval of the difference of two dependent correlations (
dependent_correlations(),method="zou"): the covariance of the two estimates, scaled to a correlation (Zou, 2007; after Dunn & Clark, 1969, and Steiger, 1980).- Parameters:
- Returns:
float
References
Zou, G. Y. (2007). Toward using confidence intervals to compare correlations. Psychological Methods, 12(4), 399-413. https://doi.org/10.1037/1082-989x.12.4.399 Dunn, O. J., & Clark, V. A. (1969). Correlation coefficients measured on the same individuals. Journal of the American Statistical Association, 64(325), 366-377. https://doi.org/10.1080/01621459.1969.10500981
- apatools.lib.rz_ci(r, n, conf_level=0.95)[source]¶
Confidence interval of a correlation via Fisher’s z transformation.
tanh(atanh(r) +- z_crit / sqrt(n - 3)): asymmetric aroundrand always within (-1, 1). Assumes bivariate normality and a sample (not population) correlation.- Parameters:
- Returns:
numpy.ndarray –
[lower, upper].
References
Fisher, R. A. (1921). On the “probable error” of a coefficient of correlation deduced from a small sample. Metron.
- apatools.lib.z_transform(values, return_params=False, ignore_errors=True)[source]¶
z-transformation (standardization) with the mean and the population standard deviation (
ddof=0) of the non-missing values; NaNs stay NaN.If the standard deviation is zero (constant values) or undefined (no values, only NaNs) the z-scores do not exist: a
ValueErroris raised, or, withignore_errors=True, an array of NaN is returned (without any division by zero). Withreturn_paramsthe mean and the standard deviation are returned as well.