Okay, I did ctrl+shift+f10 and added 100 rows of each data set per datapasta, it's kind of hard to look at. let me know if you need something different.
Thanks for the help.
#Author: Sal Meza
#Created: 1/20/19
#Last edited: 1/29/19
#Competion1
ToTrain=read.csv(file = "train.csv", header = TRUE, sep = ",")
#> Warning in file(file, "rt"): cannot open file 'train.csv': No such file or
#> directory
#> Error in file(file, "rt"): cannot open the connection
#ToTrain$Fentanyl = as.factor(ToTrain$Fentanyl)
#train <- train[train$Home_Zip!="Homeless", ]
#train <- train[train$Home_Zip!="Unknown", ]
#train <- train[train$Education!="NA", ]
ToTest=read.csv(file = "test.csv", header = TRUE, sep = ",")
#> Warning in file(file, "rt"): cannot open file 'test.csv': No such file or
#> directory
#> Error in file(file, "rt"): cannot open the connection
#test <- test[test$Home_Zip!="Homeless", ]
#test <- test[test$Home_Zip!="Unknown", ]
#test <- test[test$Education!="NA", ]
pastaTrain <- tibble::tribble(
~Sex, ~Race, ~Age, ~Morphine, ~Codeine, ~Fentanyl, ~Oxycodone, ~Hydrocodone, ~Oxymorphone, ~Hydromorphone, ~Dihydrocodeine, ~Buprenorphine, ~Norbuprenorphine, ~Cotinine, ~id,
1, 1, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 851,
1, 1, 25, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1271,
0, 1, 48, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 448,
1, 1, 55, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 423,
0, 1, 29, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1032,
1, 1, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1502,
1, 4, 24, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1557,
1, 2, 65, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 681,
1, 1, 55, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 981,
1, 1, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1353,
1, 2, 24, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1241,
1, 2, 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1391,
0, 1, 48, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 473,
1, 1, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 859,
1, 1, 44, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 920,
1, 4, 41, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1073,
0, 2, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 513,
0, 1, 46, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 369,
0, 2, 64, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 836
)
pastaTest <- tibble::tribble(
~Sex, ~Race, ~Age, ~Morphine, ~Codeine, ~Oxycodone, ~Hydrocodone, ~Oxymorphone, ~Hydromorphone, ~Dihydrocodeine, ~Buprenorphine, ~Norbuprenorphine, ~Cotinine, ~id,
1, 1, 23, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1066,
1, 1, 48, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 913,
1, 1, 53, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 53,
0, 1, 47, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 94,
1, 2, 42, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1154,
0, 1, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 528,
1, 1, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 137,
1, 1, 38, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 808,
0, 1, 43, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1310,
1, 1, 32, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 995,
0, 1, 39, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 477,
1, 2, 19, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1137,
0, 1, 35, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 543,
1, 2, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2,
0, 1, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1362,
0, 1, 38, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 665,
0, 1, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 556,
1, 1, 28, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 177,
0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1472
)
install.packages("AUC")
#> Installing package into 'C:/Users/userOne/Documents/R/win-library/3.5'
#> (as 'lib' is unspecified)
#> package 'AUC' successfully unpacked and MD5 sums checked
#>
#> The downloaded binary packages are in
#> C:\Users\userOne\AppData\Local\Temp\Rtmpsj0xqi\downloaded_packages
install.packages("caret")
#> Installing package into 'C:/Users/userOne/Documents/R/win-library/3.5'
#> (as 'lib' is unspecified)
#> package 'caret' successfully unpacked and MD5 sums checked
#> Warning: cannot remove prior installation of package 'caret'
#>
#> The downloaded binary packages are in
#> C:\Users\userOne\AppData\Local\Temp\Rtmpsj0xqi\downloaded_packages
install.packages("e1071")
#> Installing package into 'C:/Users/userOne/Documents/R/win-library/3.5'
#> (as 'lib' is unspecified)
#> package 'e1071' successfully unpacked and MD5 sums checked
#> Warning: cannot remove prior installation of package 'e1071'
#>
#> The downloaded binary packages are in
#> C:\Users\userOne\AppData\Local\Temp\Rtmpsj0xqi\downloaded_packages
install.packages("datapasta")
#> Installing package into 'C:/Users/userOne/Documents/R/win-library/3.5'
#> (as 'lib' is unspecified)
#> package 'datapasta' successfully unpacked and MD5 sums checked
#>
#> The downloaded binary packages are in
#> C:\Users\userOne\AppData\Local\Temp\Rtmpsj0xqi\downloaded_packages
install.packages("reprex")
#> Installing package into 'C:/Users/userOne/Documents/R/win-library/3.5'
#> (as 'lib' is unspecified)
#> package 'reprex' successfully unpacked and MD5 sums checked
#>
#> The downloaded binary packages are in
#> C:\Users\userOne\AppData\Local\Temp\Rtmpsj0xqi\downloaded_packages
library(datapasta)
library(AUC)
#> AUC 0.3.0
#> Type AUCNews() to see the change log and ?AUC to get an overview.
library(caret)
#> Error in library(caret): there is no package called 'caret'
library(e1071)
#> Error in library(e1071): there is no package called 'e1071'
library(reprex)
set.seed(569)
ctrl <- trainControl(method = "repeatedcv", number = 10, savePredictions = TRUE)
#> Error in trainControl(method = "repeatedcv", number = 10, savePredictions = TRUE): could not find function "trainControl"
model <- train(Fentanyl~
Age+Sex+Race+
Oxycodone+Hydrocodone+Buprenorphine+
Morphine+Codeine+Norbuprenorphine+
Naloxone,
ToTrain,
method = "glm", family = "poisson",
trControl = ctrl,
tuneLength = 10)#end train
#> Error in train(Fentanyl ~ Age + Sex + Race + Oxycodone + Hydrocodone + : could not find function "train"
#predicted <- predict(model, ToTrain["Fentanyl"], type = "prob")
#actual <- ToTrain["Fentanyl"]
Created on 2019-02-02 by the reprex package (v0.2.1)