nbc4vaIO: Run nbc4va using file input and output

Description Usage Arguments Details Value See Also Examples

View source: R/nbc4va_utility.R

Description

Runs nbc and uses summary.nbc on input data files or dataframes to output result files or dataframes with data on predictions, probabilities, causes, and performance metrics in an easily accessible way.

Usage

1
2
3
4
5
6
7
nbc4vaIO(trainFile, testFile, known = TRUE, csmfaFile = NULL,
  saveFiles = TRUE, outDir = dirname(testFile),
  fileHeader = strsplit(basename(testFile), "\\.")[[1]][[1]],
  fileReader = read.csv, fileReaderIn = "file",
  fileReaderArgs = list(as.is = TRUE, stringsAsFactors = FALSE),
  fileWriter = write.csv, fileWriterIn = "x", fileWriterOut = "file",
  fileWriterArgs = list(row.names = FALSE), outExt = "csv")

Arguments

trainFile

A character value of the path to the data to be used as the train argument for nbc or a dataframe of the train argument.

testFile

A character value of the path to the data to be used as the test argument for nbc or a dataframe of the test argument.

known

TRUE to indicate that the test causes are available in the 2nd column and FALSE to indicate that they are not known

csmfaFile

A character value of the path to the data to be used as the csmfa.obs argument for summary.nbc or a named vector of the csmfa.obs argument.

  • If (csmfaFile is char): the file must have only 1 column of the causes per case

saveFiles

Set to TRUE to save the return object as files or FALSE to return the actual object

outDir

A character value of the path to the directory to store the output results files.

fileHeader

A character value of the file header name to use for the output results files.

  • The default is to use the name of the testFile

fileReader

A function that is able to read the trainFile and the testFile.

  • The default is set to read csv files using read.csv

fileReaderIn

A character value of the fileReader argument name that accepts a file path for reading as an input.

fileReaderArgs

A list of the fileReader arguments to be called with do.call.

fileWriter

A function that is able to write data.frame objects to a file location.

  • The default is set to write csv files using write.csv

fileWriterIn

A character value of the fileWriter argument name that accepts a dataframe for writing.

fileWriterOut

A character value of the fileWriter argument name that accepts a file path for writing as an output.

fileWriterArgs

A list of arguments of the fileWriter arguments to be called with do.call.

outExt

A character value of the extension (without the period) to use for the result files.

  • The default is set to use the "csv" extension

  • The default is the directory of the testFile

Details

See Methods documentation for details on the methodology and implementation of the Naive Bayes Classifier algorithm. This function may also act as a wrapper for the main nbc4va package functions.

Value

out Vector or list of respective paths or data from the naive bayes classifier:

See Also

Other utility functions: nbc4vaGUI

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
library(nbc4va)
data(nbc4vaData)

# Split data into train and test sets
train <- nbc4vaData[1:50, ]
test <- nbc4vaData[51:100, ]

# Save train and test data as csv in temp location
trainFile <- tempfile(fileext=".csv")
testFile <- tempfile(fileext=".csv")
write.csv(train, trainFile, row.names=FALSE)
write.csv(test, testFile, row.names=FALSE)

# Use nbc4vaIO via file input and output
# Set "known" to indicate whether test causes are known
outFiles <- nbc4vaIO(trainFile, testFile, known=TRUE)

# Use nbc4vaIO as a wrapper
out <- nbc4vaIO(train, test, known=TRUE, saveFiles=FALSE)

nbc4va documentation built on May 2, 2019, 1:42 p.m.