Title: | Latent Class Discriminant Analysis |
---|---|
Description: | Providing a method for Local Discrimination via Latent Class Models. The approach is described in <https://www.r-project.org/conferences/useR-2009/abstracts/pdf/Bucker.pdf>. |
Authors: | Michael Buecker |
Maintainer: | Michael Buecker <[email protected]> |
License: | GPL |
Version: | 0.3.2 |
Built: | 2025-02-08 02:35:09 UTC |
Source: | https://github.com/cran/lcda |
Local Discrimination via Latent Class Models with common components.
cclcda(x, ...) ## Default S3 method: cclcda(x, grouping=NULL, prior=NULL, probs.start=NULL, nrep=1, m=3, maxiter = 1000, tol = 1e-10, subset, na.rm = FALSE, ...) ## S3 method for class 'formula' cclcda(formula, data, ...)
cclcda(x, ...) ## Default S3 method: cclcda(x, grouping=NULL, prior=NULL, probs.start=NULL, nrep=1, m=3, maxiter = 1000, tol = 1e-10, subset, na.rm = FALSE, ...) ## S3 method for class 'formula' cclcda(formula, data, ...)
x |
Matrix or data frame containing the explanatory variables. Manifest variables must contain only integer values, and must be coded with consecutive values from 1 to the maximum number of outcomes for each variable. All missing values should be entered as NA. |
grouping |
A factor specifying the class for each observation; if not specified, the first column of 'data' is taken. The class must be coded by integer values with consecutive values from 1 to the maximum number of classes. |
formula |
Formula of the form |
data |
Data frame from which variables specified in formula are to be taken. |
prior |
The prior probabilities of class membership. If unspecified, the class proportions for the training set are used. If present, the probabilities should be specified in the order of the factor levels. |
probs.start |
A list of matrices (per variable) of response probabilities |
nrep |
Number of times to estimate the model, using different random values of |
m |
The number of subclasses. Can be either a vector containing the number of subclasses per class or a number of subclasses for all classes. Default is |
maxiter |
The maximum number of iterations through which the estimation algorithm will cycle. |
tol |
A tolerance value for judging when convergence has been reached. When the one-iteration change in the estimated log-likelihood is less than |
subset |
An index vector specifying the cases to be used in the training sample. |
na.rm |
Logical, for how |
... |
Further arguments to be passed to |
The cclcda
-function performs a Common Components Latent Class Discriminant Analysis (CCLCDA). The model to estimate is
where is the latent subclass index,
is the variable index and
is the observation index. The variable
is
if the variable
of this observation is
.
This common Latent Class Modell will be estimated for all classes by the
poLCA
-function (see poLCA
) and class conditional mixing proportions are computed afterwards. These weights are computed by
where is the class index and
the number of observations in class
.
The LCA uses the assumption of local independence to estimate a mixture model of latent multi-way tables, the number of which (m
) is specified by the user. Estimated parameters include the latent-class-conditional response probabilities for each manifest variable and the class conditional mixing proportions
denoting population share of observations corresponding to each latent multi-way table per class.
Posterior class probabilities can be estimated with the predict
method.
A list of class cclcda
containing the following components:
call |
The (matched) function call. |
lca.theta |
The estimated class conditional response probabilities of the LCA given as a list of matrices like |
lca.w |
The estimated mixing proportions of the LCA. |
lca.wmk |
The estimated class conditional mixing proportions of the LCA. |
prior |
Prior probabilites. |
m |
Number of latent subclasses. |
r |
Number of different responses per variable. |
k |
Number of classes. |
d |
Number of variables. |
aic |
Value of the AIC for each class conditional Latent Class Model. |
bic |
Value of the BIC for each class conditional Latent Class Model. |
Gsq |
The likelihood ratio/deviance statistic for each class conditional model. |
Chisq |
The Pearson Chi-square goodness of fit statistic for fitted vs. observed multiway tables for each class conditional model. |
entropy |
Value of the weighted entropy as described below. |
gini |
Value of the weighted Gini coefficient as described below. |
chi.stat |
Value of the Chi-square test statistik of the test of latent class membership and class membership as described below. |
chi.p |
P Value of the Chi-square of the test of latent class membership and class membership as described below. |
If the number of latent classes per class is unknown a model selection must be accomplished to determine the value of m
. For this goal there are some model selection criteria implemented. The AIC, BIC, likelihood ratio statistic and the Chi-square goodness of fit statistic are taken from the poLCA-function (see poLCA
).
Additionally cclcda
provides quality criteria which should give insight into the model's classification potential. These criteria are similar to the splitting criteria of classification trees. The impurity measures are
– Weighted entropy: The weighted entropy is given by
– Weighted Gini coefficient: The weighted Gini coefficient is given by
– Pearson's Chi-square test: A Pearson's Chi-square test is performed to test the independence of latent class membership and class membership.
Michael B\"ucker
predict.cclcda
, lcda
, predict.lcda
, cclcda2
, predict.cclcda2
, poLCA
# response probabilites probs1 <- list() probs1[[1]] <- matrix(c(0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1, 0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7), nrow=4, byrow=TRUE) probs1[[2]] <- matrix(c(0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1, 0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1), nrow=4, byrow=TRUE) probs1[[3]] <- matrix(c(0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7, 0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1), nrow=4, byrow=TRUE) probs1[[4]] <- matrix(c(0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1, 0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1), nrow=4, byrow=TRUE) prior <- c(0.5,0.5) wmk <- matrix(c(0.45,0.45,0.05,0.05,0.05,0.05,0.45,0.45), ncol=4, nrow=2, byrow=TRUE) wkm <- apply(wmk*prior, 2, function(x) x/sum(x)) # generation of training data data_temp <- poLCA.simdata(N = 1000, probs = probs1, nclass = 2, ndv = 4, nresp = 4, P=rep(0.25,4)) data <- data_temp$dat lclass <- data_temp$trueclass grouping <- numeric() for (i in 1:length(lclass)) { grouping[i] <- sample(c(1,2),1, prob=wkm[,lclass[i]]) } # generation of test data data_temp <- poLCA.simdata(N = 500, probs = probs1, nclass = 2, ndv = 4, nresp = 4, P=rep(0.25,4)) data.test <- data_temp$dat lclass <- data_temp$trueclass grouping.test <- numeric() for (i in 1:length(lclass)) { grouping.test[i] <- sample(c(1,2),1, prob=wkm[,lclass[i]]) } # cclcda-procedure object <- cclcda(data, grouping, m=4) object
# response probabilites probs1 <- list() probs1[[1]] <- matrix(c(0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1, 0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7), nrow=4, byrow=TRUE) probs1[[2]] <- matrix(c(0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1, 0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1), nrow=4, byrow=TRUE) probs1[[3]] <- matrix(c(0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7, 0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1), nrow=4, byrow=TRUE) probs1[[4]] <- matrix(c(0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1, 0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1), nrow=4, byrow=TRUE) prior <- c(0.5,0.5) wmk <- matrix(c(0.45,0.45,0.05,0.05,0.05,0.05,0.45,0.45), ncol=4, nrow=2, byrow=TRUE) wkm <- apply(wmk*prior, 2, function(x) x/sum(x)) # generation of training data data_temp <- poLCA.simdata(N = 1000, probs = probs1, nclass = 2, ndv = 4, nresp = 4, P=rep(0.25,4)) data <- data_temp$dat lclass <- data_temp$trueclass grouping <- numeric() for (i in 1:length(lclass)) { grouping[i] <- sample(c(1,2),1, prob=wkm[,lclass[i]]) } # generation of test data data_temp <- poLCA.simdata(N = 500, probs = probs1, nclass = 2, ndv = 4, nresp = 4, P=rep(0.25,4)) data.test <- data_temp$dat lclass <- data_temp$trueclass grouping.test <- numeric() for (i in 1:length(lclass)) { grouping.test[i] <- sample(c(1,2),1, prob=wkm[,lclass[i]]) } # cclcda-procedure object <- cclcda(data, grouping, m=4) object
Local Discrimination via Latent Class Models with common components
cclcda2(x, ...) ## Default S3 method: cclcda2(x, grouping=NULL, prior=NULL, probs.start=NULL, wmk.start=NULL, nrep=1, m=3, maxiter = 1000, tol = 1e-10, subset, na.rm = FALSE, ...) ## S3 method for class 'formula' cclcda2(formula, data, ...)
cclcda2(x, ...) ## Default S3 method: cclcda2(x, grouping=NULL, prior=NULL, probs.start=NULL, wmk.start=NULL, nrep=1, m=3, maxiter = 1000, tol = 1e-10, subset, na.rm = FALSE, ...) ## S3 method for class 'formula' cclcda2(formula, data, ...)
x |
Matrix or data frame containing the explanatory variables. Manifest variables must contain only integer values, and must be coded with consecutive values from 1 to the maximum number of outcomes for each variable. All missing values should be entered as NA. |
grouping |
A factor specifying the class for each observation; if not specified, the first column of 'data' is taken. The class must be coded by integer values with consecutive values from 1 to the maximum number of classes. |
formula |
Formula of the form |
data |
Data frame from which variables specified in formula are to be taken. |
prior |
The prior probabilities of class membership. If unspecified, the class proportions for the training set are used. If present, the probabilities should be specified in the order of the factor levels. |
probs.start |
A list of matrices (per variable) of response probabilities |
wmk.start |
A matrix of starting values for the parameter |
nrep |
Number of times to estimate the model, using different random values of |
m |
The number of subclasses. Can be either a vector containing the number of subclasses per class or a number of subclasses for all classes. Default is |
maxiter |
The maximum number of iterations through which the estimation algorithm will cycle. |
tol |
A tolerance value for judging when convergence has been reached. When the one-iteration change in the estimated log-likelihood is less than |
subset |
An index vector specifying the cases to be used in the training sample. |
na.rm |
Logical, for how |
... |
Further arguments to be passed to |
The cclcda2
-function performs a Common Components Latent Class Discriminant Analysis 2 (CCLCDA2). The class conditional model to estimate is
where is the latent subclass index,
is the variable index and
is the observation index. The variable
is
if the variable
of this observation is
.
This Latent Class Modell will be estimated. The class conditional mixing proportions
and the parameters
are computed in every step of the EM-Algorithm.
The LCA uses the assumption of local independence to estimate a mixture model of latent multi-way tables, the number of which (m
) is specified by the user. Estimated parameters include the latent-class-conditional response probabilities for each manifest variable and the class conditional mixing proportions
denoting population share of observations corresponding to each latent multi-way table per class.
Posterior class probabilities can be estimated with the predict
method.
A list of class cclcda2
containing the following components:
call |
The (matched) function call. |
lca.theta |
The estimated class conditional response probabilities of the LCA given as a list of matrices like |
lca.w |
The estimated mixing proportions of the LCA. |
lca.wmk |
The estimated class conditional mixing proportions of the LCA. |
prior |
Prior probabilites. |
m |
Number of latent subclasses. |
r |
Number of different responses per variable. |
k |
Number of classes. |
d |
Number of variables. |
aic |
Value of the AIC for each class conditional Latent Class Model. |
bic |
Value of the BIC for each class conditional Latent Class Model. |
Gsq |
The likelihood ratio/deviance statistic for each class conditional model. |
Chisq |
The Pearson Chi-square goodness of fit statistic for fitted vs. observed multiway tables for each class conditional model. |
entropy |
Value of the weighted entropy as described below. |
gini |
Value of the weighted Gini coefficient as described below. |
chi.stat |
Value of the Chi-square test statistik of the test of latent class membership and class membership as described below. |
chi.p |
P Value of the Chi-square of the test of latent class membership and class membership as described below. |
If the number of latent classes per class is unknown a model selection must be accomplished to determine the value of m
. For this goal there are some model selection criteria implemented. The AIC, BIC, likelihood ratio statistic and the Chi-square goodness of fit statistic are taken from the poLCA-function (see poLCA
).
Additionally cclcda2
provides quality criteria which should give insight into the model's classification potential. These criteria are similar to the splitting criteria of classification trees. The impurity measures are
– Weighted entropy: The weighted entropy is given by
– Weighted Gini coefficient: The weighted Gini coefficient is given by
– Pearson's Chi-square test: A Pearson's Chi-square test is performed to test the independence of latent class membership and class membership.
Michael B\"ucker
predict.cclcda2
, lcda
, predict.lcda
, cclcda
, predict.cclcda
, poLCA
# response probabilites probs1 <- list() probs1[[1]] <- matrix(c(0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1, 0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7), nrow=4, byrow=TRUE) probs1[[2]] <- matrix(c(0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1, 0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1), nrow=4, byrow=TRUE) probs1[[3]] <- matrix(c(0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7, 0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1), nrow=4, byrow=TRUE) probs1[[4]] <- matrix(c(0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1, 0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1), nrow=4, byrow=TRUE) prior <- c(0.5,0.5) wmk <- matrix(c(0.45,0.45,0.05,0.05,0.05,0.05,0.45,0.45), ncol=4, nrow=2, byrow=TRUE) wkm <- apply(wmk*prior, 2, function(x) x/sum(x)) # generation of training data data_temp <- poLCA.simdata(N = 1000, probs = probs1, nclass = 2, ndv = 4, nresp = 4, P=rep(0.25,4)) data <- data_temp$dat lclass <- data_temp$trueclass grouping <- numeric() for (i in 1:length(lclass)) { grouping[i] <- sample(c(1,2),1, prob=wkm[,lclass[i]]) } # generation of test data data_temp <- poLCA.simdata(N = 500, probs = probs1, nclass = 2, ndv = 4, nresp = 4, P=rep(0.25,4)) data.test <- data_temp$dat lclass <- data_temp$trueclass grouping.test <- numeric() for (i in 1:length(lclass)) { grouping.test[i] <- sample(c(1,2),1, prob=wkm[,lclass[i]]) } # cclcda-procedure object <- cclcda2(data, grouping, m=4) object
# response probabilites probs1 <- list() probs1[[1]] <- matrix(c(0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1, 0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7), nrow=4, byrow=TRUE) probs1[[2]] <- matrix(c(0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1, 0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1), nrow=4, byrow=TRUE) probs1[[3]] <- matrix(c(0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7, 0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1), nrow=4, byrow=TRUE) probs1[[4]] <- matrix(c(0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1, 0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1), nrow=4, byrow=TRUE) prior <- c(0.5,0.5) wmk <- matrix(c(0.45,0.45,0.05,0.05,0.05,0.05,0.45,0.45), ncol=4, nrow=2, byrow=TRUE) wkm <- apply(wmk*prior, 2, function(x) x/sum(x)) # generation of training data data_temp <- poLCA.simdata(N = 1000, probs = probs1, nclass = 2, ndv = 4, nresp = 4, P=rep(0.25,4)) data <- data_temp$dat lclass <- data_temp$trueclass grouping <- numeric() for (i in 1:length(lclass)) { grouping[i] <- sample(c(1,2),1, prob=wkm[,lclass[i]]) } # generation of test data data_temp <- poLCA.simdata(N = 500, probs = probs1, nclass = 2, ndv = 4, nresp = 4, P=rep(0.25,4)) data.test <- data_temp$dat lclass <- data_temp$trueclass grouping.test <- numeric() for (i in 1:length(lclass)) { grouping.test[i] <- sample(c(1,2),1, prob=wkm[,lclass[i]]) } # cclcda-procedure object <- cclcda2(data, grouping, m=4) object
Local Discrimination via Latent Class Models
lcda(x, ...) ## Default S3 method: lcda(x, grouping=NULL, prior=NULL, probs.start=NULL, nrep=1, m=3, maxiter = 1000, tol = 1e-10, subset, na.rm = FALSE, ...) ## S3 method for class 'formula' lcda(formula, data, ...)
lcda(x, ...) ## Default S3 method: lcda(x, grouping=NULL, prior=NULL, probs.start=NULL, nrep=1, m=3, maxiter = 1000, tol = 1e-10, subset, na.rm = FALSE, ...) ## S3 method for class 'formula' lcda(formula, data, ...)
x |
Matrix or data frame containing the explanatory variables. Manifest variables must contain only integer values, and must be coded with consecutive values from 1 to the maximum number of outcomes for each variable. All missing values should be entered as NA. |
grouping |
A factor specifying the class for each observation; if not specified, the first column of |
formula |
Formula of the form |
data |
Data frame from which variables specified in formula are to be taken. |
prior |
The prior probabilities of class membership. If unspecified, the class proportions for the training set are used. If present, the probabilities should be specified in the order of the factor levels. |
probs.start |
A list (per class) of lists of matrices (per variable) of response probabilities |
nrep |
Number of times to estimate the model, using different random values of |
m |
The number of subclasses per class. Can be either a vector containing the number of subclasses per class or a number of subclasses for all classes. Default is |
maxiter |
The maximum number of iterations through which the estimation algorithm will cycle. |
tol |
A tolerance value for judging when convergence has been reached. When the one-iteration change in the estimated log-likelihood is less than |
subset |
An index vector specifying the cases to be used in the training sample. |
na.rm |
Logical, for how |
... |
Further arguments to be passed to |
The lcda
-function performs a Latent Class Discriminant Analysis (LCDA). A Latent Class Modell will be estimated for each class by the poLCA
-function (see poLCA
).
The class conditional model is given by
where is the class index,
is the latent subclass index,
is the variable index and
is the observation index. The variable
is
if the variable
of this observation is
and in class
. The parameter
is the class conditional mixture weight and
is the probability for outcome
of variable
in subclass
of class
.
These Latent Class Models use the assumption of local independence to estimate a mixture model of latent multi-way tables. The mixture models are estimated by the EM-algorithm. The number of mixture components (m
) is specified by the user. Estimated parameters include the latent-class conditional response probabilities for each manifest variable and the class conditional mixing proportions
denoting the population share of observations corresponding to each latent multi-way table.
Posterior class probabilities and class memberships can be estimated with the predict
method.
A list of class lcda
containing the following components:
call |
The (matched) function call. |
lca.theta |
The estimated class conditional response probabilities of the LCA given as a list of matrices like |
lca.w |
The estimated mixing proportions of the LCA. |
prior |
Prior probabilites. |
m |
Number of latent subclasses per class. |
r |
Number of possible responses per variable. |
k |
Number of classes. |
d |
Number of variables. |
aic |
Value of the AIC for each class conditional Latent Class Model. |
bic |
Value of the BIC for each class conditional Latent Class Model. |
Gsq |
The likelihood ratio/deviance statistic for each class conditional model. |
Chisq |
The Pearson Chi-square goodness of fit statistic for fitted vs. observed multiway tables for each class conditional model. |
If the number of latent classes per class is unknown a model selection must be accomplished to determine the value of m
. For this goal there are some model selection criteria implemented. The AIC, BIC, likelihood ratio statistic and the Chi-square goodness of fit statistic are taken from the poLCA-function (see poLCA
). For each class these criteria can be regarded separately and for each class the number of latent classes can be determined.
Michael B\"ucker
predict.lcda
, cclcda
, predict.cclcda
, cclcda2
, predict.cclcda2
, poLCA
# response probabilites for class 1 probs1 <- list() probs1[[1]] <- matrix(c(0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1), nrow=2, byrow=TRUE) probs1[[2]] <- matrix(c(0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1), nrow=2, byrow=TRUE) probs1[[3]] <- matrix(c(0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7), nrow=2, byrow=TRUE) probs1[[4]] <- matrix(c(0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1), nrow=2, byrow=TRUE) # response probabilites for class 2 probs2 <- list() probs2[[1]] <- matrix(c(0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7), nrow=2, byrow=TRUE) probs2[[2]] <- matrix(c(0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1), nrow=2, byrow=TRUE) probs2[[3]] <- matrix(c(0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1), nrow=2, byrow=TRUE) probs2[[4]] <- matrix(c(0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1), nrow=2, byrow=TRUE) # generation of data simdata1 <- poLCA.simdata(N = 500, probs = probs1, nclass = 2, ndv = 4, nresp = 4, missval = FALSE) simdata2 <- poLCA.simdata(N = 500, probs = probs2, nclass = 2, ndv = 4, nresp = 4, missval = FALSE) data1 <- simdata1$dat data2 <- simdata2$dat data <- cbind(rbind(data1, data2), rep(c(1,2), each=500)) names(data)[5] <- "grouping" data <- data[sample(1:1000),] grouping <- data[[5]] data <- data[,1:4] # lcda-procedure object <- lcda(data, grouping=grouping, m=2) object
# response probabilites for class 1 probs1 <- list() probs1[[1]] <- matrix(c(0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1), nrow=2, byrow=TRUE) probs1[[2]] <- matrix(c(0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1), nrow=2, byrow=TRUE) probs1[[3]] <- matrix(c(0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7), nrow=2, byrow=TRUE) probs1[[4]] <- matrix(c(0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1), nrow=2, byrow=TRUE) # response probabilites for class 2 probs2 <- list() probs2[[1]] <- matrix(c(0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7), nrow=2, byrow=TRUE) probs2[[2]] <- matrix(c(0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1), nrow=2, byrow=TRUE) probs2[[3]] <- matrix(c(0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1), nrow=2, byrow=TRUE) probs2[[4]] <- matrix(c(0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1), nrow=2, byrow=TRUE) # generation of data simdata1 <- poLCA.simdata(N = 500, probs = probs1, nclass = 2, ndv = 4, nresp = 4, missval = FALSE) simdata2 <- poLCA.simdata(N = 500, probs = probs2, nclass = 2, ndv = 4, nresp = 4, missval = FALSE) data1 <- simdata1$dat data2 <- simdata2$dat data <- cbind(rbind(data1, data2), rep(c(1,2), each=500)) names(data)[5] <- "grouping" data <- data[sample(1:1000),] grouping <- data[[5]] data <- data[,1:4] # lcda-procedure object <- lcda(data, grouping=grouping, m=2) object
Classifies new observations using parameters determined by
the cclcda
-function.
## S3 method for class 'cclcda' predict(object, newdata, ...)
## S3 method for class 'cclcda' predict(object, newdata, ...)
object |
Object of class |
newdata |
Data frame of cases to be classified. |
... |
Further arguments are ignored. |
Posterior probabilities for new observations using parameters determined by
the cclcda
-function are computed. The classification of the new data is done by the Bayes decision function.
A list with components:
class |
Vector (of class |
posterior |
Posterior probabilities for the classes.
For details of computation see |
Michael B\"ucker
cclcda
, lcda
, predict.lcda
, cclcda2
, predict.cclcda2
, poLCA
# response probabilites probs1 <- list() probs1[[1]] <- matrix(c(0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1, 0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7), nrow=4, byrow=TRUE) probs1[[2]] <- matrix(c(0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1, 0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1), nrow=4, byrow=TRUE) probs1[[3]] <- matrix(c(0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7, 0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1), nrow=4, byrow=TRUE) probs1[[4]] <- matrix(c(0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1, 0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1), nrow=4, byrow=TRUE) prior <- c(0.5,0.5) wmk <- matrix(c(0.45,0.45,0.05,0.05,0.05,0.05,0.45,0.45), ncol=4, nrow=2, byrow=TRUE) wkm <- apply(wmk*prior, 2, function(x) x/sum(x)) # generation of training data data_temp <- poLCA.simdata(N = 1000, probs = probs1, nclass = 2, ndv = 4, nresp = 4, P=rep(0.25,4)) data <- data_temp$dat lclass <- data_temp$trueclass grouping <- numeric() for (i in 1:length(lclass)) { grouping[i] <- sample(c(1,2),1, prob=wkm[,lclass[i]]) } # generation of test data data_temp <- poLCA.simdata(N = 500, probs = probs1, nclass = 2, ndv = 4, nresp = 4, P=rep(0.25,4)) data.test <- data_temp$dat lclass <- data_temp$trueclass grouping.test <- numeric() for (i in 1:length(lclass)) { grouping.test[i] <- sample(c(1,2),1, prob=wkm[,lclass[i]]) } # cclcda-procedure object <- cclcda(data, grouping, m=4) pred <- predict(object, data.test)$class 1-(sum(pred==grouping.test)/500)
# response probabilites probs1 <- list() probs1[[1]] <- matrix(c(0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1, 0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7), nrow=4, byrow=TRUE) probs1[[2]] <- matrix(c(0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1, 0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1), nrow=4, byrow=TRUE) probs1[[3]] <- matrix(c(0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7, 0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1), nrow=4, byrow=TRUE) probs1[[4]] <- matrix(c(0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1, 0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1), nrow=4, byrow=TRUE) prior <- c(0.5,0.5) wmk <- matrix(c(0.45,0.45,0.05,0.05,0.05,0.05,0.45,0.45), ncol=4, nrow=2, byrow=TRUE) wkm <- apply(wmk*prior, 2, function(x) x/sum(x)) # generation of training data data_temp <- poLCA.simdata(N = 1000, probs = probs1, nclass = 2, ndv = 4, nresp = 4, P=rep(0.25,4)) data <- data_temp$dat lclass <- data_temp$trueclass grouping <- numeric() for (i in 1:length(lclass)) { grouping[i] <- sample(c(1,2),1, prob=wkm[,lclass[i]]) } # generation of test data data_temp <- poLCA.simdata(N = 500, probs = probs1, nclass = 2, ndv = 4, nresp = 4, P=rep(0.25,4)) data.test <- data_temp$dat lclass <- data_temp$trueclass grouping.test <- numeric() for (i in 1:length(lclass)) { grouping.test[i] <- sample(c(1,2),1, prob=wkm[,lclass[i]]) } # cclcda-procedure object <- cclcda(data, grouping, m=4) pred <- predict(object, data.test)$class 1-(sum(pred==grouping.test)/500)
Classifies new observations using parameters determined by
the cclcda2
-function.
## S3 method for class 'cclcda2' predict(object, newdata, ...)
## S3 method for class 'cclcda2' predict(object, newdata, ...)
object |
Object of class |
newdata |
Data frame of cases to be classified. |
... |
Further arguments are ignored. |
Posterior probabilities for new observations using parameters determined by
the cclcda2
-function are computed. The classification of the new data is done by the Bayes decision function.
A list with components:
class |
Vector (of class |
posterior |
Posterior probabilities for the classes.
For details of computation see |
Michael B\"ucker
cclcda2
, lcda
, predict.lcda
, cclcda
, predict.cclcda
, poLCA
# response probabilites probs1 <- list() probs1[[1]] <- matrix(c(0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1, 0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7), nrow=4, byrow=TRUE) probs1[[2]] <- matrix(c(0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1, 0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1), nrow=4, byrow=TRUE) probs1[[3]] <- matrix(c(0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7, 0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1), nrow=4, byrow=TRUE) probs1[[4]] <- matrix(c(0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1, 0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1), nrow=4, byrow=TRUE) prior <- c(0.5,0.5) wmk <- matrix(c(0.45,0.45,0.05,0.05,0.05,0.05,0.45,0.45), ncol=4, nrow=2, byrow=TRUE) wkm <- apply(wmk*prior, 2, function(x) x/sum(x)) # generation of training data data_temp <- poLCA.simdata(N = 1000, probs = probs1, nclass = 2, ndv = 4, nresp = 4, P=rep(0.25,4)) data <- data_temp$dat lclass <- data_temp$trueclass grouping <- numeric() for (i in 1:length(lclass)) { grouping[i] <- sample(c(1,2),1, prob=wkm[,lclass[i]]) } # generation of test data data_temp <- poLCA.simdata(N = 500, probs = probs1, nclass = 2, ndv = 4, nresp = 4, P=rep(0.25,4)) data.test <- data_temp$dat lclass <- data_temp$trueclass grouping.test <- numeric() for (i in 1:length(lclass)) { grouping.test[i] <- sample(c(1,2),1, prob=wkm[,lclass[i]]) } # cclcda2-procedure object <- cclcda2(data, grouping, m=4) pred <- predict(object, data.test)$class 1-(sum(pred==grouping.test)/500)
# response probabilites probs1 <- list() probs1[[1]] <- matrix(c(0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1, 0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7), nrow=4, byrow=TRUE) probs1[[2]] <- matrix(c(0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1, 0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1), nrow=4, byrow=TRUE) probs1[[3]] <- matrix(c(0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7, 0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1), nrow=4, byrow=TRUE) probs1[[4]] <- matrix(c(0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1, 0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1), nrow=4, byrow=TRUE) prior <- c(0.5,0.5) wmk <- matrix(c(0.45,0.45,0.05,0.05,0.05,0.05,0.45,0.45), ncol=4, nrow=2, byrow=TRUE) wkm <- apply(wmk*prior, 2, function(x) x/sum(x)) # generation of training data data_temp <- poLCA.simdata(N = 1000, probs = probs1, nclass = 2, ndv = 4, nresp = 4, P=rep(0.25,4)) data <- data_temp$dat lclass <- data_temp$trueclass grouping <- numeric() for (i in 1:length(lclass)) { grouping[i] <- sample(c(1,2),1, prob=wkm[,lclass[i]]) } # generation of test data data_temp <- poLCA.simdata(N = 500, probs = probs1, nclass = 2, ndv = 4, nresp = 4, P=rep(0.25,4)) data.test <- data_temp$dat lclass <- data_temp$trueclass grouping.test <- numeric() for (i in 1:length(lclass)) { grouping.test[i] <- sample(c(1,2),1, prob=wkm[,lclass[i]]) } # cclcda2-procedure object <- cclcda2(data, grouping, m=4) pred <- predict(object, data.test)$class 1-(sum(pred==grouping.test)/500)
Classifies new observations using the parameters determined by
the lcda
-function.
## S3 method for class 'lcda' predict(object, newdata, ...)
## S3 method for class 'lcda' predict(object, newdata, ...)
object |
Object of class |
newdata |
Data frame of cases to be classified. |
... |
Further arguments are ignored. |
Posterior probabilities for new observations using parameters determined by
the lcda
-function are computed. The classification of the new data is done by the Bayes decision function.
A list with components:
class |
Vector (of class |
posterior |
Posterior probabilities for the classes.
For details of computation see |
Michael B\"ucker
lcda
, cclcda
, predict.cclcda
, cclcda2
, predict.cclcda2
, poLCA
# response probabilites for class 1 probs1 <- list() probs1[[1]] <- matrix(c(0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1), nrow=2, byrow=TRUE) probs1[[2]] <- matrix(c(0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1), nrow=2, byrow=TRUE) probs1[[3]] <- matrix(c(0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7), nrow=2, byrow=TRUE) probs1[[4]] <- matrix(c(0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1), nrow=2, byrow=TRUE) # response probabilites for class 2 probs2 <- list() probs2[[1]] <- matrix(c(0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7), nrow=2, byrow=TRUE) probs2[[2]] <- matrix(c(0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1), nrow=2, byrow=TRUE) probs2[[3]] <- matrix(c(0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1), nrow=2, byrow=TRUE) probs2[[4]] <- matrix(c(0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1), nrow=2, byrow=TRUE) # generation of data simdata1 <- poLCA.simdata(N = 500, probs = probs1, nclass = 2, ndv = 4, nresp = 4, missval = FALSE) simdata2 <- poLCA.simdata(N = 500, probs = probs2, nclass = 2, ndv = 4, nresp = 4, missval = FALSE) data1 <- simdata1$dat data2 <- simdata2$dat data <- cbind(rbind(data1, data2), rep(c(1,2), each=500)) names(data)[5] <- "grouping" data <- data[sample(1:1000),] grouping <- data[[5]] data <- data[,1:4] # lcda-procedure object <- lcda(data, grouping=grouping, m=2) pred.class <- predict(object, newdata=data)$class sum(pred.class==grouping)/length(pred.class)
# response probabilites for class 1 probs1 <- list() probs1[[1]] <- matrix(c(0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1), nrow=2, byrow=TRUE) probs1[[2]] <- matrix(c(0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1), nrow=2, byrow=TRUE) probs1[[3]] <- matrix(c(0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7), nrow=2, byrow=TRUE) probs1[[4]] <- matrix(c(0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1), nrow=2, byrow=TRUE) # response probabilites for class 2 probs2 <- list() probs2[[1]] <- matrix(c(0.1,0.1,0.7,0.1,0.1,0.1,0.1,0.7), nrow=2, byrow=TRUE) probs2[[2]] <- matrix(c(0.1,0.1,0.1,0.7,0.7,0.1,0.1,0.1), nrow=2, byrow=TRUE) probs2[[3]] <- matrix(c(0.7,0.1,0.1,0.1,0.1,0.7,0.1,0.1), nrow=2, byrow=TRUE) probs2[[4]] <- matrix(c(0.1,0.7,0.1,0.1,0.1,0.1,0.7,0.1), nrow=2, byrow=TRUE) # generation of data simdata1 <- poLCA.simdata(N = 500, probs = probs1, nclass = 2, ndv = 4, nresp = 4, missval = FALSE) simdata2 <- poLCA.simdata(N = 500, probs = probs2, nclass = 2, ndv = 4, nresp = 4, missval = FALSE) data1 <- simdata1$dat data2 <- simdata2$dat data <- cbind(rbind(data1, data2), rep(c(1,2), each=500)) names(data)[5] <- "grouping" data <- data[sample(1:1000),] grouping <- data[[5]] data <- data[,1:4] # lcda-procedure object <- lcda(data, grouping=grouping, m=2) pred.class <- predict(object, newdata=data)$class sum(pred.class==grouping)/length(pred.class)