
# Estimate a logistic regression model
infert1 <- infert
infert1$isCase <- (infert1$case == 1)
myModelInfo <- rxLogisticRegression(formula = isCase ~ age + parity + education + spontaneous + induced,
                       data = infert1)
                       
# Create an xdf file with per-instance results using rxPredict
xdfOut <- tempfile(pattern = "scoreOut", fileext = ".xdf")
scoreDS <- rxPredict(myModelInfo, data = infert1,
    outData = xdfOut, overwrite = TRUE,
    extraVarsToWrite = c("isCase", "Probability"))
   
# Summarize results with an ROC curve
rxRocCurve(actualVarName = "isCase", predVarNames = "Probability", data = scoreDS)

# Use the built-in data set 'airquality' to create test and train data
DF <- airquality[!is.na(airquality$Ozone), ]	
DF$Ozone <- as.numeric(DF$Ozone)
set.seed(12)
randomSplit <- rnorm(nrow(DF))
trainAir <- DF[randomSplit >= 0,]
testAir <- DF[randomSplit < 0,]
airFormula <- Ozone ~ Solar.R + Wind + Temp

# Regression Fast Tree for train data
fastTreeReg <- rxFastTrees(airFormula, type = "regression", 
    data = trainAir)  
    
# Put score and model variables in data frame, including the model variables
# Add the suffix "Pred" to the new variable
fastTreeScoreDF <- rxPredict(fastTreeReg, data = testAir, 
    writeModelVars = TRUE, suffix = "Pred")

rxGetVarInfo(fastTreeScoreDF)

# Clean-up
file.remove(xdfOut)
