Description Usage Arguments Value Examples
View source: R/func_predict2.r
Takes predictions from model object(s) and and combines it with actual values This function takes a vector of strings that represent the model object names
1 2  | 
model | 
 A vector of containing strings of the model object names  | 
newdata | 
 A dataframe with input variables that predict2() will feed into the model  | 
actual | 
 Vector of expected (or 'actual') data from the test dataset. Will be merged to the predicted data for easy export and subsequent comparison  | 
pred_type | 
 The type of predicted value predict will return: regression will return values; classification options: response prob, vote. Default is 'response' [see predict.randomForest for more information]  | 
append_cols | 
 Append additional columns to the predictions .csv.  | 
write_model | 
 Logical. Whether to write the model fit objects to disk (as .data; one for each model). Default = FALSE  | 
write_pred | 
 Logical. Whether to write the predictions to disk (as a .csv). Default = FALSE  | 
csv_name | 
 String add to the fileneames of the data and prediction files (Default value = 'model'; model.data; model.csv)  | 
dir | 
 Path location where the .csv and .data files will be written. Default is current working directory: getwd()  | 
dir_data | 
 Specify location for data files if you want the data files to be in a separate file. Default is current working directory: getwd()  | 
dir_csv | 
 Specify location for csv files if you want the data files to be in a separate file. Default is current working directory: getwd() working directory (i.e. getwd())  | 
predict2() will return the results from predict() as a data.frame. each model object in model' will be one column in the dataframe.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19  | library(predict2)
data(lm_data)
df_train = lm_data[1:25, ]
df_test = lm_data[26:50, ]
lm_int = lm(y ~ x, data = df_train)
lm_noint = lm(y ~ 0 + x, data = df_train)
list_lm = c('lm_int', 'lm_noint')
predicted = predict2(
  model = list_lm,
  newdata = df_test,
  actual = df_test$y,
  append_cols = df_test,
  pred_type = 'response',
  write_model = FALSE,
  write_pred = FALSE,
  csv_name = 'none'
)
head(predicted)
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.