Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@

documentation_peek.pdf
documentation_for_developers/
libs/
playgrounds/
utility_scripts/
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# History files
# History and RStudio files
.Rhistory
.Rapp.history
.RData

# RStudio files
.Rproj.user
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf
inst/doc

# README htmls in any folder
README.html

# The devtools zip is downloaded when the package is updating itself. If it's not deleted, there's no reason to commit it to the repository.
devtools.zip
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: IalsaSynthesis
Title: Synthesizing Information Across Collaborating Research
Version: 0.0-1
Date: 2015-04-29
Version: 0.0-3
Date: 2015-04-30
Authors@R: c(person("Will", "Beasley", email="wibeasley@hotmail.com", role=c("aut", "cre")),
person("Andrey", "Koval", email="andkov@uvic.ca", role = c("aut")),
person(given="Integrative Analysis of Longitudinal Studies of Aging (IALSA)", role = c("cph")))
Expand All @@ -16,6 +16,7 @@ Depends:
R(>= 3.0.0),
stats
Imports:
readr,
testit
Suggests:
devtools,
Expand Down
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Generated by roxygen2 (4.1.1): do not edit by hand

export(extract_aic)
export(extract_bic)
export(extract_bic_adjusted)
export(extract_free_parameter_count)
export(extract_loglikelihood)
export(extract_output_filename)
export(extract_scaling_correction)
export(validate_filename_output)
89 changes: 89 additions & 0 deletions R/extract.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#' @name extract
#' @aliases extract_output_filename extract_free_parameter_count extract_loglikelihood extract_scaling_correction extract_aic extract_bic extract_bic_adjusted
#' @export extract_output_filename extract_free_parameter_count extract_loglikelihood extract_scaling_correction extract_aic extract_bic extract_bic_adjusted
#'
#' @title Extract the values within model output files.
#'
#' @description Functions that extract the values within model output files.
#'
#' @param mplus_output Text containing model output.
#'
#' @return A \code{numeric} value corresponding to the desired quantity.
#'
#' @author Will Beasley
#'
#' @examples
#' library(IalsaSynthesis) #Load the package into the current R session.

extract_output_filename <- function( mplus_output ) {
# gsub(pattern="DATA: File = (.+);", replacement="\\1", mplus_output, perl=T)

matches <- regexpr(".+DATA: File = (.+);.*", mplus_output, perl=TRUE);
result <- attr(matches, "capture.start")[,1]
attr(result, "match.length") <- attr(matches, "capture.length")[,1]
observed_snippet <- regmatches(mplus_output, result)

return( observed_snippet )
}

extract_free_parameter_count <- function( mplus_output ) {
matches <- regexpr("Number of Free Parameters\\s+(\\d{1,})\\s+", mplus_output, perl=TRUE);
result <- attr(matches, "capture.start")[,1]
attr(result, "match.length") <- attr(matches, "capture.length")[,1]
matched_string <- regmatches(mplus_output, result)
matched_float <- as.numeric(matched_string)

return( matched_float )
}

extract_loglikelihood <- function( mplus_output ) {
matches <- regexpr("Loglikelihood\\s+H0 Value\\s+([-\\d\\.]+)\\s+", mplus_output, perl=TRUE);
result <- attr(matches, "capture.start")[,1]
attr(result, "match.length") <- attr(matches, "capture.length")[,1]
matched_string <- regmatches(mplus_output, result)
matched_float <- as.numeric(matched_string)

return( matched_float )
}

extract_scaling_correction <- function( mplus_output ) {
matches <- regexpr("\\s+H0 Scaling Correction Factor\\s+([-\\d\\.]+)\\s+for MLR\\s+", mplus_output, perl=TRUE);
result <- attr(matches, "capture.start")[,1]
attr(result, "match.length") <- attr(matches, "capture.length")[,1]
matched_string <- regmatches(mplus_output, result)
matched_float <- ifelse(length(matched_string>0), as.numeric(matched_string), NA_real_)

return( matched_float )
}

extract_aic <- function( mplus_output ) {
matches <- regexpr("Akaike \\(AIC\\)\\s+([-\\d\\.]+)\\s+", mplus_output, perl=TRUE);
result <- attr(matches, "capture.start")[,1]
attr(result, "match.length") <- attr(matches, "capture.length")[,1]
matched_string <- regmatches(mplus_output, result)
matched_float <- as.numeric(matched_string)

return( matched_float )
}

extract_bic <- function( mplus_output ) {
matches <- regexpr("Bayesian \\(BIC\\)\\s+([-\\d\\.]+)\\s+", mplus_output, perl=TRUE);
result <- attr(matches, "capture.start")[,1]
attr(result, "match.length") <- attr(matches, "capture.length")[,1]
matched_string <- regmatches(mplus_output, result)
matched_float <- as.numeric(matched_string)

return( matched_float )
}

extract_bic_adjusted <- function( mplus_output ) {
# matches <- regexpr("\\s+Sample-Size Adjusted BIC\\s+(\\d+(\\.\\d+)?)\\s+", mplus_output, perl=TRUE);
# matches <- regexpr("\\s+Sample-Size Adjusted BIC\\s+(.+)\\s+", mplus_output, perl=TRUE);
matches <- regexpr("\\s+Sample-Size Adjusted BIC\\s+([-\\d\\.]+)\\s+", mplus_output, perl=TRUE);
result <- attr(matches, "capture.start")[,1]
attr(result, "match.length") <- attr(matches, "capture.length")[,1]
matched_string <- regmatches(mplus_output, result)
matched_float <- as.numeric(matched_string)

return( matched_float )
}
Loading