# Check if the package exists. If it does not exist, download the package from CRAN if("boot" %in% rownames(installed.packages(),) == FALSE) {install.packages("boot",repos="cran.stat.ucla.edu")} library(boot) # Read the value of K kay = %Question.kfold% #print(kay) # Read the value of max degree of polynomial degree <- %Question.poldegree% #print(degree) # Read the data stream into R the.data <- read.Alteryx("#1",mode="data.frame") names(the.data) <- sapply(names(the.data), function(x) gsub("\\.", "\\_", x)) # Get the user input and make sure the names are acceptable R names name.y.var <- names(the.data)[1] #print(name.y.var) name.x.var <- names(the.data)[-1] #print(name.x.var) cv.error <- rep(0,degree) degreeVector <- 1:degree model.name <- 'glm.fit' for (d in degreeVector){ dep <- paste(paste(paste(paste('poly(',name.x.var,sep=''),',',sep=''),d,sep=''),')',sep='') the.formula <- paste(name.y.var, '~', dep) model.call <- paste(paste(model.name, ' <- glm(', the.formula, ', data = the.data', sep=""),')',sep='') eval(parse(text = model.call)) cv.error[d] <- cv.glm(data = the.data,glm.fit,K=kay)$delta[1] } AlteryxGraph(1,width=2400, height=3000, res=300) (p <- plot(degreeVector,cv.error, type = "l", col = "blue", xlab = "Model Complexity (Degree of Polynomial)")) invisible(dev.off())