R/bootmds.stops.R

Defines functions bootmds.stops

#' MDS Bootstrap for stops objects
#'
#' Performs a bootstrap on an MDS solution. It works for derived dissimilarities only, i.e. generated by the call dist(data). The original data matrix needs to be provided, as well as the type of dissimilarity measure used to compute the input dissimilarities (note we cannot as of yet have any dissimilarity matrix).
#'
#' @param object  Object of class stops or pcops.
#' @param data Initial data (before dissimilarity computation).
#' @param method.dat Dissimilarity computation used as MDS input. This must be one of "pearson", "spearman", "kendall", "euclidean", "maximum", "manhattan", "canberra", "binary".
#' @param nrep Number of bootstrap replications.
#' @param alpha Alpha level for condfidence ellipsoids.
#' @param verbose If 'TRUE', bootstrap index is printed out.
#' @param  ...  Additional arguments needed for dissimilarity computation as specified in \code{\link[smacof]{sim2diss}}.
#'
#' @details In order to examine the stability solution of an MDS, a bootstrap on the raw data can be performed. This results in confidence ellipses in the configuration plot. The ellipses are returned as list which allows users to produce (and further customize) the plot by hand. See \code{\link[smacof]{bootmds}} for more. 
#'
#' @return An object of class 'smacofboot', see \code{\link[smacof]{bootmds}}. With values 
#' \itemize{
#' \item cov: Covariances for ellipse computation
#' \item bootconf: Configurations bootstrap samples
#' \item stressvec: Bootstrap stress values
#' \item bootci: Stress bootstrap percentile confidence interval
#' \item spp: Stress per point (based on stress.en) 
#' \item stab: Stability coefficient
#' }
#'
#'
#' @importFrom smacof bootmds
#' @examples
#' dats <- na.omit(PVQ40[,1:5])
#' diss <- dist(t(dats))   ## Euclidean distances 
#' fit <- stops(diss,loss="rstress",itmax=5,lower=0.2,upper=3)       
#' set.seed(123)
#' resboot <- bootmds(fit, dats, method.dat = "euclidean", nrep = 2)
#' resboot
#' @export
bootmds.stops<- function(object, data, method.dat = "pearson", nrep = 100, alpha = 0.05, 
                            verbose = FALSE, ...) 
{   
    calli <- match.call()
    ocall <- object$fit$call
    ocall$type <- object$fit$type
    ocall$weightmat <- object$fit$weightmat
    ocall$init <- object$fit$init
    ocall$ndim <- object$fit$ndim
    if(!is.numeric(ocall$itmax)) ocall$itmax <- object$fit$niter+1000 else ocall$itmax <- object$fit$call$itmax
    object$fit$call <- ocall
    #if(class(object$fit)[1]=="smacofB") result <- smacof::jackmds(object$fit,eps=eps,itmax=itmax,verbose=verbose)
    #if(class(object$fit)[1]=="smacofP")
    out <- smacof::bootmds(object$fit,data=data,method.dat=method.dat,nrep=nrep,alpha=alpha,verbose=verbose,...)
    out$call <- calli
    out
}

Try the stops package in your browser

Any scripts or data that you put into this service are public.

stops documentation built on Dec. 12, 2023, 3:02 a.m.