R/f_convenience_fit.R

Defines functions fit

Documented in fit

# psychonetrics parameter extraction:
fit <- function(x){
  
  if (is(x,"psychonetrics_bootstrap")){
    fittable <- x@fitmeasures[,c("measure","min","q2.5","q97.5","max")]
    for (j in 2:ncol(fittable)){
      fittable[[j]] <- goodNum2(fittable[[j]])
    }
    
    print.data.frame(fittable,row.names=FALSE)
    invisible(x@fitmeasures)
  } else {
    
    # Bootstrap warning:
    if (x@sample@bootstrap){
      boot_warning()
    }
    
    
    if (!x@computed){
      stop("Model has not yet been computed. Use 'runmodel'.")
    }
    if (is.null(x@fitmeasures)){
      stop("No fit measures computed yet. Use 'addfit'.")
    }
    
    # AWESOME HEADER!!!
    # cat(
    #   paste0("\t################################\n",
    #          "\t## psychonetrics fit measures ##\n",
    #          "\t################################\n\n"))
    # psychonetrics_print_logo() 
    # No awesome header :(
    
    df <- data.frame(
      Measure = names(x@fitmeasures),
      Value = goodNum2(unlist(x@fitmeasures))
    )
    print.data.frame(df,row.names=FALSE)
    
    # Numeric DF to return:
    
    dfnum <- data.frame(
      Measure = names(x@fitmeasures),
      Value = unlist(x@fitmeasures)
    )
    invisible(dfnum)
  }
}

Try the psychonetrics package in your browser

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

psychonetrics documentation built on June 22, 2024, 10:29 a.m.