https://github.com/cran/IQCC
Raw File
Tip revision: 5c6e6dea621fd5b486441c5e649098ad5a6549e6 authored by Flavio Barros on 15 November 2017, 21:16:12 UTC
version 0.7
Tip revision: 5c6e6de
T2.2.R
#' Hotelling T2 Statistic for Phase II.
#' 
#' Calculate the Hotelling T2 statistic for multivariate observations at phase
#' II , to be used to build the corresponding control chart.
#' 
#' Before using this function it is necessary to execute the function
#' "stats"(that calculate the auxiliary statistics involved in the T2 formula)
#' and the function "data.2" (or other way to supply the data).
#' 
#' @param datum2 The data set for the phase II. Shoul be a vector.
#' @param estat The values of the auxiliary statistics. Should be a list with a
#' matrix with the means, mean of the means and mean of the standard deviation.
#' @param n The size of each sample used previously in data.2. If they are
#' individual observations, use n = 1.
#' @return Return a vector with the Hotelling T2 statistics.
#' @export
#' @author Daniela R. Recchia, Emanuel P. Barbosa
#' @seealso \link{T2.1},\link{stats}, \link{data.2}, \link{cchart.T2.2}
#' @references Montgomery, D.C.,(2008)."Introduction to Statistical Quality
#' Control". Chapter 11. Wiley.
#' @examples
#' 
#' mu <- c(5.682, 88.22)
#' Sigma <- symMatrix(c(3.770, -5.495, 13.53), 2)
#' #Example with individual observations
#' datum <- data.1(50, 1, mu, Sigma)
#' estat <- stats(datum, 50, 1, 2)
#' datum2 <- data.2(estat, 1, p = 2)
#' T2II <- T2.2(datum2, estat, 1)
#' #Example with subgroup observations
#' datum <- data.1(20, 10, mu, Sigma)
#' estat <- stats(datum, 20, 10, 2)
#' datum2 <- data.2(estat, 10, p = 2)
#' T2II <- T2.2(datum2, estat, 10)
#' 
T2.2 <- function(datum2, estat, n)
{
    if(n == 1)
    {
        T2 <- (t(datum2 - estat[[1]]) %*% solve(estat[[2]]) %*% (datum2 - estat[[1]]))
    }
    if(n > 1)
    {
        media <- colMeans(datum2)
        T2 <- n * (t(media - estat[[1]]) %*% solve(estat[[2]]) %*% (media - estat[[1]]))
    }
    return(T2)
}
back to top