#' Confusion Matrix
#'
#' @description
#' Create a confusion matrix ........
#'
#' @usage
#' coMa(x, file, header)
#'
#' @param x is a confusion matrix.
#' @param file is a confusion matrix in a file.
#' @param header true if data file have header
#' @param ... Additional parameters.
#'
#' @return An object of class "coMa" is a list containing the following components:
#'
#' @examples
#' x<-matrix(c(35,4,12,2,14,11,9,5,11,3,38,12,1,0,4,2),ncol=4,nrow=4)
#' cm1 <- coMa(x)
#' @export
#'
coMa <- function(x,file=NULL,header=FALSE){
#Pensar si es mejor poner aquĆ la carga desde fichero o en otro lugar
#si se lee desde fichero x contiene el contenido del fichero
#test(x)
if (!is.matrix(x))
stop("x is not a matrix")
if (nrow(x)!=ncol(x))
stop("x is not a square matrix")
if (!is.numeric(x))
stop("x has non-integer numbers")
if (sum(x<0)!=0)
stop("x has negative numbers")
if (sum(x-trunc(x))!=0)
stop("x has non-integer numbers")
ans <- list(data=x)
class(ans)<-"coMa"
return(ans)
}
#' Confusion Matrix
#'
#' @description
#' Test if the argument is a confusion matrix object ........
#'
#' @usage
#' is.coMa(x)
#'
#' @param x is a confusion matrix.
#'
#'
#' @return TRUE if the argument is a confusion matrix object and FALSE in other case.
#'
#'
#' @export
#' @examples
#' x<-matrix(c(35,4,12,2,14,11,9,5,11,3,38,12,1,0,4,2),ncol=4,nrow=4)
#' cm1 <- coMa(x)
#' is.coMa(cm1)
#'
#'
#' @export
is.coMa <- function (x){
inherits(x, "coMa")
}
#' @method print coMa
#' @export
print.coMa <- function (x, ...){
if (!inherits(x, "coMa")){
stop("x not is a coMa object")
}else{
cat("Object class coMa\n")
cat("Confusion Matrix\n")
x$data
}
}
#' @method summary coMa
#' @export
summary.coMa <- function (object, alpha=0.05, ...){
if (!inherits(object, "coMa")){
stop("object not is a coMa object")
}else{
gkappa<-GKappa(object,alpha)
goa<-GOA(object,alpha)
gupis<-GUPIs(object)
genis<-GEnIs(object)
ans<-list(gkappa=gkappa, goa=goa, gupis=gupis, genis=genis)
class(ans)<-"summary.coMa"
return(ans)
}
}
#' @method print summary.coMa
#' @export
print.summary.coMa <- function (x, ...){
if (!inherits(x, "summary.coMa")){
stop("x not is a summary.coMa object")
}else{
#genero todo el codigo de summary
#devuelvo objeto summary.coMa#
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.