├── Chapter07 ├── E1.txt ├── 07__09__periodogram.R ├── 07__03__autoarima.R ├── 07__02__sarimax.R ├── 07__04__var.R ├── 07__01__arima.R ├── beerprices.csv └── steel.csv ├── Chapter01 ├── 10 │ ├── rcpp_example.cpp │ └── Rcpp.R ├── 11 │ └── ggplot_gut.R ├── 12 │ ├── companies.csv │ └── gganimate.R ├── 13 │ ├── Customers_data.csv │ ├── Customers_data_missing_products.csv │ ├── R_classes_script_.R │ └── R_classes_script_inheritance.R ├── 14 │ ├── traminer__ex.R │ └── data__model.csv ├── 15 │ ├── traminer__ex.R │ └── data__model.csv ├── 16 │ └── example_map.R ├── 03 │ ├── ctgs.csv │ └── ggplot.R ├── 05 │ └── dplyr.R ├── 06 │ └── 3dplots.R ├── 02 │ └── densities.R ├── 07 │ ├── person_salary.csv │ └── tables.R ├── 01 │ └── maximum_likelihood.R ├── 04 │ └── random_numbers.R ├── 09 │ └── diagrammer.R └── 08 │ └── simple_sampling.R ├── Chapter03 ├── house_prices_aug.numbers ├── sales_clients_combos.numbers ├── 03__05__homocedasticitytest.R ├── 03__06__sandwich.R ├── 03__07__varselection.R ├── 03__02__sjplot.R ├── 03__04__hypothesis.R ├── 03__10__leverage.R ├── 03__03_correlations.R ├── 03__01__ols_matrix.R ├── 03__08__ridge.R ├── 03__09__lasso.R ├── sales_clients_combos.csv ├── shoes_sales.csv └── house_prices_aug.csv ├── Chapter05 ├── 05__02__anova_nonparametric.R ├── 05__01__wilcoxon.R ├── 05__06__npmv.R ├── 05__05__acepack.R ├── 05__03__spearman.R ├── 05__04__loess.R ├── 05__07__semiparametric.R ├── anova__lot_type.csv ├── pre_post_employee.csv └── heights.csv ├── Chapter02 ├── 02__03__pairedttes.R ├── 02__07__randomanova.R ├── Untitled.R ├── 02__01__ttest.R ├── 02__05__2wayanova.R ├── 02__06__types_squares.R ├── 02__10__manova.R ├── 02__09__multivariateT.R ├── 02__04__anovamechanics.R ├── 02__08__repeatedmeasures.R ├── 02__02__fisherbehrens.R ├── anova__lot_type.csv ├── class2.csv ├── class1.csv ├── pre_post_employee.csv ├── heights.csv ├── 2wayanova.csv ├── clients.csv └── employee_time_bonus.csv ├── Chapter06 ├── 06__06__mixturegaussians.R ├── 06__02__covrob.R ├── 06__01__intro.R ├── 06__04__robanova.R ├── 06__05__pca.R ├── 06__07__robustcluster.R └── 06__03__glm.R ├── densities.R ├── Chapter08 ├── 08__04__nestedcrossed.R ├── Untitled.R ├── 08__01__mixedintro.R ├── 08__05__robustlmm.R ├── company_areas.csv ├── company_areas2.csv ├── 08__07__GLMmixed.R ├── 08__02__plots.R ├── 08__06__cAIC.R ├── 08__03__nlmixed.R └── sample_random_regression.csv ├── Chapter09 ├── 09__08__logicregression.R ├── 09__03__featureselection.R ├── 09__07__lassoridgeElasticnet.R ├── lakers_.csv ├── 09__04__modeltuning.R ├── 09__05__classificationROC.R ├── 09__02__preprocessing.R ├── 09__01__partition.R ├── 09__06__gradientboosting.R └── approved.csv ├── Chapter04 ├── clients.csv ├── Untitled.R ├── 04__01__stanmodel.R ├── 04__08_glm.R ├── 04__05__stanmodel.R ├── 04__07_prediction.R ├── 04__02__stanmodel.R ├── 04__06__variableselection.R ├── 04__03__stanmodel.R └── 04__04__stanmodel.R ├── Chapter10 ├── 10__2__bayesiannetwork.R ├── 10__6__financialdata.R ├── 10__5__subwaymodel.R ├── 10__3__hybridnet.R ├── 10__1__introBNnetworks.R ├── employee_data.csv ├── 10__4__bnviewer.R ├── subway_data.csv └── subway_data_extended.csv ├── LICENSE └── README.md /Chapter07/E1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/R-Statistics-Cookbook/HEAD/Chapter07/E1.txt -------------------------------------------------------------------------------- /Chapter01/11/ggplot_gut.R: -------------------------------------------------------------------------------- 1 | install.packages("ggplotgui") 2 | 3 | library("ggplotgui") 4 | 5 | 6 | ggplot_shiny(mtcars) 7 | -------------------------------------------------------------------------------- /Chapter03/house_prices_aug.numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/R-Statistics-Cookbook/HEAD/Chapter03/house_prices_aug.numbers -------------------------------------------------------------------------------- /Chapter03/sales_clients_combos.numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/R-Statistics-Cookbook/HEAD/Chapter03/sales_clients_combos.numbers -------------------------------------------------------------------------------- /Chapter01/03/ctgs.csv: -------------------------------------------------------------------------------- 1 | Company,Adjusted Sales, Unadjusted Sales 2 | Company1,298,394 3 | Company2,392,454 4 | Company3,453,499 5 | Compnay4,541,598 6 | Company5,674,762 7 | -------------------------------------------------------------------------------- /Chapter01/05/dplyr.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | library(dplyr) 4 | 5 | 6 | mtcars 7 | 8 | mtcars %>% group_by(am,gear) %>% summarise(mean_hp = mean(hp),sum_mpg = sum(mpg)) %>% ungroup %>% arrange(mean_hp) 9 | -------------------------------------------------------------------------------- /Chapter01/13/Customers_data.csv: -------------------------------------------------------------------------------- 1 | Customer_id,Name,City 2 | 1,John M,New York 3 | 2,Lisa,London 4 | 3,Stephanie,New York 5 | 4,Robert,Miami 6 | 5,Steven M,Barcelona 7 | 6,Sarah C,Barcelona 8 | 7,Michael B,New York -------------------------------------------------------------------------------- /Chapter03/03__05__homocedasticitytest.R: -------------------------------------------------------------------------------- 1 | data = read.csv("./people_shopping.csv") 2 | 3 | model = lm(sales ~ people_in + discount,data=data) 4 | plot(model) 5 | 6 | library("lmtest") 7 | bptest(model) 8 | 9 | -------------------------------------------------------------------------------- /Chapter01/13/Customers_data_missing_products.csv: -------------------------------------------------------------------------------- 1 | Customer_id,Name,City,Missing_product,Missing_since 2 | 827,Michaela,London,TV,01/01/2018 3 | 821,Tom,Radio,London,03/05/2018 4 | 628,Tim,TV,Miami,05/03/2018 5 | 829,Emma,Miami,Dinner table,08/02/2018 6 | -------------------------------------------------------------------------------- /Chapter05/05__02__anova_nonparametric.R: -------------------------------------------------------------------------------- 1 | 2 | library(FSA) 3 | library(dplyr) 4 | 5 | 6 | t = read.csv("./anova__lot_type.csv") 7 | kruskal.test(Result ~ Food.Type,data=t) 8 | 9 | 10 | dunnTest(Result ~ Food.Type,data=t) 11 | -------------------------------------------------------------------------------- /Chapter02/02__03__pairedttes.R: -------------------------------------------------------------------------------- 1 | data = read.csv("./pre_post_employee.csv") 2 | 3 | t.test(data$post_bonus,data$pre_bonus,conf.level = .95,alternative="greater",paired=TRUE) 4 | t.test(data$post_bonus,data$pre_bonus,conf.level = .95,alternative="less",paired=TRUE) 5 | -------------------------------------------------------------------------------- /Chapter03/03__06__sandwich.R: -------------------------------------------------------------------------------- 1 | data = read.csv("./people_shopping.csv") 2 | 3 | model = lm(sales ~ people_in + discount,data=data) 4 | 5 | library("lmtest") 6 | bptest(model) 7 | 8 | summary(model) 9 | 10 | 11 | library(sandwich) 12 | coeftest(model, vcov=vcovHC(model)) 13 | -------------------------------------------------------------------------------- /Chapter05/05__01__wilcoxon.R: -------------------------------------------------------------------------------- 1 | data = read.csv("./heights.csv") 2 | data$Sample = as.factor(data$Sample) 3 | wilcox.test(Height ~ Sample,data=data) 4 | 5 | 6 | 7 | data = read.csv("./pre_post_employee.csv") 8 | wilcox.test(data$post_bonus, data$pre_bonus,paired=TRUE) 9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter01/06/3dplots.R: -------------------------------------------------------------------------------- 1 | 2 | library(plot3D) 3 | 4 | x = rnorm(100) 5 | y = rnorm(100) 6 | z = x + y + rnorm(100,0,0.3) 7 | idrow = 1:100 8 | 9 | 10 | scatter3D(x, y, z, bty = "g", colkey = TRUE, main ="x-y-z plot",phi = 10,theta=50) 11 | text3D(x, y, z, labels = idrow, add = TRUE, colkey = FALSE, cex = 0.5) 12 | -------------------------------------------------------------------------------- /Chapter06/06__06__mixturegaussians.R: -------------------------------------------------------------------------------- 1 | library(qclust) 2 | 3 | data ("geyser2") 4 | 5 | 6 | result_robust_mixture <- qclust::Qclust(geyser2,K=3,q=0.9999) 7 | 8 | plot(result_robust_mixture) 9 | 10 | plot(result_robust_mixture,what="density",type="persp") 11 | plot(result_robust_mixture,what="boundaries",ngrid=200) -------------------------------------------------------------------------------- /Chapter05/05__06__npmv.R: -------------------------------------------------------------------------------- 1 | library(npmv) 2 | 3 | nonpartest(Sepal.Length | Sepal.Width | Petal.Length | Petal.Width ~ Species, data = iris, permreps = 2000) 4 | 5 | 6 | ssnonpartest(Sepal.Length | Sepal.Width | Petal.Length | Petal.Width ~ Species, data = iris, test = c(1, 0, 0, 0), alpha = 0.05, factors.and.variables = TRUE) 7 | -------------------------------------------------------------------------------- /Chapter02/02__07__randomanova.R: -------------------------------------------------------------------------------- 1 | library(lme4) 2 | library(lmerTest) 3 | library(lsmeans) 4 | clients <- read.csv("./clients.csv") 5 | 6 | 7 | E = lmer(Sales ~ -1 + Strategy + (1|Client) + (1|Salesman),data=clients) 8 | summary(E) 9 | 10 | result_lsmeans = lsmeans(E,pairwise ~ Strategy) 11 | print(result_lsmeans) 12 | 13 | anova(E) 14 | -------------------------------------------------------------------------------- /Chapter02/Untitled.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | data = read.csv("./heights.csv") 3 | data$Sample = as.factor(data$Sample) 4 | leveneTest(Height ~ Sample,data) 5 | 6 | 7 | sample1 = data %>% filter(Sample==1) %>% select(Height) 8 | sample2 = data %>% filter(Sample==2) %>% select(Height) 9 | 10 | 11 | t.test(sample1,sample2,var.equal=TRUE,conf.level = .95,alternative="two.sided") -------------------------------------------------------------------------------- /densities.R: -------------------------------------------------------------------------------- 1 | 2 | vals = rnorm(10000,0,1) 3 | 4 | 5 | 6 | plot(density(vals)) 7 | abline(v=2,col="red") 8 | 9 | 10 | 11 | print(paste("Area to the left of x=2",pnorm(2,0,1))) 12 | print(paste("Area to the right of x=2",1-pnorm(2,0,1))) 13 | print(paste("90th Quantile: x value that has 90% to the left",qnorm(0.9,0,1))) 14 | 15 | 16 | 17 | print(paste("Area to the left of x=3",pchisq(3,33))) 18 | 19 | -------------------------------------------------------------------------------- /Chapter01/03/ggplot.R: -------------------------------------------------------------------------------- 1 | library(ggplot2) 2 | library(reshape) 3 | 4 | datag = read.csv("./ctgs.csv") 5 | 6 | 7 | 8 | transformed_data = melt(datag,id.vars = "Company") 9 | 10 | ggplot(transformed_data, aes(x = Company, y = value, fill = variable)) + geom_bar(stat = "identity") 11 | ggplot(transformed_data, aes(x = Company, y = value, fill = variable)) + geom_bar(stat = "identity",position=position_dodge()) 12 | -------------------------------------------------------------------------------- /Chapter02/02__01__ttest.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | library(car) 3 | 4 | data = read.csv("./heights.csv") 5 | data$Sample = as.factor(data$Sample) 6 | leveneTest(Height ~ Sample,data) 7 | 8 | 9 | sample1 = data %>% filter(Sample==1) %>% select(Height) 10 | sample2 = data %>% filter(Sample==2) %>% select(Height) 11 | 12 | 13 | t.test(sample1,sample2,var.equal=TRUE,conf.level = .95,alternative="two.sided") -------------------------------------------------------------------------------- /Chapter03/03__07__varselection.R: -------------------------------------------------------------------------------- 1 | library("olsrr") 2 | library(dplyr) 3 | 4 | 5 | model = lm(data=Boston,medv ~ .) 6 | 7 | head(ols_step_all_possible(model) %>% arrange(desc(adjr))) 8 | 9 | ols_step_forward_p(model) 10 | 11 | ols_step_backward_p(model) 12 | 13 | ols_step_both_p(model) 14 | 15 | 16 | 17 | 18 | ols_step_forward_aic(model) 19 | 20 | ols_step_backward_aic(model) 21 | 22 | ols_step_both_aic(model) 23 | 24 | -------------------------------------------------------------------------------- /Chapter01/02/densities.R: -------------------------------------------------------------------------------- 1 | 2 | vals = rnorm(10000,0,1) 3 | 4 | 5 | 6 | plot(main = "density",density(vals)) 7 | abline(v=2,col="red") 8 | 9 | 10 | 11 | print(paste("Area to the left of x=2",pnorm(2,0,1))) 12 | print(paste("Area to the right of x=2",1-pnorm(2,0,1))) 13 | print(paste("90th Quantile: x value that has 97.72% to the left",qnorm(0.9772,0,1))) 14 | 15 | 16 | 17 | print(paste("Area to the left of x=3",pchisq(3,33))) 18 | 19 | -------------------------------------------------------------------------------- /Chapter03/03__02__sjplot.R: -------------------------------------------------------------------------------- 1 | library(sjPlot) 2 | library(lme4) 3 | 4 | clients <- read.csv("./sales_clients_combos.csv") 5 | 6 | model1 <- lm(Sales ~ Strategy + (Client) + (Salesman),data=clients) 7 | 8 | tab_model(model1) 9 | 10 | 11 | 12 | 13 | model2 <- lmer(Sales ~ Strategy + Client + (1|Salesman),data=clients) 14 | 15 | tab_model(model2) 16 | 17 | 18 | 19 | tab_df(clients,title="Clients dataset",alternate.rows = TRUE) 20 | -------------------------------------------------------------------------------- /Chapter02/02__05__2wayanova.R: -------------------------------------------------------------------------------- 1 | data = read.csv("./2wayanova.csv") 2 | 3 | d = aov(Sales ~ Colour + Font + Font*Colour,data=data ) 4 | plot(d, 2) 5 | shapiro.test(residuals(d)) 6 | 7 | 8 | 9 | data = data[-c(22,44),] 10 | d = aov(Sales ~ Colour + Font + Font*Colour,data=data ) 11 | plot(d, 2) 12 | shapiro.test(residuals(d)) 13 | 14 | plot(d, 1) 15 | 16 | anova(d) 17 | 18 | rbind(TukeyHSD(d)$Colour,TukeyHSD(d)$Font) 19 | -------------------------------------------------------------------------------- /Chapter06/06__02__covrob.R: -------------------------------------------------------------------------------- 1 | library(MASS) 2 | 3 | library(robust) 4 | 5 | Sigma <- matrix(c(2,1,1,2),2,2) 6 | d <- mvrnorm(n = 1000, mu=c(5,5), Sigma) 7 | covClassic(d,cor = TRUE) 8 | cov.rob(d,cor = TRUE) 9 | 10 | 11 | d[1:50,1:2] = matrix(rnorm(100,20,10),c(50,2)) 12 | covClassic(d,cor = TRUE) 13 | 14 | 15 | cov.rob(d,cor = TRUE) 16 | d[1:200,1:2] = matrix(rnorm(400,20,10),c(50,2)) 17 | covClassic(d,cor = TRUE) 18 | cov.rob(d,cor = TRUE) -------------------------------------------------------------------------------- /Chapter01/07/person_salary.csv: -------------------------------------------------------------------------------- 1 | Person,Career,Age,Salary,Contacted 2 | John,Engineer,+45,10.000,TRUE 3 | Mike,Engineer,+45,13.000,FALSE 4 | Lisa,Teacher,30-45,12.000,TRUE 5 | Marcel,Sales,30-45,18.000,TRUE 6 | Max,Sales,30-45,12.000,TRUE 7 | Paul,Teacher,+45,13.000,FALSE 8 | Paul,Egineer,30-45,18.000,FALSE 9 | Anthony,Sales,20-30,13.000,FALSE 10 | Tom,Lawyer,20-30,19.000,FALSE 11 | Lisa,Lawyer,20-30,18.000,TRUE 12 | Alex,Teacher,20-30,21.000,TRUE 13 | Tom,Pilot,30-45,23.000,TRUE 14 | -------------------------------------------------------------------------------- /Chapter06/06__01__intro.R: -------------------------------------------------------------------------------- 1 | set.seed(10) 2 | x1 = rnorm(100,0,2) 3 | x2 = rnorm(100,0,2) 4 | y = x1 + x2 + rnorm(100,0,1) 5 | y[100] = 100 6 | 7 | plot(x1,y) 8 | 9 | e = lm(y ~ -1+ x1 + x2) 10 | summary(e) 11 | 12 | 13 | 14 | rlm_model = rlm(y ~ -1 + x1 + x2,psi =psi.huber) 15 | summary(rlm_model) 16 | 17 | 18 | rlm_model = rlm(y ~ -1 + x1 + x2,psi = psi.hampel) 19 | summary(rlm_model) 20 | 21 | rlm_model = rlm(y ~ -1 + x1 + x2,psi = psi.bisquare) 22 | summary(rlm_model) 23 | -------------------------------------------------------------------------------- /Chapter02/02__06__types_squares.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | library(car) 3 | r = read.csv("./2wayanova.csv") 4 | r = r[-c(22,44),] 5 | 6 | 7 | type1 = aov(Sales ~ Colour + Font + Font*Colour,data=r ) 8 | summary(type1) 9 | 10 | 11 | 12 | type2 = Anova(aov(Sales ~ Colour + Font,data=r ),type=c("II")) 13 | type2 14 | 15 | 16 | 17 | options(contrasts = c("contr.sum","contr.poly")) 18 | type3 = Anova(aov(Sales ~ Colour + Font + Font*Colour,data=r ),type=c("III")) 19 | type3 -------------------------------------------------------------------------------- /Chapter06/06__04__robanova.R: -------------------------------------------------------------------------------- 1 | library(robust) 2 | 3 | 4 | r = PlantGrowth 5 | 6 | 7 | d = aov(weight ~ group,data=r ) 8 | summary(d) 9 | plot(d, 2) 10 | 11 | 12 | 13 | robanova = robust::lmRob(weight ~ group,data=r ) 14 | robust::anova.lmRob(robanova) 15 | 16 | 17 | 18 | 19 | 20 | r[1,1] = 50 21 | r[2,1] = 50 22 | d = aov(weight ~ group,data=r ) 23 | 24 | plot(d, 2) 25 | summary(d) 26 | 27 | 28 | robanova = robust::lmRob(weight ~ group,data=r ) 29 | robust::anova.lmRob(robanova) 30 | -------------------------------------------------------------------------------- /Chapter03/03__04__hypothesis.R: -------------------------------------------------------------------------------- 1 | library(multcomp) 2 | 3 | data = read.csv("./house_prices.csv") 4 | 5 | model = lm(Property_price ~ size + number.bathrooms + number.bedrooms + number.entrances + size_balcony + size_entrance,data=data) 6 | summary(model) 7 | 8 | summary(glht(model,linfct = c("number.bathrooms + number.entrances + number.bedrooms + size_balcony + size_entrance - size = 0"))) 9 | 10 | summary(glht(model,linfct = c("number.entrances + number.bathrooms - size_balcony - size_entrance = 0"))) 11 | -------------------------------------------------------------------------------- /Chapter08/08__04__nestedcrossed.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | data = read.csv("./company_areas.csv") 4 | 5 | xtabs(~ Group + Person, data) 6 | 7 | lmer(Rating ~ -1 + (1 | Group/Person) , data = data) 8 | 9 | lmer(Rating ~ -1 + (1 | Group) + (1 | Person), data = data) 10 | 11 | 12 | 13 | 14 | 15 | data2 = read.csv("./company_areas2.csv") 16 | 17 | xtabs(~ Group + Person, data2) 18 | 19 | lmer(Rating ~ -1 + (1 | Group/Person) , data = data2) 20 | 21 | lmer(Rating ~ -1 + (1 | Group) + (1 | Person), data = data2) -------------------------------------------------------------------------------- /Chapter02/02__10__manova.R: -------------------------------------------------------------------------------- 1 | library(MASS) 2 | f = matrix(c(2,1,1,1,2,1,1,1,2),3,3) 3 | 4 | x1 = mvrnorm(50,c(10,10,10),f) 5 | x1 = cbind(x1,1) 6 | x2 = mvrnorm(50,c(10,10,10),f) 7 | x2 = cbind(x2,2) 8 | x3 = mvrnorm(50,c(30,10,10),f) 9 | x3 = cbind(x3,3) 10 | 11 | 12 | total_data = data.frame(rbind(x1,x2,x3)) 13 | colnames(total_data) = c("History","Math","Biology","class") 14 | 15 | 16 | result = manova(cbind(History,Math,Biology) ~ class,data=total_data) 17 | summary(result) 18 | 19 | 20 | summary.aov(result) -------------------------------------------------------------------------------- /Chapter07/07__09__periodogram.R: -------------------------------------------------------------------------------- 1 | library(imputeTS) 2 | library(timesboot) 3 | 4 | steel =read.csv("./steel.csv") 5 | steel = ts(steel$valor,start=c(1993,1),frequency = 12) 6 | plot.ts(steel) 7 | spectrum(steel, spans = c(5, 7),lty = 1) 8 | 9 | 10 | 11 | 12 | 13 | steel_trend = decompose(steel) 14 | corrected = steel - steel_trend$trend 15 | corrected = imputeTS::na.kalman(corrected) 16 | plot.ts(corrected) 17 | 18 | 19 | 20 | 21 | td = timesboot::boot_spec(corrected,de_trend = FALSE) -------------------------------------------------------------------------------- /Chapter01/14/traminer__ex.R: -------------------------------------------------------------------------------- 1 | 2 | library(TraMineR) 3 | 4 | datax <- read.csv("./data__model.csv",stringsAsFactors = FALSE) 5 | mvad.labels <- c("CLOSED","L1", "L2", "L3") 6 | mvad.scode <- c("CLD","L1", "L2", "L3") 7 | mvad.seq <- seqdef(datax, 3:22, states = mvad.scode,labels = mvad.labels) 8 | group__ <- paste0(datax$Sex,"-",datax$Age) 9 | 10 | 11 | seqfplot(mvad.seq, with.legend = T, border = NA,group=group__, main = "Sequence frequency plot") 12 | seqdplot(mvad.seq, with.legend = T,group=group__, border = NA, main = "State distribution plot") 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter08/Untitled.R: -------------------------------------------------------------------------------- 1 | data = read.csv("C:\\R_book\\sample_random_regression.csv") 2 | 3 | data$clientid = as.factor(data$clientid) 4 | 5 | library("lme4") 6 | 7 | 8 | lmer(data=data,deal_size ~ salespeople_involved + time_spent_deal + (-1 + salespeople_involved|clientid) + (-1 + time_spent_deal|clientid) ) 9 | 10 | lmer(data=data,deal_size ~ salespeople_involved + time_spent_deal + (1 + salespeople_involved|clientid) ) 11 | 12 | lmer(data=data,deal_size ~ salespeople_involved + time_spent_deal + (1 + time_spent_deal + salespeople_involved|clientid) ) 13 | 14 | ranef(model) -------------------------------------------------------------------------------- /Chapter09/09__08__logicregression.R: -------------------------------------------------------------------------------- 1 | set.seed(10) 2 | library(caret) 3 | 4 | baseketball_data_2019 = read.csv("./lakers_.csv") 5 | baseketball_data_2019 = baseketball_data_2019[,-c(1,2)] 6 | 7 | 8 | 9 | rctrl1 <- trainControl(method = "cv",number=5) 10 | baseketball_data_2019$win = as.factor(baseketball_data_2019$win) 11 | model1 <- train(win~.,baseketball_data_2019, 12 | method = "logreg", 13 | metric = "Accuracy", 14 | trControl = rctrl1, 15 | tuneLength = 4) -------------------------------------------------------------------------------- /Chapter02/02__09__multivariateT.R: -------------------------------------------------------------------------------- 1 | library(MASS) 2 | library(Hotelling) 3 | 4 | class1 = read.csv("./class1.csv") 5 | class2 = read.csv("./class2.csv") 6 | 7 | sapply(class1,mean) 8 | sapply(class2,mean) 9 | 10 | test_hotelling = hotelling.test(class1,class2) 11 | print(test_hotelling) 12 | 13 | 14 | 15 | 16 | library(heplots) 17 | 18 | class1$group = "1" 19 | class2$group = "2" 20 | combined = rbind(class1,class2) 21 | combined$group = as.factor(combined$group) 22 | 23 | boxM(cbind(combined$Math,combined$History,combined$Sociology)~group,data = combined) 24 | -------------------------------------------------------------------------------- /Chapter04/clients.csv: -------------------------------------------------------------------------------- 1 | bought,age,bought_before,time_as_customer 2 | 0,23,0,2 3 | 0,19,1,0 4 | 0,21,0,2 5 | 0,27,0,1 6 | 0,21,3,0 7 | 0,17,0,2 8 | 0,22,3,2 9 | 0,22,8,0 10 | 0,26,0,2 11 | 0,23,3,1 12 | 0,29,0,0 13 | 0,17,3,1 14 | 0,23,1,1 15 | 0,18,0,1 16 | 0,23,3,0 17 | 0,18,0,1 18 | 0,18,9,0 19 | 0,19,0,2 20 | 0,21,1,3 21 | 1,62,1,11 22 | 1,57,12,5 23 | 1,55,22,7 24 | 1,51,27,12 25 | 1,61,2,9 26 | 1,26,2,8 27 | 1,53,8,7 28 | 1,53,8,7 29 | 1,23,11,6 30 | 1,69,5,8 31 | 1,23,14,10 32 | 1,23,18,5 33 | 1,53,9,10 34 | 1,29,3,10 35 | 1,53,7,10 36 | 1,23,6,11 37 | 1,53,3,8 38 | 1,25,2,5 39 | 1,29,12,8 40 | 1,49,14,8 41 | 1,43,19,5 42 | -------------------------------------------------------------------------------- /Chapter06/06__05__pca.R: -------------------------------------------------------------------------------- 1 | library(MASS) 2 | 3 | library(rospca) 4 | 5 | set.seed(100) 6 | 7 | matrix = diag(10) 8 | 9 | matrix[2,1] = 0.8 10 | 11 | matrix[1,2] = 0.8 12 | 13 | matrix[4,3] = 0.8 14 | 15 | matrix[3,4] = 0.8 16 | 17 | matrix[5,6] = 0.8 18 | 19 | matrix[6,5] = 0.8 20 | 21 | 22 | 23 | 24 | 25 | 26 | d <- mvrnorm(n = 1000, mu=rep(0,10), matrix) 27 | 28 | prcomp(d,scale=TRUE,center=TRUE) 29 | 30 | x1 = rospca::robpca(d) 31 | 32 | x1$eigenvalues 33 | 34 | 35 | 36 | d[1:1,1:10] <- -400 37 | prcomp(d,scale=TRUE,center=TRUE) 38 | 39 | x1 = rospca::robpca(d) 40 | 41 | x1$eigenvalues -------------------------------------------------------------------------------- /Chapter07/07__03__autoarima.R: -------------------------------------------------------------------------------- 1 | library(forecast) 2 | 3 | average_temp = read.csv("./temperature.csv") 4 | average_temp$indice_tiempo = as.Date(average_temp$indice_tiempo,"%Y-%m-%d") 5 | average_temp = ts(average_temp$temperatura_promedio,start=c(2001,1),frequency = 12) 6 | 7 | 8 | plot.ts(average_temp) 9 | best_mode = auto.arima(average_temp,max.p=5,max.q=5,max.Q=2,max.P=2,allowmean = TRUE,allowdrift = FALSE) 10 | 11 | 12 | plot.ts(average_temp) 13 | lines(best_mode$fitted,col="red") 14 | 15 | predictions <- forecast(best_mode$fitted,48) 16 | plot(predictions) 17 | -------------------------------------------------------------------------------- /Chapter06/06__07__robustcluster.R: -------------------------------------------------------------------------------- 1 | library(tclust) 2 | library(ggplot2) 3 | data ("geyser2") 4 | 5 | 6 | clus_kmeans <- kmeans (geyser2, centers = 3) 7 | clus_tkmeans <- tkmeans (geyser2, k = 3, alpha = 0.05) 8 | geyser2$cluster <- as.factor(clus_kmeans$cluster) 9 | 10 | 11 | 12 | 13 | ggplot(geyser2, aes(x=geyser2$`Eruption length`, y=geyser2$`Previous eruption length`,color=geyser2$cluster)) + labs(x = "Eruption length", y = "Previous eruption length")+theme(legend.position="none") + geom_point(aes(size=3,alpha = 0.2)) 14 | 15 | 16 | plot (clus_tkmeans,main="Robust k-means",xlab="X-axis label", ylab="y-axix label") 17 | -------------------------------------------------------------------------------- /Chapter01/01/maximum_likelihood.R: -------------------------------------------------------------------------------- 1 | library(bbmle) 2 | N <- 1000 3 | xx <- rgamma(N, shape=20,rate=2) 4 | LL <- function(shape, rate) { 5 | R = suppressWarnings(dgamma(xx, shape=shape, rate=rate)) 6 | return(-sum(log(R))) 7 | } 8 | 9 | P_1000 = mle2(LL, start = list(shape = 1, rate=1)) 10 | summary(P_1000) 11 | 12 | 13 | 14 | 15 | 16 | N <- 10 17 | x <- rgamma(N, shape=20,rate=2) 18 | LL <- function(shape, rate) { 19 | R = suppressWarnings(dgamma(x, shape=shape, rate=rate)) 20 | return(-sum(log(R))) 21 | } 22 | 23 | P_10 = mle2(LL, start = list(shape = 1, rate=1)) 24 | summary(P_10) 25 | 26 | confint(P_1000) 27 | confint(P_10) 28 | -------------------------------------------------------------------------------- /Chapter04/Untitled.R: -------------------------------------------------------------------------------- 1 | library(rstan) 2 | 3 | values = list(y = rnorm(1000,5,3)) 4 | 5 | model =" 6 | 7 | data { 8 | real y[1000]; 9 | } 10 | 11 | parameters { 12 | real mu; 13 | real sigma; 14 | } 15 | 16 | model { 17 | mu ~ normal(0,10); 18 | sigma ~ normal(0,10); 19 | y ~ normal(mu,sigma); 20 | } 21 | " 22 | 23 | fit <- stan(model_code = model, data = values, warmup = 500, iter = 1000, chains = 4, cores = 2, thin = 1) 24 | posterior = extract(fit) 25 | 26 | par(mfrow=c(2,1)) 27 | plot(posterior$mu, type = "l") 28 | plot(posterior$sigma, type = "l") 29 | traceplot(fit) 30 | stan_dens(fit) 31 | summary(fit) 32 | 33 | -------------------------------------------------------------------------------- /Chapter04/04__01__stanmodel.R: -------------------------------------------------------------------------------- 1 | library(rstan) 2 | 3 | values = list(y = rnorm(1000,5,3)) 4 | 5 | model =" 6 | 7 | data { 8 | real y[1000]; 9 | } 10 | 11 | parameters { 12 | real mu; 13 | real sigma; 14 | } 15 | 16 | model { 17 | mu ~ normal(0,10); 18 | sigma ~ normal(0,10); 19 | y ~ normal(mu,sigma); 20 | } 21 | " 22 | 23 | fit <- stan(model_code = model, data = values, warmup = 500, iter = 1000, chains = 4, cores = 2, thin = 1) 24 | posterior = extract(fit) 25 | 26 | par(mfrow=c(2,1)) 27 | plot(posterior$mu, type = "l") 28 | plot(posterior$sigma, type = "l") 29 | traceplot(fit) 30 | stan_dens(fit) 31 | summary(fit) 32 | 33 | -------------------------------------------------------------------------------- /Chapter07/07__02__sarimax.R: -------------------------------------------------------------------------------- 1 | library(forecast) 2 | 3 | car_production =read.csv("./car_production.csv") 4 | 5 | car_production$indice_tiempo = as.Date(car_production$indice_tiempo,"%Y-%m-%d") 6 | car_production = ts(car_production$produccion_automotriz_unidades,start=c(1981,1),frequency = 12) 7 | 8 | 9 | plot.ts(car_production) 10 | acf(diff(car_production)) 11 | 12 | 13 | 14 | results <- arima(car_production,order=c(1,1,0),seasonal=c(2,0,0,12)) 15 | results 16 | 17 | 18 | 19 | predictions <- forecast(results,24) 20 | plot(predictions) 21 | 22 | 23 | 24 | plot.ts(results$residuals) 25 | qqnorm(results$residuals) -------------------------------------------------------------------------------- /Chapter01/16/example_map.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | library(leaflet) 3 | 4 | line = data.frame(lat = c(-54.777255,-38.038561),long=c(-64.936853,-57.529756),mag="start") 5 | sub_data = data.frame(lat = c(-54.777255,-38.038561,-46.12,-46.73333333333333),long=c(-64.936853,-57.529756,-59.69,-60.13333333333333),mag=c("start","end","sound anomaly","last known position")) 6 | area_search = data.frame(lat=-46.12,long=-59.69) 7 | 8 | leaflet(data = sub_data) %>% addTiles() %>% 9 | addMarkers(~long, ~lat, popup = ~as.character(mag), label = ~as.character(mag)) %>% 10 | addPolylines(data = line, lng = ~long, lat = ~lat) %>% addCircles(lng = -59.69, lat = -46.12, weight = 1,radius = 120000) -------------------------------------------------------------------------------- /Chapter05/05__05__acepack.R: -------------------------------------------------------------------------------- 1 | library(acepack) 2 | 3 | 4 | data = read.csv("./house_prices.csv") 5 | 6 | x = data[,2:7] 7 | 8 | y = data[,1] 9 | 10 | 11 | 12 | lm_model = lm(data=data,Property_price~ size + number.bathrooms + number.bedrooms + number.entrances + size_balcony + size_entrance) 13 | summary(lm_model) 14 | 15 | 16 | ace_model = ace(x,y) 17 | 18 | ace_model$rsq 19 | 20 | par(mfrow=c(1,2)) 21 | plot(ace_model$x[1,],ace_model$tx[,1],xlab="untransformed size_entrance",ylab="transformed size_entrance") 22 | plot(ace_model$x[5,],ace_model$tx[,5],xlab="untransformed size_balcony",ylab="transformed size_balcony") 23 | 24 | 25 | -------------------------------------------------------------------------------- /Chapter01/10/rcpp_example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace Rcpp; 3 | 4 | // [[Rcpp::export]] 5 | int bring_element (NumericVector rand_vector, NumericMatrix rand_matrix) { 6 | Rcout << "Process starting" << std::endl; 7 | int mcounter = 0; 8 | 9 | for (int q = 0; q < rand_vector.size();q++){ 10 | for (int x = 0; x < rand_matrix.rows();x++){ 11 | for (int y = 0; y < rand_matrix.cols();y++){ 12 | double v1 = rand_matrix.at(x,y); 13 | double v2 = rand_vector[q]; 14 | if ( v1 < v2){ 15 | mcounter++; 16 | } 17 | } 18 | } 19 | } 20 | 21 | Rcout << "Process ended" << std::endl; 22 | return mcounter; 23 | } 24 | -------------------------------------------------------------------------------- /Chapter01/12/companies.csv: -------------------------------------------------------------------------------- 1 | Company,Year,Sales,Profit,Company_id 2 | A,1990,928,45,#D4BCDB 3 | A,2000,812,56,#D4BCDB 4 | A,2010,989,88,#D4BCDB 5 | A,2018,1302,98,#D4BCDB 6 | B,1990,82,20,#8AC34F 7 | B,2000,188,26,#8AC34F 8 | B,2010,289,56,#8AC34F 9 | B,2018,459,189,#8AC34F 10 | C,1990,1500,200,#C6E79C 11 | C,2000,1700,300,#C6E79C 12 | C,2010,1900,569,#C6E79C 13 | C,2018,2300,849,#C6E79C 14 | D,1990,1340,134,#313695 15 | D,2000,1565,188,#313695 16 | D,2010,1892,459,#313695 17 | D,2018,1892,499,#313695 18 | E,1990,732,67,#468A1F 19 | E,2000,837,92,#468A1F 20 | E,2010,140,34,#468A1F 21 | E,2018,189,29,#468A1F 22 | F,1990,45,89,#AD0826 23 | F,2000,78,18,#AD0826 24 | F,2010,188,36,#AD0826 25 | F,2018,399,199,#AD0826 26 | -------------------------------------------------------------------------------- /Chapter05/05__03__spearman.R: -------------------------------------------------------------------------------- 1 | x = seq(1,100) 2 | 3 | y = 20/(1+exp(x-50)) 4 | 5 | plot(x,y) 6 | 7 | 8 | cor.test( ~ x + y, method = "spearman",conf.level = 0.95) 9 | 10 | cor.test( ~ x + y, method = "pearson",conf.level = 0.95) 11 | 12 | 13 | x = seq(1,100) 14 | 15 | y = sapply(x,function(x){(runif(1)-0.5)*10 + 20/(1+exp(x-50))}) 16 | 17 | plot(x,y) 18 | 19 | 20 | 21 | cor.test( ~ x + y, method = "spearman",conf.level = 0.95) 22 | 23 | cor.test( ~ x + y, method = "pearson",conf.level = 0.95) 24 | 25 | 26 | 27 | salary=c(10,50,45,87,69,100) 28 | 29 | educ_level=c(1,2,3,4,5,6) 30 | 31 | cor.test( ~ salary + educ_level, method = "spearman",conf.level = 0.95) -------------------------------------------------------------------------------- /Chapter03/03__10__leverage.R: -------------------------------------------------------------------------------- 1 | library(car) 2 | 3 | data = read.csv("./house_prices_aug.csv") 4 | 5 | model = lm(Property_price ~ size + number.bathrooms + number.bedrooms +number.entrances +size_balcony +size_entrance,data=data) 6 | plot(model) 7 | 8 | 9 | 10 | leveragePlots(model) 11 | 12 | outlierTest(model) 13 | 14 | plot(hatvalues(model), type = "h") 15 | 16 | 17 | 18 | cooksd <- sort(cooks.distance(model)) 19 | 20 | cutoff <- 4/((nrow(data)-length(model$coefficients)-1)) 21 | 22 | plot(model, which=4, cook.levels=cutoff) 23 | 24 | 25 | model2 = lm(Property_price ~ size + number.bathrooms + number.bedrooms +number.entrances +size_balcony +size_entrance,data=data[-c(408),]) 26 | 27 | model 28 | model2 29 | -------------------------------------------------------------------------------- /Chapter08/08__01__mixedintro.R: -------------------------------------------------------------------------------- 1 | data = read.csv("./sample_random_regression.csv") 2 | 3 | data$clientid = as.factor(data$clientid) 4 | 5 | library("lme4") 6 | 7 | 8 | lmer(data=data,deal_size ~ salespeople_involved + time_spent_deal + (-1 + salespeople_involved|clientid) + (-1 + time_spent_deal|clientid) ) 9 | 10 | lmer(data=data,deal_size ~ salespeople_involved + time_spent_deal + (1 + salespeople_involved|clientid) ) 11 | 12 | lmer(data=data,deal_size ~ salespeople_involved + time_spent_deal + (1 + time_spent_deal + salespeople_involved|clientid) ) 13 | 14 | model = lmer(data=data,deal_size ~ salespeople_involved + time_spent_deal + (-1 + salespeople_involved|clientid) + (-1 + time_spent_deal|clientid) ) 15 | ranef(model) 16 | -------------------------------------------------------------------------------- /Chapter01/12/gganimate.R: -------------------------------------------------------------------------------- 1 | # Load required package 2 | library(gapminder) 3 | library(gganimate) 4 | # Basic scatter plot 5 | 6 | data = read.csv("./companies.csv",stringsAsFactors = FALSE) 7 | colors = c("A"="#AB5406","B"="#EC9936","C"="#BE1826","D"="#9B4A06","E"="#FDD6A2","F"="#9ACD62") 8 | 9 | p = ggplot(data, aes(Sales, Profit, size = Profit,colour=Company)) + 10 | geom_point(alpha = 0.7, show.legend = FALSE) + 11 | scale_colour_manual(values = colors) + 12 | scale_size(range = c(2, 12)) + 13 | # Here comes the gganimate specific bits 14 | labs(title = 'Year: {frame_time}', x = 'Sales', y = 'Profit') + 15 | transition_time(Year) + 16 | ease_aes('linear') 17 | 18 | animate(p, nframes = 48, renderer = gifski_renderer("/Users/admin/Documents/R_book/gganim.gif")) 19 | -------------------------------------------------------------------------------- /Chapter07/07__04__var.R: -------------------------------------------------------------------------------- 1 | library(vars) 2 | 3 | 4 | oilgas =read.csv("./fuel_series.csv") 5 | colnames(oilgas) = c("time_index","oil_processed","gasoil_prod","fueloil_prod","butane") 6 | joined_data =ts(oilgas[-1],start=c(1996,1),frequency=12) 7 | 8 | 9 | m = VAR(joined_data,p=12) 10 | summary(m) 11 | restrict(m, method = "ser") 12 | any(roots(m)>0.9999) 13 | 14 | normalitytest <- normality.test(m) 15 | plot(normalitytest) 16 | 17 | plot(m) 18 | 19 | var.2c.fevd <- fevd(m, n.ahead = 5) 20 | plot(var.2c.fevd) 21 | 22 | var.2c.irf <- irf(m, impulse = "oil_processed", 23 | response = c("butane", "gasoil_prod", "fueloil_prod"), boot = TRUE) 24 | plot(var.2c.irf) 25 | 26 | var.2c.prd <- predict(m, n.ahead = 24, ci = 0.95) 27 | plot(var.2c.prd) 28 | -------------------------------------------------------------------------------- /Chapter02/02__04__anovamechanics.R: -------------------------------------------------------------------------------- 1 | data = read.csv("./anova__lot_type.csv") 2 | 3 | result = lm(Result ~ Lot,data=data) 4 | SS_LOT = sum((predict(result)-mean(data$Result))**2) 5 | 6 | result = lm(Result ~ Lot + Food.Type,data=data) 7 | SS_FOODTYPE = sum((predict(result)-mean(data$Result))**2) - SS_LOT 8 | 9 | SS_ERROR = sum((predict(result)-data$Result)**2) 10 | 11 | FF_LOT = (SS_LOT/1)/(SS_ERROR/56) 12 | FF_FOODTYPE = (SS_FOODTYPE/2)/(SS_ERROR/56) 13 | pval_LOT = 1-pf(FF_LOT,1,56) 14 | pval_FOODTYPE = 1-pf(FF_FOODTYPE,2,56) 15 | 16 | 17 | 18 | print(paste("SS(ERROR) = ",SS_ERROR)) 19 | print(paste("SS(LOT) =",SS_LOT,"/F(LOT) = ",FF_LOT,"pvalue = ",pval_LOT)) 20 | print(paste("SS(FOODTYPE) =",SS_FOODTYPE,"/F(FOODTYPE) = ",FF_FOODTYPE,"pvalue = ",pval_FOODTYPE)) 21 | 22 | 23 | anova(result) 24 | -------------------------------------------------------------------------------- /Chapter01/15/traminer__ex.R: -------------------------------------------------------------------------------- 1 | 2 | library(TraMineR) 3 | 4 | datax <- read.csv("./data__model.csv",stringsAsFactors = FALSE) 5 | mvad.labels <- c("CLOSED","L1", "L2", "L3") 6 | mvad.scode <- c("CLD","L1", "L2", "L3") 7 | mvad.seq <- seqdef(datax, 3:22, states = mvad.scode,labels = mvad.labels) 8 | group__ <- paste0(datax$Sex,"-",datax$Age) 9 | 10 | 11 | seqHtplot(mvad.seq,group=group__, title = "Entropy index") 12 | 13 | 14 | dist.om1 <- seqdist(mvad.seq, method = "OM", indel = 1, sm = "TRATE") 15 | library(cluster) 16 | clusterward1 <- agnes(dist.om1, diss = TRUE, method = "ward") 17 | plot(clusterward1, which.plot = 2) 18 | cl1.4 <- cutree(clusterward1, k = 4) 19 | cl1.4fac <- factor(cl1.4, labels = paste("Type", 1:4)) 20 | 21 | seqrplot(mvad.seq, diss = dist.om1, group = cl1.4fac,border = NA) 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Chapter01/07/tables.R: -------------------------------------------------------------------------------- 1 | library(expss) 2 | library(formattable) 3 | 4 | data = read.csv("/Users/admin/Documents/R_book/chapter01/07/person_salary.csv",stringsAsFactors = FALSE) 5 | Green = "#71CA97" 6 | Green2 = "#DeF7E9" 7 | 8 | table__out = data.frame(table(data$Career,data$Age)) 9 | colnames(table__out) = c("Career","Age","Freq") 10 | formattable(table__out,align =c("c","c","c"), list("Freq"= color_tile(Green, Green2))) 11 | 12 | formattable(data,align =c("c","c","c","c"), list( 13 | "Person" = formatter("span", style = ~ style(color = "grey",font.weight = "bold")), 14 | "Salary"= color_tile(Green, Green2), 15 | "Contacted" = formatter("span", 16 | style = x ~ style(color = ifelse(x, "green", "red")), 17 | x ~ icontext(ifelse(x, "ok", "remove"), ifelse(x, "Yes", "No"))))) 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter08/08__05__robustlmm.R: -------------------------------------------------------------------------------- 1 | library(lme4) 2 | library(robustlmm) 3 | set.seed(10) 4 | 5 | X = 7*runif(1000) 6 | G = c() 7 | 8 | for (x in 1:100){ 9 | G = c(G,rep(x,10)) 10 | } 11 | 12 | pre____frame = cbind(X=X,G=G,NOISE = rnorm(1000,0,0.03)) 13 | shocks_frame = cbind(G = 1:100,shocks = rnorm(100,0,1)) 14 | merged_frame = merge(pre____frame,shocks_frame,by="G") 15 | merged_frame$Y = 10 + merged_frame$shocks + merged_frame$NOISE 16 | XYG = merged_frame[,c(1,2,5)] 17 | 18 | 19 | lmer(data=XYG, Y ~ 1 + (1|G)) 20 | rlmer(data=XYG, Y ~ 1 + (1|G)) 21 | 22 | positions = sample(1:1000, 50, replace=T) 23 | XYG[positions,"Y"] = rnorm(1,50,10) 24 | 25 | 26 | 27 | 28 | lmer(data=XYG, Y ~ 1 + (1|G)) 29 | rlmer(data=XYG, Y ~ 1 + (1|G)) 30 | 31 | model = rlmer(data=XYG, Y ~ 1 + (1|G)) 32 | plot(model) 33 | 34 | -------------------------------------------------------------------------------- /Chapter01/04/random_numbers.R: -------------------------------------------------------------------------------- 1 | library(ggplot2) 2 | library(tidyr) 3 | 4 | rnorm_result = data.frame(rnorm = rnorm(10000,0,1)) 5 | inverse_way = data.frame(inverse = qnorm(runif(10000),0,1)) 6 | 7 | total_table = cbind(rnorm_result,inverse_way) 8 | transp_table = gather(total_table) 9 | colnames(transp_table) = c("method","value") 10 | 11 | ggplot(transp_table, aes(x=value,fill=method)) + geom_density(alpha=0.25) 12 | 13 | 14 | 15 | 16 | 17 | 18 | rpois_result = data.frame(rpois = rpois(10000,5)) 19 | inverse_way = data.frame(inverse = qpois(runif(10000),5)) 20 | total_table = cbind(rpois_result,inverse_way) 21 | transp_table = gather(total_table) 22 | colnames(transp_table) = c("method","value") 23 | 24 | 25 | ggplot(transp_table, aes(x=value,fill=method)) + geom_histogram(alpha=0.8,binwidth = 1) 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Chapter01/09/diagrammer.R: -------------------------------------------------------------------------------- 1 | install.packages('DiagrammeR') 2 | 3 | library('DiagrammeR') 4 | 5 | grViz(" 6 | digraph dot { 7 | 8 | graph [layout = dot] 9 | 10 | node [shape = circle, 11 | style = filled, 12 | color = grey, 13 | label = ''] 14 | 15 | node [fillcolor = white,fixedsize = true, width = 2] 16 | a[label = 'Company A'] 17 | 18 | node [fillcolor = white] 19 | b[label = 'IT+RD Consulting'] c[label = 'General Consulting'] d[label = 'Other Activities'] 20 | 21 | node [fillcolor = white] 22 | 23 | edge [color = grey] 24 | a -> {b c d} 25 | b -> {e[label = '254';color=blue] f[label = '83%';color=green]} 26 | c -> {k[label = '132';color=blue] l[label = '61%';color=green]} 27 | d -> {q[label = '192';color=blue] r[label = '47%';color=green]} 28 | }") 29 | -------------------------------------------------------------------------------- /Chapter01/10/Rcpp.R: -------------------------------------------------------------------------------- 1 | library(Rcpp) 2 | sourceCpp("./rcpp_example.cpp") 3 | 4 | Rfunc <- function(rand__vector,rand_matrix){ 5 | mcounter = 0 6 | for (q in 1:length(rand__vector)){ 7 | for (x in 1:dim(rand_matrix)[1]){ 8 | for (y in 1:dim(rand_matrix)[2]){ 9 | v1 = rand_matrix[x,y]; 10 | v2 = rand__vector[q]; 11 | if ( v1 < v2){ 12 | mcounter = mcounter+1 13 | } 14 | } 15 | } 16 | } 17 | return (mcounter) 18 | } 19 | 20 | 21 | some__matrix = replicate(500, rnorm(20)) 22 | some__vector = rnorm(100) 23 | 24 | 25 | start_time <- Sys.time() 26 | bring_element(some__vector,some__matrix) 27 | end_time <- Sys.time() 28 | print(end_time - start_time) 29 | 30 | 31 | start_time <- Sys.time() 32 | Rfunc(some__vector,some__matrix) 33 | end_time <- Sys.time() 34 | print(end_time - start_time) 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Chapter05/05__04__loess.R: -------------------------------------------------------------------------------- 1 | 2 | data = read.csv("./price__sales.csv") 3 | model_loess1 = loess(data$sales~data$price, span = 2/3, degree = 2, family = c("gaussian")) 4 | model_loess2 = loess(data$sales~data$price, span = 0.1, degree = 2, family = c("gaussian")) 5 | 6 | 7 | 8 | loess1_wrapper <- function(x){ 9 | return (predict(model_loess1,x)) 10 | } 11 | 12 | loess2_wrapper <- function(x){ 13 | return (predict(model_loess2,x)) 14 | } 15 | 16 | loess1_wrapper(5) - loess1_wrapper(10) 17 | loess1_wrapper(10) - loess1_wrapper(15) 18 | 19 | 20 | plot(data$price,data$sales) 21 | curve(loess1_wrapper,add=TRUE,col="red",lwd=3) 22 | curve(loess2_wrapper,add=TRUE,col="blue",lwd=3) 23 | legend(17.7, 0.5, legend=c("span=0.75", "span=0.1"),col=c("red", "blue"), lty=1:1, cex=0.8) 24 | 25 | 26 | 27 | 28 | 29 | ggplot(data, aes(x=price, y=sales)) + geom_point(size=2, shape=1) + geom_smooth(se = TRUE, method = "loess") 30 | -------------------------------------------------------------------------------- /Chapter05/05__07__semiparametric.R: -------------------------------------------------------------------------------- 1 | library(SemiPar) 2 | set.seed(10) 3 | 4 | x1 = rnorm(100,20,6) 5 | x2 = runif(100,1,8) 6 | y = 10 + x1 + x2 + rnorm(100,0,5) 7 | data_sim = data.frame(x1=x1,x2=x2,y=y) 8 | par(mfrow=c(1,2)) 9 | 10 | attach(data_sim) 11 | fit <- spm(y ~ x1 +x2) 12 | summary(fit) 13 | plot(fit) 14 | 15 | 16 | 17 | 18 | x1 = rnorm(100,20,6) 19 | x2 = runif(100,1,8) 20 | y = 10 + x1 + 150*exp(-x2) + rnorm(100,0,5) 21 | data_sim = data.frame(x1=x1,x2=x2,y=y) 22 | fit <- spm(data_sim$y ~ f(data_sim$x1)+f(data_sim$x2)) 23 | summary(fit) 24 | plot(fit) 25 | 26 | 27 | 28 | 29 | 30 | fit <- spm(data_sim$y ~ data_sim$x1 + f(data_sim$x2)) 31 | summary(fit) 32 | 33 | 34 | 35 | 36 | fit <- spm(data_sim$y ~ data_sim$x1 + f(data_sim$x2,spar=20)) 37 | summary(fit) 38 | plot(fit) 39 | 40 | fit <- spm(data_sim$y ~ data_sim$x1 + f(data_sim$x2,df=6)) 41 | summary(fit) 42 | plot(fit) -------------------------------------------------------------------------------- /Chapter03/03__03_correlations.R: -------------------------------------------------------------------------------- 1 | data = read.csv("./shoes_sales.csv") 2 | 3 | library(caret) 4 | library(car) 5 | 6 | X = data[-1] 7 | 8 | findLinearCombos(X) 9 | 10 | 11 | 12 | 13 | X = as.matrix(X) 14 | 15 | det(t(X) %*% X) 16 | 17 | 18 | 19 | 20 | model = lm(data=data,Sales ~ women_apparel_price + male_apparel_price+ shoes_female_price + shoes_male_price +shoes_kids_prices+shoes_male_price_b+prices_shoes) 21 | summary(model) 22 | 23 | det(t(X[,c(-6,-7)]) %*% X[,c(-6,-7)]) 24 | 25 | 26 | fixedmodel = lm(data=data,Sales ~ women_apparel_price + male_apparel_price+ shoes_female_price + shoes_male_price +shoes_kids_prices) 27 | summary(fixedmodel) 28 | vif(fixedmodel) 29 | 30 | 31 | 32 | 33 | aggregated_apparel = data$women_apparel_price + data$male_apparel_price 34 | aggregated_femalekids = data$shoes_female_price + data$shoes_kids_prices 35 | finalmodel = lm(data=data,Sales ~ aggregated_apparel + shoes_male_price + aggregated_femalekids) 36 | summary(finalmodel) 37 | vif(finalmodel) 38 | -------------------------------------------------------------------------------- /Chapter10/10__2__bayesiannetwork.R: -------------------------------------------------------------------------------- 1 | library(bnlearn) 2 | library(ggplot2) 3 | 4 | data = read.csv("./employee_data.csv")[-1] 5 | dag = model2network("[Area][travel_time|Area][performance|travel_time:diet_quality][Recently_had_child][Sleep_quality|Recently_had_child:Area][diet_quality|Sleep_quality]") 6 | 7 | 8 | ci.test("performance", "Sleep_quality", c("diet_quality", "travel_time"), test = "mi", data = data) 9 | ci.test("diet_quality", "Area", c("Sleep_quality"), test = "mi", data = data) 10 | 11 | ci.test("travel_time", "Area", test = "mi", data = data) 12 | arc_strengths = arc.strength(dag, data = data, criterion = "mi") 13 | 14 | 15 | ggplot(data=arc_strengths, aes(x=paste0(arc_strengths$from,"->",arc_strengths$to), y=strength)) + 16 | geom_bar(stat="identity") + theme(axis.text.x = element_text(angle = 90, hjust = 1),axis.title.x=element_blank()) 17 | 18 | 19 | dsep(dag,"travel_time","Recently_had_child") 20 | dsep(dag,"travel_time","Sleep_quality") 21 | dsep(dag,"travel_time","Sleep_quality","Area") 22 | -------------------------------------------------------------------------------- /Chapter03/03__01__ols_matrix.R: -------------------------------------------------------------------------------- 1 | set.seed(10) 2 | 3 | sim_data1 = runif(1000)*100 4 | 5 | sim_data2 = sim_data1 + runif(1000)*100 6 | 7 | depvar = 40 + sim_data2 + sim_data1 + rnorm(1000,0,20) 8 | 9 | model_data = data.frame(cbind(depvar,sim_data1,sim_data2)) 10 | 11 | summary(lm(data=model_data,depvar ~ sim_data1 + sim_data2)) 12 | 13 | 14 | 15 | 16 | X = as.matrix(model_data[c("sim_data1","sim_data2")]) 17 | X = cbind(rep(1,1000),X) 18 | colnames(X)[1] = "intercept" 19 | Y = as.matrix(model_data["depvar"]) 20 | 21 | 22 | 23 | beta = solve(t(X) %*% X) %*% (t(X) %*% Y) 24 | beta 25 | predictions = X %*% beta 26 | head(predictions) 27 | 28 | 29 | 30 | residuals = predictions - Y 31 | 32 | sd_c = var(residuals)[1] 33 | 34 | cov_matrix = solve(t(X) %*% X ) * sd_c 35 | 36 | diag(cov_matrix) = sqrt(diag(cov_matrix)) 37 | 38 | print(paste("Std Error:",diag(cov_matrix))) 39 | Y = as.matrix(model_data["depvar"]) -------------------------------------------------------------------------------- /Chapter04/04__08_glm.R: -------------------------------------------------------------------------------- 1 | library(rstan) 2 | data = read.csv("./clients.csv") 3 | 4 | model =" 5 | 6 | data { 7 | int y[40]; 8 | real x[40,3]; 9 | real ns[2,3]; 10 | } 11 | 12 | parameters { 13 | real beta[3]; 14 | real alpha; 15 | } 16 | 17 | model { 18 | beta ~ gamma(5,10); 19 | alpha ~ normal(0,20); 20 | for (n in 1:40) 21 | y[n] ~ bernoulli_logit(alpha + beta[1]*x[n,1] + beta[2]*x[n,2] + beta[3]*x[n,3]); 22 | } 23 | 24 | generated quantities { 25 | 26 | vector[2] y_preds; 27 | for (n in 1:2) { 28 | y_preds[n] = bernoulli_logit_rng(alpha + beta[1]*ns[n,1] + beta[2]*ns[n,2] + beta[3]*ns[n,3]); 29 | } 30 | } 31 | " 32 | 33 | topredict = rbind(c(20,0,1),c(60,5,8)) 34 | xy = list(y=data[,1],x=data[,2:4],ns=topredict) 35 | fit = stan(model_code = model, data = xy, warmup = 500, iter = 5000, chains = 4, cores = 2, thin = 1,verbose=FALSE) 36 | 37 | rstan::traceplot(fit,pars=c("beta[1]","beta[2]","beta[3]","alpha")) 38 | summary(fit) 39 | stan_dens(fit) 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Chapter10/10__6__financialdata.R: -------------------------------------------------------------------------------- 1 | library('depmixS4') 2 | 3 | datas = read.csv("./hist_PAM20190304.csv")[5] 4 | returns = diff(datas$cierre)/datas$cierre[-length(datas$cierre)] 5 | plot(returns,type="l") 6 | returns = data.frame(returns =returns) 7 | hist(returns$returns,main="Histogram of returns") 8 | 9 | 10 | 11 | 12 | 13 | 14 | hmm <- depmix(returns ~ 1, family = gaussian(), nstates = 2, data=data.frame(returns=returns)) 15 | hmmfit <- fit(hmm, verbose = FALSE) 16 | 17 | 18 | 19 | 20 | 21 | 22 | post_probs <- posterior(hmmfit) 23 | layout(1:4) 24 | plot(datas$cierre,type="l") 25 | plot(returns$returns,type="l") 26 | plot(post_probs$state, type='s', main='True Regimes', xlab='', ylab='Regime') 27 | matplot(post_probs[,-1], type='l', main='Regime Posterior Probabilities', ylab='Probability') 28 | legend(x='topright', c('Flat-Bear','Bull'), fill=1:3, bty='n') 29 | 30 | 31 | 32 | 33 | 34 | hmm <- depmix(returns ~ 1, family = gaussian(), nstates = 3, data=data.frame(returns=returns)) -------------------------------------------------------------------------------- /Chapter07/07__01__arima.R: -------------------------------------------------------------------------------- 1 | set.seed(95) 2 | build_series = function(coef){ 3 | start_value = 90 4 | values = c(start_value) 5 | previous_value = values 6 | 7 | for (x in 1:200){ 8 | current_value = coef*previous_value + rnorm(1,0,10) 9 | values = c(values,current_value) 10 | previous_value = current_value 11 | } 12 | return (values) 13 | } 14 | 15 | ss1 = build_series(1) 16 | ss2 = build_series(1) 17 | ss3 = build_series(1) 18 | 19 | 20 | plot(ss1,type="l",ylim=c(-200,300)) 21 | lines(ss2,col="red") 22 | lines(ss3,col="green") 23 | 24 | 25 | 26 | s1 = build_series(0.2) 27 | s2 = build_series(0.2) 28 | s3 = build_series(0.2) 29 | 30 | plot(s1,type="l",ylim=c(-50,50)) 31 | lines(s2,col="red") 32 | lines(s3,col="green") 33 | 34 | 35 | 36 | acf(s1) 37 | arima(s1,order=c(1,0,0),include.mean = FALSE ) 38 | 39 | 40 | 41 | acf(ss1) 42 | arima(ss1,order=c(1,0,0),include.mean = FALSE ) 43 | 44 | 45 | s1_d = diff(s1) 46 | plot(s1_d,type="l") 47 | acf(s1_d) 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Chapter04/04__05__stanmodel.R: -------------------------------------------------------------------------------- 1 | library(rstan) 2 | 3 | library(coda) 4 | 5 | library(DrBats) 6 | 7 | 8 | 9 | 10 | data = read.csv("./house_prices.csv") 11 | 12 | model =" 13 | data { 14 | real y[481]; 15 | real x[481,6]; 16 | } 17 | 18 | parameters { 19 | real beta[6]; 20 | real sigma; 21 | real alpha; 22 | } 23 | 24 | model { 25 | beta ~ normal(5,20); 26 | for (n in 1:125) 27 | y[n] ~ normal(alpha + beta[1]*x[n,1] + beta[2]*x[n,2] + beta[3]*x[n,3] + beta[4]*x[n,4] + beta[5]*x[n,5] + beta[6]*x[n,6], sigma); 28 | } 29 | " 30 | 31 | xy = list(y=data[,1],x=data[,2:7]) 32 | fit = stan(model_code = model, data = xy, warmup = 500, iter = 5000, chains = 4, cores = 2, thin = 1,verbose=FALSE) 33 | 34 | 35 | 36 | coda__obj = coda.obj(fit) 37 | heidel.diag(coda__obj) 38 | 39 | HPDinterval(coda__obj) 40 | 41 | raftery.diag(coda__obj) 42 | 43 | effectiveSize(coda__obj) 44 | 45 | cumuplot(coda__obj) 46 | 47 | gelman.plot(coda__obj) 48 | 49 | geweke.plot(coda__obj) 50 | 51 | crosscorr.plot(coda__obj) 52 | 53 | autocorr.plot(coda__obj) 54 | -------------------------------------------------------------------------------- /Chapter04/04__07_prediction.R: -------------------------------------------------------------------------------- 1 | library(rstan) 2 | 3 | data = read.csv("./house_prices.csv") 4 | 5 | 6 | 7 | 8 | model =" 9 | 10 | data { 11 | 12 | real y[481]; 13 | 14 | real x[481,6]; 15 | 16 | real ns[2,6]; 17 | 18 | } 19 | 20 | parameters { 21 | 22 | real beta[6]; 23 | 24 | real sigma; 25 | 26 | real alpha; 27 | 28 | } 29 | 30 | model { 31 | 32 | beta ~ normal(5,10); 33 | 34 | for (n in 1:481) 35 | 36 | y[n] ~ normal(alpha + beta[1]*x[n,1] + beta[2]*x[n,2] + beta[3]*x[n,3] + beta[4]*x[n,4] + beta[5]*x[n,5] + 37 | 38 | beta[6]*x[n,6], sigma); 39 | 40 | } 41 | 42 | generated quantities { 43 | 44 | vector[2] y_preds; 45 | for (n in 1:2) { 46 | y_preds[n] = normal_rng(alpha + beta[1]*ns[n,1] + beta[2]*ns[n,2] + beta[3]*ns[n,3] + beta[4]*ns[n,4] + beta[5]*ns[n,5] + beta[6]*ns[n,6], sigma); 47 | } 48 | } 49 | 50 | " 51 | topredict = rbind(c(10,3,3,3,3,20),c(7,3,3,3,3,10)) 52 | xy = list(y=data[,1],x=data[,2:7],ns=topredict) 53 | fit = stan(model_code = model, data = xy, warmup = 500, iter = 5000, chains = 4, cores = 2, thin = 1,verbose=FALSE) 54 | -------------------------------------------------------------------------------- /Chapter09/09__03__featureselection.R: -------------------------------------------------------------------------------- 1 | library(MASS) 2 | library(caret) 3 | library(randomForest) 4 | 5 | control <- trainControl(method="repeatedcv", number=4, repeats=1) 6 | tunegrid <- expand.grid(.mtry=c(2,3,4,5,6,7,8)) 7 | data <- Boston 8 | result = train(medv~., data=data, method="rf", metric="RMSE", tuneGrid=tunegrid, 9 | trControl=control,importance=TRUE)$finalModel 10 | 11 | result 12 | 13 | 14 | 15 | 16 | gbmImp <- varImp(result) 17 | importance(result) 18 | varImpPlot(result) 19 | 20 | 21 | 22 | tunegrid <- expand.grid(.mtry=c(1)) 23 | result = train(medv~., data=data[,c("medv","rm","lstat")], method="rf", metric="RMSE", 24 | tuneGrid=tunegrid, trControl=control)$finalModel 25 | result 26 | 27 | 28 | 29 | 30 | control <- rfeControl(functions=rfFuncs, method="cv", number=10) 31 | results <- rfe(as.matrix(data[-14]),as.matrix(data[14]), sizes=c(1:5), rfeControl=control) 32 | print(results) 33 | predictors(results) 34 | plot(results, type=c("g", "o")) 35 | -------------------------------------------------------------------------------- /Chapter08/company_areas.csv: -------------------------------------------------------------------------------- 1 | Group,Person,Rating 2 | Marketing,A,14.90791662 3 | Marketing,B,11.77541242 4 | Marketing,C,10.1041425 5 | Marketing,D,23.38556471 6 | Marketing,A,16.36069068 7 | Marketing,B,14.17309587 8 | Marketing,C,11.18180926 9 | Marketing,D,20.66411022 10 | Marketing,A,17.50647941 11 | Marketing,B,11.47192872 12 | Marketing,C,13.79551121 13 | Marketing,D,16.9890131 14 | Marketing,A,16.13029924 15 | Marketing,B,11.83542177 16 | Marketing,C,16.52422546 17 | Marketing,D,16.2604708 18 | Marketing,A,13.72673998 19 | Marketing,B,17.17348104 20 | Marketing,C,13.39423101 21 | Marketing,D,20.84087566 22 | Sales,A,34.78458355 23 | Sales,B,28.92265828 24 | Sales,C,31.68091908 25 | Sales,D,39.41863161 26 | Sales,A,34.73167592 27 | Sales,B,34.18176547 28 | Sales,C,30.49097931 29 | Sales,D,39.06621649 30 | Sales,A,40.20953886 31 | Sales,B,31.71353744 32 | Sales,C,37.41525312 33 | Sales,D,37.8253632 34 | Sales,A,33.82469214 35 | Sales,B,34.46000778 36 | Sales,C,32.30552666 37 | Sales,D,35.57531988 38 | Sales,A,38.36228252 39 | Sales,B,26.5410002 40 | Sales,C,30.86774296 41 | Sales,D,40.25041675 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Chapter01/13/R_classes_script_.R: -------------------------------------------------------------------------------- 1 | 2 | library(R6) 3 | 4 | 5 | customers = read.csv("./Customers_data.csv") 6 | 7 | Customer = R6Class(public=list(Customer_id = NULL,Name = NULL,City = NULL, 8 | initialize = function(customer_id,name,city,Missing_product,Missing_since){ 9 | self$Customer_id <- customer_id 10 | self$Name <- name 11 | self$City <- city 12 | }, 13 | is_city_in_america = function(){ 14 | return (upper_(self$City) %in% c("NEW YORK","LONDON","MIAMI","BARCELONA")) 15 | }, 16 | full_print = function(){ 17 | print("------------------------------------") 18 | print(paste("Customer name ->",self$Name)) 19 | print(paste("Customer city ->",self$City)) 20 | print("------------------------------------") 21 | } 22 | ),private=list( 23 | upper_ = function(x){ 24 | return (toupper(x)) 25 | } 26 | )) 27 | 28 | list_of_customers = list() 29 | for (row in 1:nrow(customers)){ 30 | row_read = customers[row,] 31 | customer = Customer$new(row_read$Customer_id,row_read$Name,row_read$City) 32 | list_of_customers[[row]] <- (customer) 33 | } 34 | 35 | list_of_customers[[1]]$full_print() 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Chapter06/06__03__glm.R: -------------------------------------------------------------------------------- 1 | library(robust) 2 | set.seed(1000) 3 | x1 = rnorm(1000) 4 | x2 = rnorm(1000) 5 | link_val = 2 + 2*x1 + 5*x2 6 | pr = 1/(1+exp(-link_val)) 7 | y = rbinom(1000,1,pr) 8 | df = data.frame(y=y,x1=x1,x2=x2) 9 | glm( y~x1+x2,data=df,family="binomial") 10 | robust::glmRob(y~x1+x2,data=df,family="binomial") 11 | 12 | 13 | 14 | 15 | 16 | 17 | x1 = rnorm(1000) 18 | x2 = rnorm(1000) 19 | link_val = 2 + 2*x1 + 5*x2 20 | pr = 1/(1+exp(-link_val)) 21 | y = rbinom(1000,1,pr) 22 | x1[1:50] = 10*rnorm(50) 23 | df = data.frame(y=y,x1=x1,x2=x2) 24 | glm( y~x1+x2,data=df,family="binomial") 25 | robust::glmRob(y~x1+x2,method="cubif",data=df,family="binomial") 26 | 27 | 28 | 29 | 30 | 31 | x1 = rnorm(1000) 32 | x2 = rnorm(1000) 33 | link_val = 2 + 2*x1 + 5*x2 34 | pr = 1/(1+exp(-link_val)) 35 | y = rbinom(1000,1,pr) 36 | x1[1:100] = 10*rnorm(100) 37 | df = data.frame(y=y,x1=x1,x2=x2) 38 | glm( y~x1+x2,data=df,family="binomial") 39 | robust::glmRob(y~x1+x2,mthod="cubif",data=df,family="binomial") -------------------------------------------------------------------------------- /Chapter08/company_areas2.csv: -------------------------------------------------------------------------------- 1 | Group,Person,Rating 2 | Marketing,A,14.90791662 3 | Marketing,B,11.77541242 4 | Marketing,C,10.1041425 5 | Marketing,D,23.38556471 6 | Marketing,A,16.36069068 7 | Marketing,B,14.17309587 8 | Marketing,C,11.18180926 9 | Marketing,D,20.66411022 10 | Marketing,A,17.50647941 11 | Marketing,B,11.47192872 12 | Marketing,C,13.79551121 13 | Marketing,D,16.9890131 14 | Marketing,A,16.13029924 15 | Marketing,B,11.83542177 16 | Marketing,C,16.52422546 17 | Marketing,D,16.2604708 18 | Marketing,A,13.72673998 19 | Marketing,B,17.17348104 20 | Marketing,C,13.39423101 21 | Marketing,D,20.84087566 22 | Sales,AA,34.78458355 23 | Sales,BB,28.92265828 24 | Sales,CC,31.68091908 25 | Sales,DD,39.41863161 26 | Sales,AA,34.73167592 27 | Sales,BB,34.18176547 28 | Sales,CC,30.49097931 29 | Sales,DD,39.06621649 30 | Sales,AA,40.20953886 31 | Sales,BB,31.71353744 32 | Sales,CC,37.41525312 33 | Sales,DD,37.8253632 34 | Sales,AA,33.82469214 35 | Sales,BB,34.46000778 36 | Sales,CC,32.30552666 37 | Sales,DD,35.57531988 38 | Sales,AA,38.36228252 39 | Sales,BB,26.5410002 40 | Sales,CC,30.86774296 41 | Sales,DD,40.25041675 42 | -------------------------------------------------------------------------------- /Chapter10/10__5__subwaymodel.R: -------------------------------------------------------------------------------- 1 | data = read.csv("./subway_data.csv") 2 | 3 | data$weather_sunny = 0 4 | data$weather_sunny[data$weather=="sunny"] = 1 5 | 6 | hmm <- depmix(data$people ~ 1 + data$weather_sunny, family = poisson(), nstates = 2, data=data,respstart=c(10,10,10,10)) 7 | hmmfit <- fit(hmm, verbose = TRUE) 8 | 9 | post_probs <- posterior(hmmfit) 10 | layout(1:2) 11 | plot(data$people,type="l") 12 | data$state_pred = post_probs$state 13 | matplot(post_probs[,-1], type='l', main='Regime Posterior Probabilities', ylab='Probability') 14 | legend(x='topright', c('Closed','Open'), fill=1:3, bty='n') 15 | 16 | table(data$state,data$state_pred) 17 | 18 | 19 | 20 | 21 | data = read.csv("./subway_data_extended.csv") 22 | 23 | data$weather_sunny = 0 24 | data$weather_sunny[data$weather=="sunny"] = 1 25 | 26 | hmm <- depmix(data = data, people ~ 1 + weather_sunny,transition=~1 + machinery_road, family = poisson(), nstates = 2, respstart=c(10,10,10,10) ) 27 | hmmfit <- fit(hmm, verbose = TRUE) 28 | post_probs <- posterior(hmmfit) 29 | data$state_pred = post_probs$state 30 | 31 | table(data$state,data$state_pred) 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Chapter10/10__3__hybridnet.R: -------------------------------------------------------------------------------- 1 | library(bnlearn) 2 | 3 | data = read.csv("https://archive.ics.uci.edu/ml/machine-learning-databases/abalone/abalone.data") 4 | colnames(data) = c("sex","length","diameter","height","whole_weight","shucked_weight","viscera_weight","shell_weight","rings") 5 | data$rings = log(data$rings) 6 | 7 | dag = model2network("[sex][length|sex][diameter|sex][height|sex][whole_weight|length:diameter:height][shucked_weight|length:diameter:height][viscera_weight|length:diameter:height][shell_weight|length:diameter:height][rings|whole_weight:shucked_weight:viscera_weight:shell_weight]") 8 | parm = list(nodes = nodes(dag), arcs = arcs(dag),col = "black", textCol = "black") 9 | graphviz.plot(dag, highlight = parm) 10 | 11 | 12 | fitted = bn.fit(dag, data) 13 | 14 | cpquery(fitted, event = (sex == "M"),evidence = list(diameter=0.65,whole_weight=.8), method = "lw") 15 | cpquery(fitted, event = (sex == "M"),evidence = list(diameter=0.15,whole_weight=.8), method = "lw") 16 | 17 | cpdist(fitted, nodes = c("height"),evidence = (viscera_weight > 0.4)) 18 | 19 | head(predict(fitted,"rings",data)) 20 | head(predict(fitted,"whole_weight",data)) 21 | -------------------------------------------------------------------------------- /Chapter02/02__08__repeatedmeasures.R: -------------------------------------------------------------------------------- 1 | library(ggplot2) 2 | library(nlme) 3 | library(lmerTest) 4 | library(lsmeans) 5 | data_company = read.csv("./employee_time_bonus.csv",stringsAsFactors = TRUE) 6 | 7 | 8 | 9 | ggplot(data_company,aes(x=Time,y=Performance)) + geom_line() + 10 | geom_point(data=data_company,aes(x=Time,y=Performance)) + 11 | facet_wrap(~Employee,nrow=3) 12 | 13 | 14 | fit <- lme(Performance ~ x_Bonus + x_Sector + Time + Time:x_Bonus , random = list( ~1 |Employee) , correlation = corAR1(form= ~Time|Employee), data = data_company) 15 | summary(fit) 16 | 17 | 18 | anova(fit) 19 | 20 | 21 | 22 | fit <- lme(Performance ~ x_Bonus + x_Sector + Time + Time:x_Bonus , random = list( ~1 |Employee) , data = data_company) 23 | summary(fit) 24 | 25 | 26 | 27 | 28 | 29 | fit <- lme(Performance ~ x_Bonus + x_Sector + Time , random = list( ~1 |Employee) , correlation = corAR1(form= ~Time|Employee), data = data_company) 30 | print(lsmeans(fit,pairwise ~ x_Bonus)) 31 | 32 | 33 | 34 | fit <- lme(Performance ~ x_Bonus + x_Sector + Time + Time:x_Bonus , random = list( ~1 + Time |Employee) , correlation = corAR1(form= ~Time|Employee), data = data_company) 35 | summary(fit) 36 | 37 | -------------------------------------------------------------------------------- /Chapter09/09__07__lassoridgeElasticnet.R: -------------------------------------------------------------------------------- 1 | set.seed(100) 2 | library(caret) 3 | summary(lm(data=longley,Employed~.)) 4 | 5 | 6 | rctrl1 <- trainControl(method = "cv",number=5) 7 | ols_ <- train(Employed~.,longley, 8 | method = "lm", 9 | trControl = rctrl1, 10 | tuneLength = 4,metric="RMSE", 11 | preProc = c("center", "scale")) 12 | 13 | lasso_ <- train(Employed~.,longley, 14 | method = "lasso", 15 | trControl = rctrl1, 16 | tuneLength = 10,metric="RMSE", 17 | preProc = c("center", "scale")) 18 | 19 | ridge_ <- train(Employed~.,longley, 20 | method = "ridge", 21 | trControl = rctrl1, 22 | tuneLength = 10,metric="RMSE", 23 | preProc = c("center", "scale")) 24 | 25 | elasticnet_ <- train(Employed~.,longley, 26 | method = "glmnet", 27 | trControl = rctrl1, 28 | tuneLength = 10,metric="RMSE", 29 | preProc = c("center", "scale")) 30 | 31 | varImp((elasticnet_)) -------------------------------------------------------------------------------- /Chapter10/10__1__introBNnetworks.R: -------------------------------------------------------------------------------- 1 | library(bnlearn) 2 | 3 | data = read.csv("./employee_data.csv")[-1] 4 | dag = model2network("[Area][travel_time|Area][performance|travel_time:diet_quality] 5 | [Recently_had_child][Sleep_quality|Recently_had_child:Area][diet_quality|Sleep_quality]") 6 | 7 | plot(dag) 8 | fitted = bn.fit(dag, data) 9 | 10 | 11 | cpquery(fitted, (performance=="HIGH"), (Area=="URBAN")) 12 | cpquery(fitted, (performance=="HIGH"), (Area=="SUBURBAN")) 13 | 14 | 15 | 16 | cpquery(fitted, (performance=="HIGH"), (travel_time=="HIGH" & Sleep_quality=="HIGH")) 17 | cpquery(fitted, (performance=="HIGH"), (travel_time=="HIGH" & Sleep_quality=="LOW")) 18 | 19 | 20 | 21 | cpquery(fitted, (Sleep_quality=="HIGH"), (performance=="HIGH")) 22 | cpquery(fitted, (Sleep_quality=="LOW") , (performance=="HIGH")) 23 | 24 | 25 | 26 | bn.fit.dotplot(fitted$diet_quality) 27 | dag2 = hc(data, maxp=2) 28 | plot(dag2) 29 | 30 | 31 | 32 | whitelist = data.frame(from=c("travel_time","diet_quality"),to=c("performance", "performance")) 33 | dag2 = hc(data,maxp=2,whitelist=whitelist) 34 | plot(dag2) 35 | fitted2 <- bn.fit(dag2,data) 36 | 37 | 38 | 39 | score(dag, data, type = "aic") 40 | score(dag2, data, type = "aic") -------------------------------------------------------------------------------- /Chapter09/lakers_.csv: -------------------------------------------------------------------------------- 1 | "","X","win","home","Kuzma","Ingram","Zubac","Ball","Hart","McGee","Caldwell.Pope","Chandler","Rondo","Beasley","James","Bullock" 2 | "1","clippers",0,1,1,1,1,1,1,0,0,0,0,0,0,0 3 | "2","kings",1,1,1,1,0,1,1,1,0,0,0,0,0,0 4 | "3","thunder",0,1,1,1,0,1,1,1,0,0,0,0,0,0 5 | "4","knicks",0,1,0,1,0,1,1,1,1,0,0,0,0,0 6 | "5","timberwolves",0,0,0,1,1,1,1,1,0,0,0,0,0,0 7 | "6","mavericks",1,0,1,1,0,1,1,1,0,0,0,0,0,0 8 | "7","pistons",1,1,1,1,0,1,1,1,0,0,0,0,0,0 9 | "8","jazz",0,0,1,1,0,1,1,1,0,0,0,0,0,0 10 | "9","cavaliers",0,1,1,1,0,1,1,1,0,0,0,0,0,0 11 | "10","bulls",1,1,1,1,0,1,0,0,1,1,0,0,0,0 12 | "11","thunder",1,0,1,1,0,1,0,0,1,1,0,0,0,0 13 | "12","rockets",0,0,1,1,0,1,0,0,1,1,0,0,0,0 14 | "13","warriors",0,1,1,1,0,0,1,0,1,1,0,0,0,0 15 | "14","timberwolves",0,1,1,1,1,0,0,0,1,0,1,0,0,0 16 | "15","suns",1,1,0,1,1,0,0,0,1,0,1,1,0,0 17 | "16","76s",0,1,0,1,1,0,0,0,1,0,1,1,0,0 18 | "17","clippers",1,0,1,1,1,0,0,0,0,0,1,0,1,0 19 | "18","warriors",0,0,1,1,1,0,0,0,1,0,1,0,0,0 20 | "19","pacers",0,0,1,1,1,0,0,0,0,0,1,0,1,0 21 | "20","celtics",1,0,1,1,0,0,0,1,0,0,1,0,1,0 22 | "21","76s",0,0,1,1,0,0,0,1,0,0,0,0,1,1 23 | "22","Hawks",0,0,1,1,0,0,0,1,0,0,0,0,1,1 24 | "23","Rockets",1,1,1,1,0,0,0,1,0,0,0,0,1,1 25 | "24","Pelicans",0,0,1,1,0,0,0,1,0,0,0,0,1,1 26 | -------------------------------------------------------------------------------- /Chapter10/employee_data.csv: -------------------------------------------------------------------------------- 1 | Personid,Area,Sleep_quality,Recently_had_child,diet_quality,travel_time,performance 2 | 1,URBAN,HIGH,NO,HIGH,LOW,HIGH 3 | 2,URBAN,HIGH,NO,HIGH,LOW,HIGH 4 | 3,URBAN,HIGH,NO,LOW,LOW,HIGH 5 | 4,URBAN,HIGH,NO,HIGH,LOW,HIGH 6 | 5,URBAN,HIGH,NO,HIGH,LOW,LOW 7 | 6,URBAN,HIGH,NO,HIGH,LOW,HIGH 8 | 7,URBAN,LOW,YES,LOW,LOW,HIGH 9 | 8,URBAN,HIGH,NO,HIGH,LOW,HIGH 10 | 9,URBAN,HIGH,YES,HIGH,LOW,HIGH 11 | 10,URBAN,HIGH,NO,HIGH,LOW,HIGH 12 | 11,URBAN,HIGH,NO,HIGH,LOW,LOW 13 | 12,URBAN,HIGH,NO,HIGH,LOW,HIGH 14 | 13,URBAN,HIGH,NO,LOW,LOW,HIGH 15 | 14,URBAN,LOW,YES,LOW,LOW,HIGH 16 | 15,URBAN,LOW,YES,HIGH,LOW,HIGH 17 | 16,URBAN,HIGH,NO,HIGH,LOW,LOW 18 | 17,SUBURBAN,LOW,NO,HIGH,HIGH,HIGH 19 | 18,SUBURBAN,HIGH,YES,LOW,LOW,HIGH 20 | 19,SUBURBAN,LOW,YES,LOW,HIGH,LOW 21 | 20,SUBURBAN,HIGH,YES,HIGH,HIGH,HIGH 22 | 21,SUBURBAN,HIGH,NO,HIGH,LOW,LOW 23 | 22,SUBURBAN,HIGH,NO,HIGH,LOW,HIGH 24 | 23,SUBURBAN,LOW,YES,LOW,HIGH,HIGH 25 | 24,SUBURBAN,LOW,NO,LOW,HIGH,LOW 26 | 25,SUBURBAN,LOW,YES,HIGH,LOW,HIGH 27 | 26,SUBURBAN,LOW,YES,HIGH,HIGH,HIGH 28 | 27,SUBURBAN,HIGH,YES,HIGH,HIGH,LOW 29 | 28,SUBURBAN,HIGH,NO,HIGH,LOW,HIGH 30 | 29,SUBURBAN,HIGH,NO,LOW,LOW,HIGH 31 | 30,SUBURBAN,LOW,YES,LOW,HIGH,LOW 32 | 31,SUBURBAN,LOW,YES,HIGH,LOW,LOW 33 | 32,SUBURBAN,HIGH,YES,HIGH,LOW,LOW -------------------------------------------------------------------------------- /Chapter01/13/R_classes_script_inheritance.R: -------------------------------------------------------------------------------- 1 | 2 | library(R6) 3 | 4 | 5 | customers = read.csv("./Customers_data_missing_products.csv") 6 | 7 | Customer_missprod = R6Class(inherit = Customer, 8 | public=list(Missing_prod = NULL,Missing_since = NULL, 9 | initialize = function(customer_id,name,city,Missing_product,Missing_since){ 10 | super$Customer_id <- customer_id 11 | super$Name <- name 12 | super$City <- city 13 | self$Missing_prod <- Missing_product 14 | self$Missing_since <- Missing_since 15 | }, 16 | full_print = function(){ 17 | print("------------------------------------") 18 | print(paste("Customer name ->",super$Name)) 19 | print(paste("Customer city ->",super$City)) 20 | print(paste("Missing prod ->",self$Missing_prod)) 21 | print(paste("Missing since ->",self$Missing_since)) 22 | print("------------------------------------") 23 | } 24 | ) 25 | ) 26 | 27 | list_of_customers = list() 28 | for (row in 1:nrow(customers)){ 29 | row_read = customers[row,] 30 | customer = Customer_missprod$new(row_read$Customer_id,row_read$Name,row_read$City,row_read$Missing_product,row_read$Missing_since) 31 | list_of_customers[[row]] <- (customer) 32 | } 33 | 34 | list_of_customers[[1]]$full_print() 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Chapter02/02__02__fisherbehrens.R: -------------------------------------------------------------------------------- 1 | calc_effective_alphas <- function(n,sd1,sd2,equalvar){ 2 | rejected <- 0 3 | for (x in 1:100000){ 4 | data1 <- rnorm(n,10,sd1) 5 | data2 <- rnorm(n,10,sd2) 6 | result <- t.test(data1,data2,var.equal=equalvar)$p.value 7 | if (result < 0.05){ 8 | rejected <- rejected + 1 9 | } 10 | } 11 | return (rejected/100000) 12 | } 13 | 14 | 15 | print(paste("n=10 / sd1=2 / sd2=5 / effective alpha=",calc_effective_alphas(10,2,5,TRUE))) 16 | print(paste("n=10 / sd1=2 / sd2=20/ effective alpha=",calc_effective_alphas(10,2,20,TRUE))) 17 | print(paste("n=10 / sd1=2 / sd2=5 / effective alpha=",calc_effective_alphas(10,2,5,FALSE))) 18 | print(paste("n=10 / sd1=2 / sd2=20/ effective alpha=",calc_effective_alphas(10,2,20,FALSE))) 19 | 20 | 21 | calc_power <- function(n,sd1,sd2,equalvar){ 22 | rejected <- 0 23 | for (x in 1:100000){ 24 | data1 <- rnorm(n,12,sd1) 25 | data2 <- rnorm(n,10,sd2) 26 | result <- t.test(data1,data2,var.equal=equalvar)$p.value 27 | if (result < 0.05){ 28 | rejected <- rejected + 1 29 | } 30 | } 31 | return (rejected/100000) 32 | } 33 | 34 | print(paste("n=10 / sd1=2 / sd2=20/ effective power=",calc_power(10,2,2,TRUE))) 35 | print(paste("n=10 / sd1=2 / sd2=20/ effective power=",calc_power(10,2,2,FALSE))) -------------------------------------------------------------------------------- /Chapter02/anova__lot_type.csv: -------------------------------------------------------------------------------- 1 | Result,Lot,Food.Type 2 | 49.55934636,1,A 3 | 35.75967805,1,A 4 | 31.36010593,1,A 5 | 49.89834259,1,A 6 | 38.56949313,1,A 7 | 19.16377281,1,A 8 | 55.65359499,1,A 9 | 45.18657617,1,A 10 | 53.30743327,1,A 11 | 36.40016612,1,A 12 | 32.88052194,1,B 13 | 30.33125907,1,B 14 | 11.24083573,1,B 15 | 24.60631987,1,B 16 | 15.36185583,1,B 17 | 33.46905855,1,B 18 | 39.19275041,1,B 19 | 28.37750078,1,B 20 | 20.82275876,1,B 21 | 28.72543397,1,B 22 | 11.82177847,1,C 23 | 21.09617185,1,C 24 | 13.5002457,1,C 25 | 28.57320364,1,C 26 | 37.56093526,1,C 27 | 24.49994981,1,C 28 | 31.91770098,1,C 29 | 28.03673628,1,C 30 | 16.4292588,1,C 31 | 9.287010677,1,C 32 | 53.10698284,2,A 33 | 56.92795803,2,A 34 | 34.2698803,2,A 35 | 54.32222137,2,A 36 | 51.11648643,2,A 37 | 40.71876911,2,A 38 | 38.94375629,2,A 39 | 56.99611425,2,A 40 | 47.39173079,2,A 41 | 40.66950047,2,A 42 | 32.53844294,2,B 43 | 30.02606541,2,B 44 | 34.46804653,2,B 45 | 25.51897506,2,B 46 | 41.87811757,2,B 47 | 45.15092534,2,B 48 | 26.33732066,2,B 49 | 24.76097348,2,B 50 | 47.65136133,2,B 51 | 23.88258625,2,B 52 | 44.8573412,2,C 53 | 42.15709126,2,C 54 | 11.10832354,2,C 55 | 32.49894095,2,C 56 | 34.20402521,2,C 57 | 10.53160234,2,C 58 | 23.70797049,2,C 59 | 28.61908178,2,C 60 | 22.76871504,2,C 61 | 30.98908103,2,C 62 | -------------------------------------------------------------------------------- /Chapter05/anova__lot_type.csv: -------------------------------------------------------------------------------- 1 | Result,Lot,Food.Type 2 | 49.55934636,1,A 3 | 35.75967805,1,A 4 | 31.36010593,1,A 5 | 49.89834259,1,A 6 | 38.56949313,1,A 7 | 19.16377281,1,A 8 | 55.65359499,1,A 9 | 45.18657617,1,A 10 | 53.30743327,1,A 11 | 36.40016612,1,A 12 | 32.88052194,1,B 13 | 30.33125907,1,B 14 | 11.24083573,1,B 15 | 24.60631987,1,B 16 | 15.36185583,1,B 17 | 33.46905855,1,B 18 | 39.19275041,1,B 19 | 28.37750078,1,B 20 | 20.82275876,1,B 21 | 28.72543397,1,B 22 | 11.82177847,1,C 23 | 21.09617185,1,C 24 | 13.5002457,1,C 25 | 28.57320364,1,C 26 | 37.56093526,1,C 27 | 24.49994981,1,C 28 | 31.91770098,1,C 29 | 28.03673628,1,C 30 | 16.4292588,1,C 31 | 9.287010677,1,C 32 | 53.10698284,2,A 33 | 56.92795803,2,A 34 | 34.2698803,2,A 35 | 54.32222137,2,A 36 | 51.11648643,2,A 37 | 40.71876911,2,A 38 | 38.94375629,2,A 39 | 56.99611425,2,A 40 | 47.39173079,2,A 41 | 40.66950047,2,A 42 | 32.53844294,2,B 43 | 30.02606541,2,B 44 | 34.46804653,2,B 45 | 25.51897506,2,B 46 | 41.87811757,2,B 47 | 45.15092534,2,B 48 | 26.33732066,2,B 49 | 24.76097348,2,B 50 | 47.65136133,2,B 51 | 23.88258625,2,B 52 | 44.8573412,2,C 53 | 42.15709126,2,C 54 | 11.10832354,2,C 55 | 32.49894095,2,C 56 | 34.20402521,2,C 57 | 10.53160234,2,C 58 | 23.70797049,2,C 59 | 28.61908178,2,C 60 | 22.76871504,2,C 61 | 30.98908103,2,C 62 | -------------------------------------------------------------------------------- /Chapter10/10__4__bnviewer.R: -------------------------------------------------------------------------------- 1 | library("bnviewer") 2 | library("bnlearn") 3 | 4 | 5 | data = read.csv("https://archive.ics.uci.edu/ml/machine-learning-databases/abalone/abalone.data") 6 | colnames(data) = c("sex","length","diameter","height","whole_weight","shucked_weight","viscera_weight","shell_weight","rings") 7 | data$rings = log(data$rings) 8 | 9 | dag = model2network("[sex][length|sex][diameter|sex][height|sex][whole_weight|length:diameter:height][shucked_weight|length:diameter:height][viscera_weight|length:diameter:height][shell_weight|length:diameter:height][rings|whole_weight:shucked_weight:viscera_weight:shell_weight]") 10 | parm = list(nodes = nodes(dag), arcs = arcs(dag),col = "black", textCol = "black") 11 | 12 | viewer(dag, 13 | bayesianNetwork.width = "100%", 14 | bayesianNetwork.height = "80vh", 15 | bayesianNetwork.layout = "layout_with_sugiyama", 16 | bayesianNetwork.title = "Abalone network", 17 | bayesianNetwork.subtitle = "User defined network", 18 | bayesianNetwork.footer = "Fig. 1 - live diagram" 19 | ) 20 | 21 | viewer(dag, 22 | bayesianNetwork.width = "100%", 23 | bayesianNetwork.height = "80vh", 24 | bayesianNetwork.layout = "layout_as_tree", 25 | bayesianNetwork.title = "Abalone network", 26 | bayesianNetwork.subtitle = "User defined network", 27 | bayesianNetwork.footer = "Fig. 1 - live diagram" 28 | ) -------------------------------------------------------------------------------- /Chapter04/04__02__stanmodel.R: -------------------------------------------------------------------------------- 1 | library(rstan) 2 | 3 | data = read.csv("./house_prices.csv") 4 | 5 | model =" 6 | 7 | data { 8 | real y[481]; 9 | real x[481,6]; 10 | } 11 | 12 | parameters { 13 | real beta[6]; 14 | real sigma; 15 | real alpha; 16 | } 17 | 18 | model { 19 | beta ~ gamma(3,1); 20 | for (n in 1:481) 21 | y[n] ~ normal(alpha + beta[1]*x[n,1] + beta[2]*x[n,2] + beta[3]*x[n,3] + beta[4]*x[n,4] + beta[5]*x[n,5] + 22 | beta[6]*x[n,6], sigma); 23 | } 24 | " 25 | 26 | 27 | lm(data=data,Property_price ~ size + number.bathrooms + number.bedrooms + number.entrances + size_balcony + size_entrance) 28 | 29 | 30 | xy = list(y=data[,1],x=data[,2:7]) 31 | fit = stan(model_code = model, data = xy, warmup = 500, iter = 5000, chains = 3, cores = 2, thin = 1,verbose=FALSE) 32 | 33 | traceplot(fit) 34 | summary(fit) 35 | stan_dens(fit) 36 | 37 | 38 | 39 | model =" 40 | 41 | data { 42 | real y[481]; 43 | real x[481,6]; 44 | } 45 | 46 | parameters { 47 | real beta[6]; 48 | real sigma; 49 | real alpha; 50 | } 51 | 52 | model { 53 | beta ~ normal(5,3); 54 | for (n in 1:481) 55 | y[n] ~ normal(alpha + beta[1]*x[n,1] + beta[2]*x[n,2] + beta[3]*x[n,3] + beta[4]*x[n,4] + beta[5]*x[n,5] + beta[6]*x[n,6], sigma); 56 | } 57 | " 58 | 59 | 60 | 61 | xy = list(y=data[,1],x=data[,2:7]) 62 | fit = stan(model_code = model, data = xy, warmup = 500, iter = 1000, chains = 4, cores = 2, thin = 1,verbose=FALSE) 63 | summary(fit) 64 | stan_dens(fit) 65 | 66 | -------------------------------------------------------------------------------- /Chapter08/08__07__GLMmixed.R: -------------------------------------------------------------------------------- 1 | library(lme4) 2 | 3 | library(emmeans) 4 | 5 | library(MASS) 6 | 7 | set.seed(10) 8 | 9 | 10 | 11 | fixed_std_model = glm(decrease ~ treatment,family=poisson(),data=OrchardSprays) 12 | 13 | summary(fixed_std_model ) 14 | 15 | emmeans(fixed_std_model, list(pairwise ~ treatment), adjust = "tukey",type="response") 16 | 17 | predict(fixed_std_model,data.frame(treatment="D"),type="response") 18 | 19 | plot(fixed_std_model) 20 | 21 | 22 | 23 | 24 | model_1 = lme4::glmer(decrease ~ treatment + (1|colpos) + (1|rowpos), family = poisson(), 25 | 26 | data = OrchardSprays) 27 | 28 | ss <- getME(model_1,c("theta","fixef")) 29 | 30 | model_2 <- update(model_1,start=ss) 31 | 32 | summary(model_2) 33 | 34 | 35 | 36 | ranef(model_2) 37 | 38 | fixef(model_2) 39 | 40 | VarCorr(model_2) 41 | 42 | 43 | 44 | 45 | plot(model_2, resid(., scaled=TRUE) ~ fitted(.) | colpos, abline = 0) 46 | 47 | plot(model_2, resid(., scaled=TRUE) ~ fitted(.) | rowpos, abline = 0) 48 | 49 | 50 | 51 | confint.merMod(model_2) 52 | 53 | emmeans(model_2, list(pairwise ~ treatment), adjust = "tukey",type="response") 54 | 55 | 56 | fixed_std_model = glm.nb(decrease ~ treatment,data=OrchardSprays) 57 | 58 | summary(fixed_std_model) 59 | 60 | model_2 = lme4::glmer.nb(decrease ~ treatment + (1|colpos) + (1|rowpos), data = OrchardSprays) 61 | 62 | ss2 <- getME(model_2,c("theta","fixef")) 63 | 64 | model_3 <- update(model_1,start=ss2) 65 | 66 | summary(model_3) -------------------------------------------------------------------------------- /Chapter03/03__08__ridge.R: -------------------------------------------------------------------------------- 1 | library(MASS) 2 | library(tidyr) 3 | library(ggplot2) 4 | library(glmnet) 5 | library(dplyr) 6 | set.seed(100) 7 | 8 | get_results<- function(lambda){ 9 | coeffs_total=data.frame(V1=numeric(),V2=numeric(),V3=numeric(),V4=numeric(),V5=numeric()) 10 | for (q in 1:100){ 11 | V1 =runif(1000)*100 12 | V2 =runif(1000)*10 + V1 13 | 14 | V3 =runif(1000)*100 15 | V4 =runif(1000)*10 + V3 16 | 17 | V5 =runif(1000)*100 18 | Residuals =runif(1000)*100 19 | Y = V1 + V2 + V3 + V4 + Residuals 20 | coefs_lm <-lm(Y ~ V1 + V2 + V3 + V4 + V5)$coefficients 21 | coefs_rd <-glmnet(cbind(V1 ,V2,V3,V4 ,V5),Y,lambda=lambda,alpha=0)$beta 22 | frame1 <-data.frame(V1=coefs_lm[2], V2=coefs_lm[3],V3=coefs_lm[4], V4=coefs_lm[5],V5=coefs_lm[6],method="lm") 23 | frame2 <-data.frame(V1=coefs_rd[1], V2=coefs_rd[2],V3=coefs_rd[3], V4=coefs_rd[4],V5=coefs_rd[5],method="ridge") 24 | coeffs_total<-rbind(coeffs_total,frame1,frame2) 25 | } 26 | transposed_data= gather(coeffs_total,"variable","value",1:5) 27 | print(transposed_data%>%group_by(variable,method) %>% summarise(median=median(value))) 28 | ggplot(transposed_data,aes(x=variable, y=value, fill=method)) +geom_boxplot() 29 | } 30 | 31 | get_results(0.1) 32 | 33 | 34 | V1 =runif(1000)*100 35 | V2 =runif(1000)*10 + V1 36 | V3 =runif(1000)*100 37 | V4 =runif(1000)*10 + V3 38 | V5 =runif(1000)*100 39 | Residuals =runif(1000)*100 40 | Y = V1 + V2 + V3 + V4 + Residuals 41 | cv.lasso=cv.glmnet(cbind(V1 ,V2,V3,V4 ,V5),Y,alpha=1) 42 | cv.lasso 43 | plot(cv.lasso) -------------------------------------------------------------------------------- /Chapter08/08__02__plots.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | library("lme4") 3 | library(ggplot2) 4 | library(sjPlot) 5 | library(sjmisc) 6 | 7 | data = read.csv("./sample_random_regression.csv") 8 | data$clientid = as.factor(data$clientid) 9 | 10 | 11 | 12 | 13 | ggplot(data=data, aes(x=salespeople_involved, y=deal_size, col=clientid))+ 14 | geom_point(size=.7, alpha=.8, position = "jitter")+ 15 | geom_smooth(method=lm,se=FALSE, size=0.6, alpha=.5)+theme_minimal()+labs(title="Linrved", subtitle="The lsses", col= "Yeance") 16 | 17 | 18 | 19 | model = lmer(data=data,deal_size ~ salespeople_involved + time_spent_deal + (1+time_spent_deal+salespeople_involved|clientid) ) 20 | 21 | 22 | 23 | 24 | ggplot(data) + 25 | aes(x = time_spent_deal, y = deal_size) + 26 | geom_point() + 27 | facet_wrap("clientid") 28 | 29 | 30 | F = coef(model)$clie 31 | F$clientid = row.names(F) 32 | 33 | 34 | ggplot(F,aes(x=reorder(clientid, -salespeople_involved), y=salespeople_involved)) + 35 | geom_bar(stat="identity", color="blue", fill="white") + labs(x = "Clientid",y = "Fixed + Random effect",title = 36 | "Sales people involved / Deal size slope") 37 | 38 | 39 | 40 | plot_model(model,type="re") 41 | 42 | 43 | 44 | plot(model, clientid ~ resid(., scaled=TRUE)) 45 | plot (model, deal_size ~ fitted(.) | clientid, abline = c (0,1)) 46 | plot(model, resid(., scaled=TRUE) ~ salespeople_involved | clientid, abline = 0) 47 | plot(model, resid(., scaled=TRUE) ~ time_spent_deal | clientid, abline = 0) -------------------------------------------------------------------------------- /Chapter03/03__09__lasso.R: -------------------------------------------------------------------------------- 1 | library(MASS) 2 | library(tidyr) 3 | library(ggplot2) 4 | library(glmnet) 5 | library(dplyr) 6 | set.seed(100) 7 | 8 | get_results<- function(lambda){ 9 | coeffs_total=data.frame(V1=numeric(),V2=numeric(),V3=numeric(),V4=numeric(),V5=numeric()) 10 | for (q in 1:100){ 11 | V1 =runif(1000)*100 12 | V2 =runif(1000)*10 + V1 13 | 14 | V3 =runif(1000)*100 15 | V4 =runif(1000)*10 + V3 16 | 17 | V5 =runif(1000)*100 18 | Residuals =runif(1000)*100 19 | Y = V1 + V2 + V3 + V4 + Residuals 20 | coefs_lm <-lm(Y ~ V1 + V2 + V3 + V4 + V5)$coefficients 21 | coefs_rd <-glmnet(cbind(V1 ,V2,V3,V4 ,V5),Y,lambda=lambda,alpha=1)$beta 22 | frame1 <-data.frame(V1=coefs_lm[2], V2=coefs_lm[3],V3=coefs_lm[4], V4=coefs_lm[5],V5=coefs_lm[6],method="lm") 23 | frame2 <-data.frame(V1=coefs_rd[1], V2=coefs_rd[2],V3=coefs_rd[3], V4=coefs_rd[4],V5=coefs_rd[5],method="lasso") 24 | coeffs_total<-rbind(coeffs_total,frame1,frame2) 25 | } 26 | transposed_data= gather(coeffs_total,"variable","value",1:5) 27 | print(transposed_data%>%group_by(variable,method) %>% summarise(median=median(value))) 28 | ggplot(transposed_data,aes(x=variable, y=value, fill=method)) +geom_boxplot() 29 | } 30 | 31 | get_results(8) 32 | get_results(0.1) 33 | 34 | V1 =runif(1000)*100 35 | V2 =runif(1000)*10 + V1 36 | V3 =runif(1000)*100 37 | V4 =runif(1000)*10 + V3 38 | V5 =runif(1000)*100 39 | Residuals =runif(1000)*100 40 | Y = V1 + V2 + V3 + V4 + Residuals 41 | cv.lasso=cv.glmnet(cbind(V1 ,V2,V3,V4 ,V5),Y,alpha=1) 42 | cv.lasso 43 | plot(cv.lasso) -------------------------------------------------------------------------------- /Chapter04/04__06__variableselection.R: -------------------------------------------------------------------------------- 1 | v1_1 = rnorm(1000,10,1) 2 | v1_2 = rnorm(1000,10,1) 3 | v1_3 = rnorm(1000,10,1) 4 | v2_1 = rnorm(1000,10,1) 5 | v2_2 = rnorm(1000,10,1) 6 | v2_3 = rnorm(1000,10,1) 7 | U = rnorm(1000,0,3) 8 | 9 | Y = v1_1 + v1_2 + v1_3 + U 10 | 11 | lista = list(x=cbind(v1_1,v1_2,v1_3,v2_1,v2_2,v2_3),y=Y,n=length(Y)) 12 | 13 | library('rjags') 14 | 15 | mod <- " model{ 16 | for (i in 1:n){ 17 | mu[i] = id[1]*b[1]*x[i,1] + id[2]*b[2]*x[i,2] + id[3]*b[3]*x[i,3] + id[4]*b[4]*x[i,4] + id[5]*b[5]*x[i,5] + id[6]*b[6]*x[i,6] 18 | y[i] ~ dnorm(mu[i], prec) 19 | } 20 | 21 | for (i in 1:6){ 22 | b[i] ~ dnorm(0.0, 1/2) 23 | id[i] ~ dbern(0.5) 24 | } 25 | prec ~ dgamma(1, 2) 26 | }" 27 | 28 | jags <- jags.model(textConnection(mod), data = lista, n.chains = 1, n.adapt = 100) 29 | update(jags, 5000) 30 | samps <- coda.samples( jags, c("b","id"), n.iter=1000 ) 31 | summary(samps) 32 | 33 | 34 | 35 | 36 | mod <- " model{ 37 | for (i in 1:n){ 38 | mu[i] = id[1]*b[1]*x[i,1] + id[2]*b[2]*x[i,2] + id[3]*b[3]*x[i,3] + id[4]*b[4]*x[i,4] + id[5]*b[5]*x[i,5] + id[6]*b[6]*x[i,6] 39 | y[i] ~ dnorm(mu[i], prec) 40 | } 41 | 42 | ka ~ dbeta(5,5) 43 | for (i in 1:6){ 44 | b[i] ~ dnorm(0.0, 1/2) 45 | id[i] ~ dbern(ka) 46 | } 47 | 48 | prec ~ dgamma(1, 2) 49 | }" 50 | 51 | jags <- jags.model(textConnection(mod), data = lista, n.chains = 1, n.adapt = 100) 52 | update(jags, 2000) 53 | samps <- coda.samples( jags, c("b","id"), n.iter=1000 ) 54 | summary(samps) -------------------------------------------------------------------------------- /Chapter04/04__03__stanmodel.R: -------------------------------------------------------------------------------- 1 | data = read.csv("/Users/admin/Documents/R_book/chapter3/house_prices.csv") 2 | 3 | model =" 4 | 5 | data { 6 | 7 | real y[481]; 8 | 9 | real x[481,6]; 10 | 11 | } 12 | 13 | parameters { 14 | 15 | real beta[6]; 16 | 17 | real sigma; 18 | 19 | real alpha; 20 | 21 | } 22 | 23 | model { 24 | 25 | beta[1] ~ uniform(0,1000); 26 | 27 | for (n in 1:481) 28 | 29 | y[n] ~ normal(alpha + beta[1]*x[n,1] + beta[2]*x[n,2] + beta[3]*x[n,3] + beta[4]*x[n,4] + beta[5]*x[n,5] + 30 | 31 | beta[6]*x[n,6], sigma); 32 | 33 | } 34 | " 35 | 36 | xy = list(y=data[,1],x=data[,2:7]) 37 | fit = stan(model_code = model, data = xy, warmup = 500, iter = 1000, chains = 1, cores = 1, thin = 1,verbose=FALSE) 38 | stan_dens(fit) 39 | 40 | 41 | 42 | 43 | 44 | model =" 45 | 46 | data { 47 | 48 | real y[481]; 49 | 50 | real x[481,6]; 51 | 52 | } 53 | 54 | parameters { 55 | 56 | real beta[6]; 57 | 58 | real sigma; 59 | 60 | real alpha; 61 | 62 | } 63 | 64 | model { 65 | 66 | beta[1] ~ uniform(0,1000); 67 | beta[2] ~ normal(1,0.1); 68 | beta[3] ~ normal(1,0.1); 69 | beta[4] ~ normal(1,0.1); 70 | beta[5] ~ normal(1,0.1); 71 | beta[6] ~ normal(1,0.1); 72 | 73 | for (n in 1:481) 74 | 75 | y[n] ~ normal(alpha + beta[1]*x[n,1] + beta[2]*x[n,2] + beta[3]*x[n,3] + beta[4]*x[n,4] + beta[5]*x[n,5] + 76 | 77 | beta[6]*x[n,6], sigma); 78 | 79 | } 80 | " 81 | 82 | xy = list(y=data[,1],x=data[,2:7]) 83 | fit = stan(model_code = model, data = xy, warmup = 500, iter = 1000, chains = 1, cores = 1, thin = 1,verbose=FALSE) 84 | stan_dens(fit) -------------------------------------------------------------------------------- /Chapter09/09__04__modeltuning.R: -------------------------------------------------------------------------------- 1 | library(caret) 2 | 3 | set.seed(11) 4 | mushroom_data = read.csv("https://archive.ics.uci.edu/ml/machine-learning-databases/mushroom/agaricus-lepiota.data",head=FALSE) 5 | 6 | colnames(mushroom_data) = c("edible","cap_shape", "cap_surface", "cap_color","bruises","odor", 7 | "gill_attachment","gill_spacing","gill_size","gill_color","stalk_shape", 8 | "stalk_root","stalk_surface_above_ring","stalk_surface_below_ring","stalk_color_above_ring", 9 | "stalk_color_below_ring","veil_type","veil_color","ring_number","ring_type", 10 | "spore_print_color","population","habitat") 11 | 12 | 13 | edible = mushroom_data[,1] 14 | mushroom_data = mushroom_data[,-1] 15 | 16 | 17 | mushroom_data = mushroom_data[,-which(colnames(mushroom_data)=="veil_type")] 18 | mushroom_dummy_model = dummyVars(data=mushroom_data,~.,sep="__") 19 | mushroom_data_model = cbind(data.frame(predict(mushroom_dummy_model, mushroom_data)), 20 | edible) 21 | 22 | 23 | 24 | control = trainControl(method="repeatedcv", number=4, repeats=1) 25 | metric = "Accuracy" 26 | tunegrid = expand.grid(.mtry=c(2,5,7,10)) 27 | 28 | 29 | 30 | rf_default = train(edible~., data=mushroom_data_model, method="rf", metric=metric, 31 | tuneGrid=tunegrid, trControl=control) 32 | 33 | 34 | print(rf_default) 35 | rf_default$finalModel 36 | -------------------------------------------------------------------------------- /Chapter08/08__06__cAIC.R: -------------------------------------------------------------------------------- 1 | library("lme4") 2 | 3 | library(cAIC4) 4 | 5 | set.seed(25) 6 | 7 | data = read.csv("./sample_random_regression.csv") 8 | 9 | data$clientid = as.factor(data$clientid) 10 | 11 | data$ERR_1 = rnorm(100,0,10) 12 | 13 | data$ERR_2 = rnorm(100,0,10) 14 | 15 | data$ERR_3 = rnorm(100,0,10) 16 | 17 | data$ERR_4 = rnorm(100,0,10) 18 | 19 | 20 | 21 | m1 = lmer(data=data,deal_size ~ salespeople_involved + time_spent_deal + (-1 + salespeople_involved|clientid) + (-1 + time_spent_deal|clientid) ) 22 | 23 | m2 = lmer(data=data,deal_size ~ salespeople_involved + time_spent_deal + (1 + salespeople_involved|clientid) ) 24 | 25 | m3 = lmer(data=data,deal_size ~ salespeople_involved + time_spent_deal + (1 + time_spent_deal + salespeople_involved|clientid) ) 26 | 27 | m4 = lmer(data=data,deal_size ~ salespeople_involved + time_spent_deal + ERR_1 + ERR_2 + ERR_3 + ERR_4 + (1 + time_spent_deal + salespeople_involved|clientid) ) 28 | 29 | m5 = lmer(data=data,deal_size ~ salespeople_involved + time_spent_deal + ERR_1 + ERR_2 + ERR_3 + (1 + time_spent_deal + salespeople_involved|clientid) ) 30 | 31 | m6 = lmer(data=data,deal_size ~ salespeople_involved + time_spent_deal + ERR_1 + ERR_2 + (1 + time_spent_deal + salespeople_involved|clientid) ) 32 | 33 | m7 = lmer(data=data,deal_size ~ salespeople_involved + time_spent_deal + ERR_1 + (1 + time_spent_deal + salespeople_involved|clientid) ) 34 | 35 | 36 | 37 | cAIC(m1)$caic 38 | 39 | 40 | cAIC(m2)$caic 41 | 42 | 43 | cAIC(m3)$caic 44 | 45 | 46 | cAIC(m4)$caic 47 | 48 | 49 | cAIC(m5)$caic 50 | 51 | 52 | cAIC(m6)$caic 53 | 54 | 55 | cAIC(m7)$caic 56 | 57 | -------------------------------------------------------------------------------- /Chapter09/09__05__classificationROC.R: -------------------------------------------------------------------------------- 1 | library(MASS) 2 | library(PRROC) 3 | library(precrec) 4 | library(pROC) 5 | 6 | set.seed(10) 7 | data = read.csv("./approved.csv") 8 | data = data[,-c(1,7)] 9 | data$Approved_ = "not_approved" 10 | data$Approved_[data$Approved == 1] <- "approved" 11 | data$Approved_ = as.factor(data$Approved_) 12 | data = data[,-1] 13 | 14 | 15 | trainIndex <- createDataPartition(data$Approved_, p = .75, list = FALSE, times = 1) 16 | traindata <- data[trainIndex,] 17 | testdata <- data[-trainIndex,] 18 | 19 | 20 | 21 | 22 | 23 | rctrl1 <- trainControl(method = "cv",number=5,classProbs = TRUE,summaryFunction = 24 | twoClassSummary) 25 | 26 | model1 <- train(Approved_~.,traindata, 27 | method = "gbm", verbose=FALSE, 28 | trControl = rctrl1,metric="ROC", 29 | tuneLength = 10) 30 | 31 | 32 | 33 | predictions_train = predict(model1,traindata) 34 | confusionMatrix(traindata$Approved_,predictions_train) 35 | 36 | 37 | 38 | predictions_test = predict(model1,testdata) 39 | confusionMatrix(testdata$Approved_,predictions_test) 40 | 41 | 42 | plot.roc(traindata$Approved_,predict(model1, traindata, type="prob")[,1],main="ROC curves, 43 | black=train,red=test") 44 | plot.roc(testdata$Approved_,predict(model1, testdata, type="prob")[,1],col="red",add=TRUE) 45 | 46 | 47 | 48 | 49 | par(mfrow=c(2,1)) 50 | sscurves <- evalmod(scores = predict(model1, traindata, type="prob")[,2], labels = traindata$Approved_) 51 | plot(sscurves) 52 | 53 | sscurves <- evalmod(scores = predict(model1, testdata, type="prob")[,2], labels = testdata$Approved_) 54 | plot(sscurves) 55 | -------------------------------------------------------------------------------- /Chapter08/08__03__nlmixed.R: -------------------------------------------------------------------------------- 1 | set.seed(10) 2 | 3 | X = 7*runif(1000) 4 | 5 | G = c() 6 | 7 | for (x in 1:100){ 8 | 9 | G = c(G,rep(x,10)) 10 | 11 | } 12 | 13 | pre____frame = cbind(X=X,G=G,NOISE = rnorm(1000,0,0.03)) 14 | 15 | shocks_frame = cbind(G = 1:100,shocks = rnorm(100,0,1)) 16 | 17 | merged_frame = merge(pre____frame,shocks_frame,by="G") 18 | 19 | merged_frame$Y = 1/(1+exp(-merged_frame$X + merged_frame$shocks)) + merged_frame$NOISE 20 | 21 | XYG = merged_frame[,c(1,2,5)] 22 | 23 | 24 | 25 | get__loglikelihood = function(params){ 26 | 27 | BETA1 = params[1] 28 | 29 | SIGMAG = params[2] 30 | 31 | SIGMA = params[3] 32 | 33 | GROUP_LIK = 0 34 | 35 | IS_ERROR = FALSE 36 | 37 | 38 | 39 | for (q in 1:100){ 40 | 41 | group_data = XYG[XYG$G==q,] 42 | 43 | average = 0; 44 | 45 | for (sim in 1:500){ 46 | 47 | group_data$shock= rnorm(10,0,SIGMAG) 48 | 49 | group_data$pred = 1/(1+exp(-BETA1*group_data$X + group_data$shock)) 50 | 51 | mult = 1 52 | 53 | for (x in 1:10){ 54 | 55 | mult = mult * dnorm(group_data$pred[x]-group_data$Y[x],0,SIGMA) 56 | 57 | } 58 | 59 | average = average + mult 60 | 61 | } 62 | 63 | average = average/500 64 | 65 | average = log(average) 66 | 67 | GROUP_LIK = GROUP_LIK + average 68 | 69 | } 70 | 71 | if (is.na(GROUP_LIK) | GROUP_LIK == -Inf){ 72 | 73 | GROUP_LIK = -1000000000 74 | 75 | } 76 | 77 | return(-GROUP_LIK) 78 | 79 | } 80 | 81 | 82 | 83 | Sys.time() 84 | 85 | optim(c(1,1,0.03),get__loglikelihood,method="BFGS",control=list(trace=1,REPORT=1)) 86 | 87 | Sys.time() -------------------------------------------------------------------------------- /Chapter09/09__02__preprocessing.R: -------------------------------------------------------------------------------- 1 | library(MASS) 2 | library(caret) 3 | library(RANN) 4 | set.seed(100) 5 | data <- read.csv("./metals.csv") 6 | data = data[-1] 7 | trainIndex <- createDataPartition(data$metal_strength, p = .75, 8 | list = FALSE, times = 1) 9 | traindata <- data[trainIndex,] 10 | testdata <- data[-trainIndex,] 11 | 12 | 13 | preprocess_object <- 14 | preProcess(traindata[-1],method=c("medianImpute","scale","center")) 15 | x_transformed <- predict(preprocess_object,traindata[-1]) 16 | combined_train_data <- cbind(x_transformed,traindata[1]) 17 | 18 | 19 | control <- trainControl(method="none") 20 | tunegrid <- expand.grid(C=c(0.01)) 21 | m3 <- train(metal_strength~., data=combined_train_data, 22 | method="svmLinear", 23 | metric="RMSE", tuneGrid=tunegrid, trControl=control) 24 | 25 | 26 | test_xdata <- predict(preprocess_object,testdata[-1]) 27 | y_test_pred <- predict(m3,test_xdata) 28 | postResample(pred = y_test_pred, obs = testdata$m) 29 | 30 | 31 | 32 | control <- trainControl(method="none") 33 | tunegrid <- expand.grid(C=c(0.9)) 34 | m3 <- train(metal_strength~., data=combined_train_data, 35 | method="svmLinear", metric="RMSE", tuneGrid=tunegrid, 36 | trControl=control) 37 | test_xdata <- predict(preprocess_object,testdata[-1]) 38 | y_test_pred <- predict(m3,test_xdata) 39 | postResample(pred = y_test_pred, obs = testdata$m) 40 | 41 | 42 | 43 | control <- trainControl(method="repeatedcv", number=4, repeats=1) 44 | tunegrid <- expand.grid(C=c(0.01,0.1,0.2,0.3,0.4,0.5)) 45 | m3 <- train(metal_strength~., data=combined_train_data, 46 | method="svmLinear",preProcess=c("medianImpute","scale","center") 47 | ,metric="RMSE", tuneGrid=tunegrid, trControl=control) 48 | m3 49 | m3$bestTune 50 | 51 | 52 | -------------------------------------------------------------------------------- /Chapter02/class2.csv: -------------------------------------------------------------------------------- 1 | Math,History,Physics 2 | 4.175394998,5.100252545,5.140093439 3 | 3.676455638,4.55004798,4.045593186 4 | 5.800250683,5.528061566,6.73385735 5 | 6.638782204,5.359526231,6.085534328 6 | 6.25694433,4.718109245,6.158065733 7 | 6.017528084,7.297447571,5.852857995 8 | 4.55681055,7.315088544,6.520769658 9 | 7.650807996,6.061851504,4.629880966 10 | 4.674673939,8.341289511,4.06921296 11 | 5.439966969,5.804282582,6.274296838 12 | 6.455614969,5.314641456,7.068989737 13 | 6.276486721,5.284795433,6.234227142 14 | 5.207632527,7.643703758,5.76275148 15 | 5.337315215,5.5563669,4.353464685 16 | 6.716013176,6.895217572,4.365428875 17 | 7.114900498,5.66256104,7.404196033 18 | 7.00177258,6.172895119,5.699982565 19 | 6.073387196,7.843152686,6.47515265 20 | 5.661077674,5.19683914,6.440456613 21 | 5.917979968,4.754341574,4.395727152 22 | 5.693113094,6.131959327,3.9853588 23 | 6.092420421,5.621819343,5.58804332 24 | 6.976083083,5.650846346,5.688548535 25 | 5.298684586,5.733516408,5.964996581 26 | 6.574354858,5.51762027,6.097459058 27 | 7.689148371,9.135625851,8.248401154 28 | 5.371030761,5.243401846,6.144139925 29 | 6.556452596,7.217033542,5.517241073 30 | 4.999616947,3.351266904,5.255565446 31 | 1.323904765,5.005314112,4.158529261 32 | 8.359483568,6.654835409,7.280206923 33 | 5.663248333,4.712855605,5.580512973 34 | 6.959132685,5.517119022,5.094132875 35 | 7.505939386,7.285905498,5.022332106 36 | 5.812133327,5.259706309,4.779627537 37 | 5.325622194,5.521559785,4.699466487 38 | 6.641243885,6.116829962,5.564774713 39 | 6.28739118,5.76973116,6.965469028 40 | 7.780858079,6.506082858,7.474433358 41 | 7.018919117,6.404663331,6.740840398 42 | 6.957719937,6.427204757,5.422233648 43 | 5.737275687,4.717894152,8.413685264 44 | 4.578932915,6.208551728,3.908124982 45 | 6.637751248,7.27833945,5.005265092 46 | 2.907777504,4.022756241,4.504037788 47 | 6.183547167,4.72408448,8.581900272 48 | 4.420781565,4.292040069,3.829323478 49 | 7.277034314,5.969752671,4.192232243 50 | 7.91802754,7.22609034,6.616001288 51 | 4.256014782,4.070396476,7.675019307 52 | -------------------------------------------------------------------------------- /Chapter02/class1.csv: -------------------------------------------------------------------------------- 1 | Math,History,Physics 2 | 7.308051,6.031917867,5.399676466 3 | 7.961098574,5.52100645,3.062257654 4 | 6.708068407,5.156177658,5.409130753 5 | 6.664234175,2.290215704,4.973637431 6 | 5.674486321,7.066650573,3.853662738 7 | 6.305229251,4.102209033,5.488794715 8 | 7.037851958,6.977884125,4.999645967 9 | 5.873399355,3.035313698,5.616073029 10 | 8.965466104,4.469932504,6.423383902 11 | 7.32781366,6.052550515,4.866234816 12 | 7.037130429,5.011006406,4.640488429 13 | 7.096712894,4.833571375,4.736211217 14 | 6.731062063,5.75162035,5.215798086 15 | 4.978756537,2.90345973,6.554901063 16 | 6.587293313,4.90084718,5.084460378 17 | 7.138678802,5.485623428,4.47725383 18 | 8.280301701,4.582234406,5.484494517 19 | 6.201438959,4.371834035,4.657069019 20 | 7.808158031,6.22813233,6.129254834 21 | 5.651096685,1.738300398,1.607499962 22 | 6.874128428,5.504307343,6.13915244 23 | 6.463935306,4.697253652,3.192027427 24 | 6.220722442,5.757863098,4.113953927 25 | 6.445824508,2.771830783,5.103192595 26 | 6.678663155,8.029336522,5.113092365 27 | 7.082721911,5.709042293,5.727073121 28 | 7.603191364,6.714863306,5.176865965 29 | 7.555913732,4.13073516,4.513335781 30 | 7.953428572,5.815448806,7.241615122 31 | 6.957933131,6.05991093,3.126259593 32 | 6.764081152,4.641623632,5.909921851 33 | 4.276424427,3.353276267,3.282571575 34 | 7.721871259,5.829271087,3.926659846 35 | 6.752646569,6.681842271,3.950696727 36 | 8.897547842,4.744615991,5.74811589 37 | 7.617872187,5.1868785,4.963567063 38 | 6.665565683,4.697416568,5.003406948 39 | 6.890070661,3.754177268,4.910101801 40 | 5.736993199,2.564874751,5.007470128 41 | 6.252128481,3.766873249,3.620119894 42 | 6.783873696,5.678035106,4.890145207 43 | 3.635280248,3.241978514,5.261901767 44 | 9.179688338,7.619037734,6.356205266 45 | 6.819702359,4.829837326,3.192784379 46 | 6.801416426,6.378889307,5.628936868 47 | 4.563932927,2.198503479,5.657221205 48 | 7.062571858,6.186874607,5.009547758 49 | 5.055471009,3.395172922,3.9799783 50 | 7.291557081,5.611848732,3.944939048 51 | 9.278822414,7.94468417,6.284348292 52 | -------------------------------------------------------------------------------- /Chapter03/sales_clients_combos.csv: -------------------------------------------------------------------------------- 1 | Client,Salesman,Strategy,Sales 2 | 1,John,Classic,21.2901894915695 3 | 2,John,Classic,28.0594553276812 4 | 2,John,Classic,21.1247966461804 5 | 3,John,Classic,22.7955063753133 6 | 3,John,Classic,12.8519131030086 7 | 4,John,Classic,22.1577007145641 8 | 4,John,Classic,24.3990014648445 9 | 5,John,Classic,27.4734552070313 10 | 1,Michael,Classic,28.0201688368905 11 | 1,Michael,Classic,30.4597384141886 12 | 2,Michael,Classic,30.4698635798089 13 | 2,Michael,Classic,28.7626171676902 14 | 3,Michael,Classic,22.9627307449863 15 | 4,Michael,Classic,31.3449377416118 16 | 4,Michael,Classic,27.0873901408421 17 | 5,Michael,Classic,26.6032272965562 18 | 5,Michael,Classic,27.0718293883785 19 | 1,Tom,Classic,39.4544187020959 20 | 1,Tom,Classic,33.6070873313208 21 | 2,Tom,Classic,32.202330461718 22 | 3,Tom,Classic,41.587689202638 23 | 3,Tom,Classic,35.2707819615278 24 | 4,Tom,Classic,40.2943362056135 25 | 4,Tom,Classic,36.4088190719881 26 | 5,Tom,Classic,33.1786421381853 27 | 5,Tom,Classic,37.6971225419555 28 | 1,John,Offer_discount,23.9027551561371 29 | 1,John,Offer_discount,28.5184886994676 30 | 2,John,Offer_discount,22.4277982244306 31 | 2,John,Offer_discount,20.939809531709 32 | 3,John,Offer_discount,15.8369760878824 33 | 4,John,Offer_discount,18.2910329543518 34 | 4,John,Offer_discount,17.17762054662 35 | 5,John,Offer_discount,23.752552926185 36 | 5,John,Offer_discount,17.9521054545616 37 | 1,Michael,Offer_discount,31.8503501050448 38 | 1,Michael,Offer_discount,25.7962109410753 39 | 2,Michael,Offer_discount,33.8575300075843 40 | 3,Michael,Offer_discount,24.084161217053 41 | 3,Michael,Offer_discount,31.3795249635514 42 | 4,Michael,Offer_discount,32.9096296441841 43 | 4,Michael,Offer_discount,27.2854821063829 44 | 5,Michael,Offer_discount,32.2115642455411 45 | 1,Tom,Offer_discount,33.9529663422732 46 | 2,Tom,Offer_discount,33.239088580085 47 | 2,Tom,Offer_discount,36.2742983541574 48 | 3,Tom,Offer_discount,38.8293257646338 49 | 3,Tom,Offer_discount,30.1175423244905 50 | 4,Tom,Offer_discount,38.1013528816385 51 | 4,Tom,Offer_discount,32.3244300795395 52 | 5,Tom,Offer_discount,30.8087363252004 -------------------------------------------------------------------------------- /Chapter09/09__01__partition.R: -------------------------------------------------------------------------------- 1 | library(caret) 2 | 3 | mushroom_data = read.csv("https://archive.ics.uci.edu/ml/machine-learning-databases/mushroom/agaricus-lepiota.data",head=FALSE) 4 | colnames(mushroom_data) = c("edible","cap-shape", "cap-surface", "cap-color","bruises","odor", 5 | "gill-attachment","gill-spacing","gill-size","gill-color","stalk-shape", 6 | "stalk-root","stalk-surface-above-ring","stalk-surface-below-ring","stalk-color-above-ring", 7 | "stalk-color-below-ring","veil-type","veil-color","ring-number","ring-type", 8 | "spore-print-color","population","habitat") 9 | 10 | 11 | 12 | trainIndex <- createDataPartition(mushroom_data$edible, p = .75, list = FALSE, times = 1) 13 | traindata <- mushroom_data[trainIndex,] 14 | testdata <- mushroom_data[-trainIndex,] 15 | 16 | 17 | 18 | 19 | total_proportion <- nrow(mushroom_data[mushroom_data$edible=="e",])/nrow(mushroom_data) 20 | train_proportion <- nrow(traindata[traindata$edible=="e",])/nrow(traindata) 21 | test_proportion <- nrow(testdata[testdata$edible=="e",])/nrow(testdata) 22 | print(paste("p of edible in data=",round(total_proportion,3), 23 | "/p of edible in train=",round(train_proportion,3), 24 | "/p of edible in test=",round(test_proportion,3))) 25 | 26 | 27 | 28 | bootstrap_sample <- createResample(mushroom_data$edible,times=10,list=FALSE) 29 | 30 | 31 | 32 | 33 | 34 | kfolds_results = createFolds(mushroom_data$edible, k=4,list=FALSE) 35 | r1 = nrow(mushroom_data[kfolds_results==1 & mushroom_data$edible=="e",])/nrow(mushroom_data[kfolds_results==1,]) 36 | r2 = nrow(mushroom_data[kfolds_results==2 & mushroom_data$edible=="e",])/nrow(mushroom_data[kfolds_results==2,]) 37 | r3 = nrow(mushroom_data[kfolds_results==3 & mushroom_data$edible=="e",])/nrow(mushroom_data[kfolds_results==3,]) 38 | r4 = nrow(mushroom_data[kfolds_results==4 & mushroom_data$edible=="e",])/nrow(mushroom_data[kfolds_results==4,]) 39 | print(paste("proportion of edible in fold1=",r1, 40 | "/proportion of edible in fold2=",r2, 41 | "/proportion of edible in fold3=",r3, 42 | "/proportion of edible in fold4=",r4)) 43 | 44 | 45 | r = rnorm(10,0,1) 46 | createTimeSlices(r,4,horizon=2) -------------------------------------------------------------------------------- /Chapter02/pre_post_employee.csv: -------------------------------------------------------------------------------- 1 | pre_bonus,post_bonus 2 | 15.82686544,12.72468892 3 | 6.75758986,15.23918703 4 | 7.161252728,11.59075535 5 | 12.21879828,4.892562819 6 | 15.00345795,16.0152301 7 | 9.984665984,5.83803107 8 | 8.031008981,8.657288966 9 | 13.80968277,15.98120944 10 | 9.429940637,11.40912299 11 | 14.41452662,12.0757674 12 | 2.984617004,12.10748181 13 | 16.98959495,8.402638759 14 | 10.18103215,14.27852187 15 | 16.75136195,8.136981914 16 | 15.66489741,12.41691776 17 | 5.186523377,11.47371539 18 | 7.175116027,6.948221803 19 | 17.9724033,9.998657793 20 | 10.98633989,12.0209064 21 | 6.745053709,10.48179025 22 | 12.34135668,10.52236903 23 | 6.008538286,12.94008921 24 | 19.28446109,11.2512715 25 | 4.62515427,13.5210717 26 | 14.35842571,7.616920818 27 | 8.529023621,12.28410995 28 | 4.517577507,13.09341564 29 | 9.764019582,9.405909412 30 | 2.718535923,11.82088789 31 | 6.246481564,13.64784904 32 | 21.45192394,12.36720034 33 | 16.2927987,15.68438661 34 | 14.13600324,9.167705402 35 | 12.13297063,16.07799292 36 | 11.1905006,10.6529993 37 | 7.97367413,13.66525684 38 | 12.30893061,16.5860569 39 | 8.559627862,9.86158184 40 | 6.621573283,17.94232741 41 | 11.69772997,5.824036326 42 | 16.41660976,13.70025963 43 | 16.49462144,19.32300707 44 | 6.50695524,12.95117954 45 | 11.38265853,9.061735813 46 | 4.38673222,13.91325251 47 | 2.623643707,9.175651384 48 | 8.145353366,9.913786772 49 | 15.12937083,16.30898971 50 | 8.707166777,11.94911163 51 | 12.64401512,15.27107235 52 | 8.293248059,12.26807581 53 | 10.20012266,11.04750501 54 | 4.252599821,9.073739737 55 | 7.867064776,16.11635171 56 | 12.20311594,14.70183083 57 | 12.72324942,19.07942391 58 | 8.542212986,14.31696628 59 | 10.83597507,16.04107078 60 | 12.15394362,13.97147869 61 | 5.481961903,17.84172837 62 | 12.29032455,8.497184641 63 | 11.27158717,9.99775824 64 | 12.79319773,10.84658947 65 | 3.398204749,12.32162724 66 | 11.18855195,10.70004566 67 | 4.312316929,13.86709876 68 | 6.888209171,12.95496101 69 | 1.295231125,9.169895463 70 | 14.89610716,10.22407007 71 | 9.594188136,11.75229978 72 | 11.0493818,14.74129795 73 | 5.567001209,13.51447825 74 | 8.717577733,16.2301773 75 | 15.26373843,11.61059324 76 | 6.984490819,15.78570534 77 | 14.76524928,10.50581859 78 | 4.590589392,18.70334125 79 | 13.21374006,10.65765841 80 | 8.470320287,15.02097787 81 | 6.733554324,19.57125596 82 | -------------------------------------------------------------------------------- /Chapter05/pre_post_employee.csv: -------------------------------------------------------------------------------- 1 | pre_bonus,post_bonus 2 | 15.82686544,12.72468892 3 | 6.75758986,15.23918703 4 | 7.161252728,11.59075535 5 | 12.21879828,4.892562819 6 | 15.00345795,16.0152301 7 | 9.984665984,5.83803107 8 | 8.031008981,8.657288966 9 | 13.80968277,15.98120944 10 | 9.429940637,11.40912299 11 | 14.41452662,12.0757674 12 | 2.984617004,12.10748181 13 | 16.98959495,8.402638759 14 | 10.18103215,14.27852187 15 | 16.75136195,8.136981914 16 | 15.66489741,12.41691776 17 | 5.186523377,11.47371539 18 | 7.175116027,6.948221803 19 | 17.9724033,9.998657793 20 | 10.98633989,12.0209064 21 | 6.745053709,10.48179025 22 | 12.34135668,10.52236903 23 | 6.008538286,12.94008921 24 | 19.28446109,11.2512715 25 | 4.62515427,13.5210717 26 | 14.35842571,7.616920818 27 | 8.529023621,12.28410995 28 | 4.517577507,13.09341564 29 | 9.764019582,9.405909412 30 | 2.718535923,11.82088789 31 | 6.246481564,13.64784904 32 | 21.45192394,12.36720034 33 | 16.2927987,15.68438661 34 | 14.13600324,9.167705402 35 | 12.13297063,16.07799292 36 | 11.1905006,10.6529993 37 | 7.97367413,13.66525684 38 | 12.30893061,16.5860569 39 | 8.559627862,9.86158184 40 | 6.621573283,17.94232741 41 | 11.69772997,5.824036326 42 | 16.41660976,13.70025963 43 | 16.49462144,19.32300707 44 | 6.50695524,12.95117954 45 | 11.38265853,9.061735813 46 | 4.38673222,13.91325251 47 | 2.623643707,9.175651384 48 | 8.145353366,9.913786772 49 | 15.12937083,16.30898971 50 | 8.707166777,11.94911163 51 | 12.64401512,15.27107235 52 | 8.293248059,12.26807581 53 | 10.20012266,11.04750501 54 | 4.252599821,9.073739737 55 | 7.867064776,16.11635171 56 | 12.20311594,14.70183083 57 | 12.72324942,19.07942391 58 | 8.542212986,14.31696628 59 | 10.83597507,16.04107078 60 | 12.15394362,13.97147869 61 | 5.481961903,17.84172837 62 | 12.29032455,8.497184641 63 | 11.27158717,9.99775824 64 | 12.79319773,10.84658947 65 | 3.398204749,12.32162724 66 | 11.18855195,10.70004566 67 | 4.312316929,13.86709876 68 | 6.888209171,12.95496101 69 | 1.295231125,9.169895463 70 | 14.89610716,10.22407007 71 | 9.594188136,11.75229978 72 | 11.0493818,14.74129795 73 | 5.567001209,13.51447825 74 | 8.717577733,16.2301773 75 | 15.26373843,11.61059324 76 | 6.984490819,15.78570534 77 | 14.76524928,10.50581859 78 | 4.590589392,18.70334125 79 | 13.21374006,10.65765841 80 | 8.470320287,15.02097787 81 | 6.733554324,19.57125596 82 | -------------------------------------------------------------------------------- /Chapter01/08/simple_sampling.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | library(ggplot2) 3 | 4 | voters_data = read.csv("./voters_.csv") 5 | 6 | 7 | 8 | proportions_10sample = c() 9 | for (q in 2:1000){ 10 | sample_data = mean(sample(voters_data$Vote,10,replace = FALSE)) 11 | proportions_10sample = c(proportions_10sample,sample_data) 12 | } 13 | 14 | proportions_50sample = c() 15 | for (q in 2:1000){ 16 | sample_data = mean(sample(voters_data$Vote,50,replace = FALSE)) 17 | proportions_50sample = c(proportions_50sample,sample_data) 18 | } 19 | 20 | proportions_100sample = c() 21 | for (q in 2:1000){ 22 | sample_data = mean(sample(voters_data$Vote,100,replace = FALSE)) 23 | proportions_100sample = c(proportions_100sample,sample_data) 24 | } 25 | 26 | proportions_500sample = c() 27 | for (q in 2:1000){ 28 | sample_data = mean(sample(voters_data$Vote,500,replace = FALSE)) 29 | proportions_500sample = c(proportions_500sample,sample_data) 30 | } 31 | 32 | joined_data50 = data.frame("sample_size"=50,"mean"=mean(proportions_50sample), "q2.5"=quantile(proportions_50sample,0.025),"q97.5"=quantile(proportions_50sample,0.975)) 33 | joined_data10 = data.frame("sample_size"=10,"mean"=mean(proportions_10sample), "q2.5"=quantile(proportions_10sample,0.025),"q97.5"=quantile(proportions_10sample,0.975)) 34 | joined_data100 = data.frame("sample_size"=100,"mean"=mean(proportions_100sample), "q2.5"=quantile(proportions_100sample,0.025),"q97.5"=quantile(proportions_100sample,0.975)) 35 | joined_data500 = data.frame("sample_size"=500,"mean"=mean(proportions_500sample), "q2.5"=quantile(proportions_500sample,0.025),"q97.5"=quantile(proportions_500sample,0.975)) 36 | 37 | data_sim = rbind(joined_data10,joined_data50,joined_data100,joined_data500) 38 | data_sim = data_sim %>% mutate(Nq2.5 = mean - 1.96*sqrt(mean*(1-mean)/sample_size),N97.5 = mean + 1.96*sqrt(mean*(1-mean)/sample_size)) 39 | data_sim$sample_size = as.factor(data_sim$sample_size) 40 | 41 | ggplot(data_sim, aes(x=sample_size, y=mean, group=1)) + 42 | geom_point(aes(size=2), alpha=0.52) + theme(legend.position="none") + 43 | geom_errorbar(width=.1, aes(ymin=q2.5, ymax=q97.5), colour="darkred") + labs(x="Sample Size",y= "Candidate A ratio", title="Candidate A ratio by sample size", subtitle="Proportion of people voting for candidate A, assuming 50-50 chance", caption="Circle is mean / Bands are 95% Confidence bands") 44 | 45 | 46 | -------------------------------------------------------------------------------- /Chapter09/09__06__gradientboosting.R: -------------------------------------------------------------------------------- 1 | library(MASS) 2 | library(PRROC) 3 | library(precrec) 4 | 5 | set.seed(10) 6 | data = read.csv("/Users/fjuretig/Documents/approved.csv") 7 | data = data[,-c(1,7)] 8 | data$Approved_ = "not_approved" 9 | data$Approved_[data$Approved == 1] <- "approved" 10 | data$Approved_ = as.factor(data$Approved_) 11 | data = data[,-1] 12 | 13 | 14 | trainIndex <- createDataPartition(data$Approved_, p = .75, list = FALSE, times = 1) 15 | traindata <- data[trainIndex,] 16 | testdata <- data[-trainIndex,] 17 | 18 | 19 | rctrl1 <- trainControl(method = "cv",number=5,classProbs = TRUE,summaryFunction = 20 | twoClassSummary) 21 | 22 | baseline <- train(Approved_~.,traindata, 23 | method = "gbm", verbose=FALSE, 24 | trControl = rctrl1, 25 | metric="ROC", 26 | tuneLength = 10) 27 | 28 | 29 | rctrl1 <- trainControl(method = "cv",number=5,sampling="up",classProbs = 30 | TRUE,summaryFunction = twoClassSummary) 31 | 32 | 33 | up <- train(Approved_~.,traindata, 34 | method = "gbm", verbose=FALSE, 35 | trControl = rctrl1, 36 | metric="ROC", 37 | tuneLength = 10) 38 | 39 | 40 | rctrl1 <- trainControl(method = "cv",number=5,sampling="smote",classProbs = 41 | TRUE,summaryFunction = twoClassSummary) 42 | 43 | smote <- train(Approved_~.,traindata, 44 | method = "gbm", verbose=FALSE, 45 | trControl = rctrl1, 46 | metric="ROC", 47 | tuneLength = 10) 48 | 49 | 50 | predictions_baseline = predict(baseline,testdata,type="prob") 51 | predictions_up = predict(up,testdata,type="prob") 52 | predictions_smote = predict(up,testdata,type="prob") 53 | 54 | 55 | confusionMatrix(testdata$Approved_,predict(baseline,testdata)) 56 | confusionMatrix(testdata$Approved_,predict(up,testdata)) 57 | confusionMatrix(testdata$Approved_,predict(smote,testdata)) 58 | confusionMatrix(testdata$Approved_,predict(baseline,testdata),mode="prec_recall") 59 | 60 | 61 | confusionMatrix(testdata$Approved_,predict(up,testdata),mode="prec_recall") 62 | confusionMatrix(testdata$Approved_,predict(smote,testdata),mode="prec_recall") 63 | -------------------------------------------------------------------------------- /Chapter09/approved.csv: -------------------------------------------------------------------------------- 1 | ,Approved,Age,income,rural,Driving license, 2 | ,1,56,90000,0,1, 3 | ,1,67,120000,1,1, 4 | ,1,76,120000,0,1, 5 | ,0,55,30074,0,0, 6 | ,1,54,120000,1,1, 7 | ,1,45,58448,1,1, 8 | ,1,87,120000,0,1, 9 | ,0,66,75903,1,1, 10 | ,1,57,120000,1,1, 11 | ,1,78,120000,0,1, 12 | ,0,89,26174,1,0, 13 | ,1,98,120000,1,1, 14 | ,1,77,120000,1,1, 15 | ,1,67,39329,0,0, 16 | ,1,87,87492,0,0, 17 | ,1,38,36960,0,0, 18 | ,0,41,46646,0,0, 19 | ,0,31,58891,0,0, 20 | ,0,21,73893,0,0, 21 | ,0,55,22148,0,0, 22 | ,0,32,42467,0,0, 23 | ,0,31,32158,0,0, 24 | ,0,41,61360,0,0, 25 | ,0,37,51103,0,0, 26 | ,0,45,67273,0,0, 27 | ,0,30,81039,0,0, 28 | ,0,55,38018,0,0, 29 | ,0,34,50943,1,0, 30 | ,0,43,21266,0,0, 31 | ,0,35,67649,0,0, 32 | ,0,23,22671,0,0, 33 | ,0,19,41570,0,0, 34 | ,0,59,55392,0,0, 35 | ,0,55,38730,0,0, 36 | ,0,50,82407,0,0, 37 | ,0,18,23507,0,0, 38 | ,0,33,89102,0,0, 39 | ,0,32,76289,0,0, 40 | ,0,57,20414,0,0, 41 | ,0,33,23492,0,0, 42 | ,0,25,33667,0,0, 43 | ,0,31,81151,0,0, 44 | ,0,31,68257,0,0, 45 | ,0,18,50595,0,0, 46 | ,0,35,78228,0,1, 47 | ,0,40,76961,0,0, 48 | ,0,32,37469,0,0, 49 | ,0,36,57786,0,0, 50 | ,0,51,53740,0,1, 51 | ,0,57,68859,0,0, 52 | ,0,52,47217,1,0, 53 | ,0,36,45292,0,0, 54 | ,0,19,70816,0,0, 55 | ,0,54,67203,1,1, 56 | ,0,37,39571,0,0, 57 | ,0,48,39697,0,0, 58 | ,0,22,50466,0,0, 59 | ,0,28,87352,0,0, 60 | ,0,56,88599,0,0, 61 | ,0,25,63513,0,0, 62 | ,0,48,81362,0,0, 63 | ,0,58,27057,0,0, 64 | ,0,35,38966,0,0, 65 | ,0,22,29041,0,0, 66 | ,0,19,87716,0,0, 67 | ,0,56,45816,0,0, 68 | ,0,53,47736,0,0, 69 | ,0,23,37388,0,1, 70 | ,0,45,42948,0,0, 71 | ,0,41,67950,0,1, 72 | ,0,29,78583,0,0, 73 | ,0,33,3728,0,0, 74 | ,0,59,31942,0,0, 75 | ,0,50,80838,1,0, 76 | ,0,24,21983,0,0, 77 | ,0,46,49299,0,0, 78 | ,0,58,38108,0,0, 79 | ,0,30,21282,0,1, 80 | ,0,18,5595,0,0, 81 | ,0,35,7228,0,1, 82 | ,0,40,7961,0,0, 83 | ,0,32,3469,0,1, 84 | ,0,36,5786,0,0, 85 | ,0,51,53740,0,1, 86 | ,0,57,68859,0,0, 87 | ,0,52,47217,1,0, 88 | ,0,36,45292,0,0, 89 | ,0,19,7016,0,0, 90 | ,0,54,6703,1,1, 91 | ,0,37,39571,0,0, 92 | ,0,48,39697,0,0, 93 | ,0,22,5066,0,0, 94 | ,0,28,87352,0,0, 95 | ,0,56,88599,0,0, 96 | ,0,25,63513,0,0, 97 | ,1,48,81362,0,0, 98 | ,1,58,27057,0,0, 99 | ,0,35,38966,0,0, 100 | ,0,22,29041,0,0, 101 | ,0,19,87716,0,0, 102 | ,0,56,45816,0,0, 103 | ,0,53,47736,0,0, 104 | ,0,23,37388,0,0, 105 | ,0,45,43233,0,0, 106 | ,1,41,67950,0,1, 107 | ,1,29,78583,0,0, 108 | ,1,33,328,0,1, 109 | ,1,59,31942,0,1, 110 | ,1,50,80838,1,0, 111 | ,1,24,2983,1,1, 112 | ,1,46,4929,0,0, 113 | ,1,58,3808,1,1, 114 | ,1,30,21282,0,1, -------------------------------------------------------------------------------- /Chapter04/04__04__stanmodel.R: -------------------------------------------------------------------------------- 1 | library(ggplot2) 2 | 3 | v1_1 = rnorm(1000,10,1) 4 | v1_2 = rnorm(1000,10,1) 5 | v1_3 = rnorm(1000,10,1) 6 | v2_1 = rnorm(1000,10,1) 7 | v2_2 = rnorm(1000,10,1) 8 | v2_3 = rnorm(1000,10,1) 9 | U = rnorm(1000,0,3) 10 | Y = v1_1 + v1_2 + v1_3 + v2_1 + v2_2 + v2_3 + U 11 | 12 | 13 | 14 | 15 | get_prior <- function(param){ 16 | c11_prior = dnorm(param[1], 0.5,5, log = T) 17 | c12_prior = dnorm(param[2], 0.5,5, log = T) 18 | c13_prior = dnorm(param[3], 0.5,5, log = T) 19 | c21_prior = dnorm(param[4], 0.5,5, log = T) 20 | c22_prior = dnorm(param[5], 0.5,5, log = T) 21 | c23_prior = dnorm(param[6], 0.5,5, log = T) 22 | sdprior = dnorm(param[7], 0.5,5, log = T) 23 | return(c11_prior+c12_prior+c13_prior+c21_prior+c22_prior+c23_prior+sdprior) 24 | 25 | } 26 | 27 | 28 | 29 | 30 | get_likelihood <- function(param){ 31 | pred = param[1]*v1_1 + param[2]*v1_2 + param[3]*v1_3 + param[4]*v2_1 + param[5]*v2_2 + param[6]*v2_3 32 | likelihood_per_observation = dnorm(Y, mean = pred, sd = param[7], log = T) 33 | sumll = sum(likelihood_per_observation) 34 | return(sumll) 35 | } 36 | 37 | 38 | get_posterior <- function(param){ 39 | return_value = get_likelihood(param) + get_prior(param) 40 | return (return_value) 41 | } 42 | 43 | 44 | get_proposalfunction <- function(param){ 45 | return(rnorm(7,mean = param, sd= c(.028,.028,.028,.028,.028,.028,.028))) 46 | } 47 | 48 | 49 | 50 | MetropolisHastings_MCMC <- function(start_, iter_){ 51 | chain_values = array(dim = c(iter_+1,7)) 52 | chain_values[1,] = start_ 53 | for (i in 1:iter_){ 54 | proposal = get_proposalfunction(chain_values[i,]) 55 | probs = exp(get_posterior(proposal) - get_posterior(chain_values[i,])) 56 | if (is.nan(probs)){ 57 | probs = 0 58 | } 59 | 60 | random_value = runif(1) 61 | if (random_value < probs){ 62 | chain_values[i+1,] = proposal 63 | }else{ 64 | chain_values[i+1,] = chain_values[i,] 65 | } 66 | } 67 | return(chain_values) 68 | } 69 | 70 | 71 | startvalue = c(0.1,0.1,0.1,0.1,0.1,0.1,10) 72 | chain_values = MetropolisHastings_MCMC(startvalue, 50000) 73 | 74 | 75 | data = data.frame(chain_values) 76 | colnames(data) = c("v1_1","v1_2","v1_3","v2_1","v2_2","v2_3","sd") 77 | data$iter = seq.int(nrow(data)) 78 | 79 | 80 | 81 | ggplot(data=data,aes(x=iter, y=v1_1)) + geom_line(color="blue") 82 | 83 | 84 | data = data[10000:50000,] 85 | data = data[seq(1, dim(data)[1], by = 5),] 86 | ggplot(data=data,aes(x=iter, y=v1_1)) + geom_line(color="blue") 87 | 88 | 89 | 90 | seqs = seq(1,nrow(data),2) 91 | plot(density(data[seqs,"v1_1"]),main="V1_1 posterior density") 92 | -------------------------------------------------------------------------------- /Chapter02/heights.csv: -------------------------------------------------------------------------------- 1 | Sample,Height 2 | 1,183.5 3 | 1,191.3 4 | 1,182.3 5 | 1,184.3 6 | 1,177.8 7 | 1,188.2 8 | 1,162.8 9 | 1,195.2 10 | 1,189.8 11 | 1,172.9 12 | 1,175.0 13 | 1,186.2 14 | 1,179.2 15 | 1,183.5 16 | 1,168.0 17 | 1,177.6 18 | 1,182.8 19 | 1,189.4 20 | 1,185.0 21 | 1,184.9 22 | 1,174.1 23 | 1,178.4 24 | 1,207.4 25 | 1,165.9 26 | 1,182.6 27 | 1,175.6 28 | 1,161.0 29 | 1,164.9 30 | 1,201.7 31 | 1,183.7 32 | 1,184.6 33 | 1,176.4 34 | 1,182.4 35 | 1,154.8 36 | 1,171.0 37 | 1,186.9 38 | 1,182.6 39 | 1,187.4 40 | 1,185.0 41 | 1,172.1 42 | 1,169.2 43 | 1,191.3 44 | 1,172.6 45 | 1,195.1 46 | 1,167.7 47 | 1,195.5 48 | 1,172.9 49 | 1,160.2 50 | 1,190.5 51 | 1,160.2 52 | 1,193.3 53 | 1,177.6 54 | 1,169.1 55 | 1,202.4 56 | 1,185.4 57 | 1,169.9 58 | 1,167.7 59 | 1,172.9 60 | 1,192.3 61 | 1,176.4 62 | 1,183.9 63 | 1,196.6 64 | 1,173.6 65 | 1,202.3 66 | 1,165.5 67 | 1,176.7 68 | 1,169.2 69 | 1,191.9 70 | 1,169.0 71 | 1,165.6 72 | 1,175.8 73 | 1,174.5 74 | 1,173.8 75 | 1,175.1 76 | 1,191.0 77 | 1,186.6 78 | 1,170.1 79 | 1,184.8 80 | 1,173.9 81 | 1,169.7 82 | 1,169.9 83 | 1,178.3 84 | 1,190.9 85 | 1,175.1 86 | 1,177.8 87 | 1,181.3 88 | 1,176.1 89 | 1,189.6 90 | 1,178.5 91 | 1,189.4 92 | 1,173.4 93 | 1,181.4 94 | 1,179.6 95 | 1,182.8 96 | 1,162.3 97 | 1,174.8 98 | 1,159.5 99 | 1,188.4 100 | 1,192.2 101 | 2,181.3 102 | 2,164.2 103 | 2,169.2 104 | 2,171.5 105 | 2,174.9 106 | 2,189.3 107 | 2,175.1 108 | 2,194.0 109 | 2,194.5 110 | 2,173.7 111 | 2,187.3 112 | 2,179.4 113 | 2,170.9 114 | 2,201.6 115 | 2,179.0 116 | 2,176.3 117 | 2,169.7 118 | 2,175.9 119 | 2,194.0 120 | 2,173.5 121 | 2,190.1 122 | 2,163.3 123 | 2,167.6 124 | 2,181.7 125 | 2,183.5 126 | 2,191.8 127 | 2,181.8 128 | 2,188.7 129 | 2,182.6 130 | 2,170.7 131 | 2,174.2 132 | 2,164.5 133 | 2,205.8 134 | 2,174.4 135 | 2,177.9 136 | 2,180.7 137 | 2,186.6 138 | 2,181.6 139 | 2,198.3 140 | 2,202.1 141 | 2,151.4 142 | 2,173.9 143 | 2,189.1 144 | 2,178.6 145 | 2,165.0 146 | 2,180.2 147 | 2,176.2 148 | 2,171.6 149 | 2,163.4 150 | 2,177.9 151 | 2,169.9 152 | 2,175.7 153 | 2,187.3 154 | 2,190.0 155 | 2,186.5 156 | 2,191.6 157 | 2,169.5 158 | 2,172.5 159 | 2,177.9 160 | 2,168.5 161 | 2,177.2 162 | 2,185.2 163 | 2,183.3 164 | 2,194.9 165 | 2,187.7 166 | 2,170.4 167 | 2,170.8 168 | 2,179.9 169 | 2,186.2 170 | 2,189.4 171 | 2,183.9 172 | 2,188.5 173 | 2,170.5 174 | 2,182.1 175 | 2,174.9 176 | 2,187.5 177 | 2,192.1 178 | 2,190.2 179 | 2,178.7 180 | 2,175.3 181 | 2,185.7 182 | 2,180.5 183 | 2,154.4 184 | 2,180.8 185 | 2,191.6 186 | 2,173.4 187 | 2,183.2 188 | 2,186.4 189 | 2,185.9 190 | 2,190.3 191 | 2,166.6 192 | 2,182.7 193 | 2,180.6 194 | 2,163.3 195 | 2,175.9 196 | 2,169.3 197 | 2,183.5 198 | 2,172.8 199 | 2,181.6 200 | 2,174.5 -------------------------------------------------------------------------------- /Chapter05/heights.csv: -------------------------------------------------------------------------------- 1 | Sample,Height 2 | 1,183.5 3 | 1,191.3 4 | 1,182.3 5 | 1,184.3 6 | 1,177.8 7 | 1,188.2 8 | 1,162.8 9 | 1,195.2 10 | 1,189.8 11 | 1,172.9 12 | 1,175.0 13 | 1,186.2 14 | 1,179.2 15 | 1,183.5 16 | 1,168.0 17 | 1,177.6 18 | 1,182.8 19 | 1,189.4 20 | 1,185.0 21 | 1,184.9 22 | 1,174.1 23 | 1,178.4 24 | 1,207.4 25 | 1,165.9 26 | 1,182.6 27 | 1,175.6 28 | 1,161.0 29 | 1,164.9 30 | 1,201.7 31 | 1,183.7 32 | 1,184.6 33 | 1,176.4 34 | 1,182.4 35 | 1,154.8 36 | 1,171.0 37 | 1,186.9 38 | 1,182.6 39 | 1,187.4 40 | 1,185.0 41 | 1,172.1 42 | 1,169.2 43 | 1,191.3 44 | 1,172.6 45 | 1,195.1 46 | 1,167.7 47 | 1,195.5 48 | 1,172.9 49 | 1,160.2 50 | 1,190.5 51 | 1,160.2 52 | 1,193.3 53 | 1,177.6 54 | 1,169.1 55 | 1,202.4 56 | 1,185.4 57 | 1,169.9 58 | 1,167.7 59 | 1,172.9 60 | 1,192.3 61 | 1,176.4 62 | 1,183.9 63 | 1,196.6 64 | 1,173.6 65 | 1,202.3 66 | 1,165.5 67 | 1,176.7 68 | 1,169.2 69 | 1,191.9 70 | 1,169.0 71 | 1,165.6 72 | 1,175.8 73 | 1,174.5 74 | 1,173.8 75 | 1,175.1 76 | 1,191.0 77 | 1,186.6 78 | 1,170.1 79 | 1,184.8 80 | 1,173.9 81 | 1,169.7 82 | 1,169.9 83 | 1,178.3 84 | 1,190.9 85 | 1,175.1 86 | 1,177.8 87 | 1,181.3 88 | 1,176.1 89 | 1,189.6 90 | 1,178.5 91 | 1,189.4 92 | 1,173.4 93 | 1,181.4 94 | 1,179.6 95 | 1,182.8 96 | 1,162.3 97 | 1,174.8 98 | 1,159.5 99 | 1,188.4 100 | 1,192.2 101 | 2,181.3 102 | 2,164.2 103 | 2,169.2 104 | 2,171.5 105 | 2,174.9 106 | 2,189.3 107 | 2,175.1 108 | 2,194.0 109 | 2,194.5 110 | 2,173.7 111 | 2,187.3 112 | 2,179.4 113 | 2,170.9 114 | 2,201.6 115 | 2,179.0 116 | 2,176.3 117 | 2,169.7 118 | 2,175.9 119 | 2,194.0 120 | 2,173.5 121 | 2,190.1 122 | 2,163.3 123 | 2,167.6 124 | 2,181.7 125 | 2,183.5 126 | 2,191.8 127 | 2,181.8 128 | 2,188.7 129 | 2,182.6 130 | 2,170.7 131 | 2,174.2 132 | 2,164.5 133 | 2,205.8 134 | 2,174.4 135 | 2,177.9 136 | 2,180.7 137 | 2,186.6 138 | 2,181.6 139 | 2,198.3 140 | 2,202.1 141 | 2,151.4 142 | 2,173.9 143 | 2,189.1 144 | 2,178.6 145 | 2,165.0 146 | 2,180.2 147 | 2,176.2 148 | 2,171.6 149 | 2,163.4 150 | 2,177.9 151 | 2,169.9 152 | 2,175.7 153 | 2,187.3 154 | 2,190.0 155 | 2,186.5 156 | 2,191.6 157 | 2,169.5 158 | 2,172.5 159 | 2,177.9 160 | 2,168.5 161 | 2,177.2 162 | 2,185.2 163 | 2,183.3 164 | 2,194.9 165 | 2,187.7 166 | 2,170.4 167 | 2,170.8 168 | 2,179.9 169 | 2,186.2 170 | 2,189.4 171 | 2,183.9 172 | 2,188.5 173 | 2,170.5 174 | 2,182.1 175 | 2,174.9 176 | 2,187.5 177 | 2,192.1 178 | 2,190.2 179 | 2,178.7 180 | 2,175.3 181 | 2,185.7 182 | 2,180.5 183 | 2,154.4 184 | 2,180.8 185 | 2,191.6 186 | 2,173.4 187 | 2,183.2 188 | 2,186.4 189 | 2,185.9 190 | 2,190.3 191 | 2,166.6 192 | 2,182.7 193 | 2,180.6 194 | 2,163.3 195 | 2,175.9 196 | 2,169.3 197 | 2,183.5 198 | 2,172.8 199 | 2,181.6 200 | 2,174.5 -------------------------------------------------------------------------------- /Chapter08/sample_random_regression.csv: -------------------------------------------------------------------------------- 1 | clientid,deal_size,salespeople_involved,time_spent_deal,, 2 | 1,60,6,4.80,-0.592525083,0.102 3 | 1,64,6,6.97,-0.592525083,0.102 4 | 1,48,7,8.46,-0.592525083,0.102 5 | 1,76,4,6.77,-0.592525083,0.102 6 | 1,65,5,9.79,-0.592525083,0.102 7 | 1,57,4,2.39,-0.592525083,0.102 8 | 1,45,4,1.55,-0.592525083,0.102 9 | 1,68,6,0.67,-0.592525083,0.102 10 | 1,63,6,2.31,-0.592525083,0.102 11 | 1,50,5,1.95,-0.592525083,0.102 12 | 2,57,3,7.83,-0.292415001,-0.28 13 | 2,62,1,6.41,-0.292415001,-0.28 14 | 2,57,1,5.59,-0.292415001,-0.28 15 | 2,70,6,7.33,-0.292415001,-0.28 16 | 2,59,6,1.12,-0.292415001,-0.28 17 | 2,51,6,0.15,-0.292415001,-0.28 18 | 2,65,4,2.92,-0.292415001,-0.28 19 | 2,58,2,0.87,-0.292415001,-0.28 20 | 2,55,6,1.39,-0.292415001,-0.28 21 | 2,64,5,8.16,-0.292415001,-0.28 22 | 3,82,5,7.50,0.117047428,-0.04 23 | 3,53,1,1.39,0.117047428,-0.04 24 | 3,61,6,2.88,0.117047428,-0.04 25 | 3,80,5,9.26,0.117047428,-0.04 26 | 3,76,3,2.00,0.117047428,-0.04 27 | 3,82,5,8.18,0.117047428,-0.04 28 | 3,95,5,8.64,0.117047428,-0.04 29 | 3,91,1,5.31,0.117047428,-0.04 30 | 3,62,2,4.04,0.117047428,-0.04 31 | 3,64,3,4.93,0.117047428,-0.04 32 | 4,69,2,6.45,-0.781844856,-0.94 33 | 4,54,6,2.53,-0.781844856,-0.94 34 | 4,57,6,5.71,-0.781844856,-0.94 35 | 4,71,1,9.27,-0.781844856,-0.94 36 | 4,55,6,5.49,-0.781844856,-0.94 37 | 4,90,4,7.45,-0.781844856,-0.94 38 | 4,61,6,5.56,-0.781844856,-0.94 39 | 4,48,1,1.14,-0.781844856,-0.94 40 | 4,40,2,6.36,-0.781844856,-0.94 41 | 4,49,6,0.10,-0.781844856,-0.94 42 | 5,64,1,8.80,1.790357276,-2.4 43 | 5,95,6,5.11,1.790357276,-2.4 44 | 5,76,2,6.16,1.790357276,-2.4 45 | 5,66,6,2.16,1.790357276,-2.4 46 | 5,56,1,4.86,1.790357276,-2.4 47 | 5,77,1,8.06,1.790357276,-2.4 48 | 5,123,7,9.32,1.790357276,-2.4 49 | 5,100,4,9.86,1.790357276,-2.4 50 | 5,90,1,9.12,1.790357276,-2.4 51 | 5,81,2,4.65,1.790357276,-2.4 52 | 6,87,1,9.82,1.512400283,0.91 53 | 6,71,1,7.16,1.512400283,0.91 54 | 6,88,4,5.61,1.512400283,0.91 55 | 6,73,4,4.53,1.512400283,0.91 56 | 6,97,5,7.77,1.512400283,0.91 57 | 6,115,2,9.08,1.512400283,0.91 58 | 6,81,4,4.15,1.512400283,0.91 59 | 6,74,3,1.49,1.512400283,0.91 60 | 6,89,5,6.31,1.512400283,0.91 61 | 6,67,2,4.34,1.512400283,0.91 62 | 7,37,1,4.88,-1.511680644,1.223 63 | 7,65,5,9.03,-1.511680644,1.223 64 | 7,47,2,4.12,-1.511680644,1.223 65 | 7,57,3,6.61,-1.511680644,1.223 66 | 7,56,1,4.98,-1.511680644,1.223 67 | 7,48,6,9.05,-1.511680644,1.223 68 | 7,54,3,4.58,-1.511680644,1.223 69 | 7,42,3,4.26,-1.511680644,1.223 70 | 7,67,1,8.81,-1.511680644,1.223 71 | 7,46,1,3.11,-1.511680644,1.223 72 | 8,94,3,2.03,1.966918568,2.054 73 | 8,118,1,9.42,1.966918568,2.054 74 | 8,83,3,0.78,1.966918568,2.054 75 | 8,80,6,0.19,1.966918568,2.054 76 | 8,72,5,2.26,1.966918568,2.054 77 | 8,86,1,8.19,1.966918568,2.054 78 | 8,73,4,3.48,1.966918568,2.054 79 | 8,80,1,7.40,1.966918568,2.054 80 | 8,82,1,8.19,1.966918568,2.054 81 | 8,87,4,4.94,1.966918568,2.054 82 | 9,102,6,4.96,1.297036668,1.12 83 | 9,73,2,7.37,1.297036668,1.12 84 | 9,103,6,6.59,1.297036668,1.12 85 | 9,63,2,3.24,1.297036668,1.12 86 | 9,108,6,8.93,1.297036668,1.12 87 | 9,73,2,2.93,1.297036668,1.12 88 | 9,79,2,6.91,1.297036668,1.12 89 | 9,104,4,9.81,1.297036668,1.12 90 | 9,62,1,1.63,1.297036668,1.12 91 | 9,71,6,0.46,1.297036668,1.12 92 | 10,61,3,5.60,-1.563016568,-1.14 93 | 10,65,6,8.14,-1.563016568,-1.14 94 | 10,80,3,7.69,-1.563016568,-1.14 95 | 10,64,6,8.26,-1.563016568,-1.14 96 | 10,55,5,2.29,-1.563016568,-1.14 97 | 10,58,1,5.33,-1.563016568,-1.14 98 | 10,39,5,3.65,-1.563016568,-1.14 99 | 10,69,7,6.37,-1.563016568,-1.14 100 | 10,72,6,2.91,-1.563016568,-1.14 101 | 10,56,4,0.32,-1.563016568,-1.14 102 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # R Statistics Cookbook 5 | 6 | R Statistics Cookbook 7 | 8 | This is the code repository for [R Statistics Cookbook](https://prod.packtpub.com/in/big-data-and-business-intelligence/r-statistics-cookbook?utm_source=github&utm_medium=repository&utm_campaign=9781789802566), published by Packt. 9 | 10 | **Over 100 recipes for performing complex statistical operations with R 3.5** 11 | 12 | ## What is this book about? 13 | R is a popular programming language for developing statistical software. This book will be a useful guide to solving common and not-so-common challenges in statistics. With this book, you'll be equipped to confidently perform essential statistical procedures across your organization with the help of cutting-edge statistical tools. 14 | 15 | This book covers the following exciting features: 16 | * Become well versed with recipes that will help you interpret plots with R 17 | * Formulate advanced statistical models in R to understand its concepts 18 | * Perform Bayesian regression to predict models and input missing data 19 | * Use time series analysis for modelling and forecasting temporal data 20 | * Implement a range of regression techniques for efficient data modelling 21 | 22 | If you feel this book is for you, get your [copy](https://www.amazon.com/dp/1789802563) today! 23 | 24 | https://www.packtpub.com/ 25 | 26 | ## Instructions and Navigations 27 | All of the code is organized into folders. For example, Chapter02. 28 | 29 | The code will look like the following: 30 | ``` 31 | library(bbmle) 32 | N <- 1000 33 | xx <- rgamma(N, shape=20,rate=2) 34 | ``` 35 | 36 | **Following is what you need for this book:** 37 | If you are a quantitative researcher, statistician, data analyst, or data scientist looking to tackle various challenges in statistics, this book is what you need! Proficiency in R programming and basic knowledge of linear algebra is necessary to follow along the recipes covered in this book. 38 | 39 | With the following software and hardware list you can run all code files present in the book (Chapter 1-15). 40 | 41 | ### Software and Hardware List 42 | 43 | | Chapter | Software required | OS required | 44 | | -------- | ------------------------------------| -----------------------------------| 45 | | 1-10 | RStudio | Windows, Mac OS X, and Linux (Any) | 46 | 47 | 48 | We also provide a PDF file that has color images of the screenshots/diagrams used in this book. [Click here to download it](https://www.packtpub.com/sites/default/files/downloads/9781789802566_ColorImages.pdf). 49 | 50 | ### Related products 51 | * Generative Adversarial Networks Projects [[Packt]](https://prod.packtpub.com/in/big-data-and-business-intelligence/generative-adversarial-networks-projects?utm_source=github&utm_medium=repository&utm_campaign=9781789136678) [[Amazon]](https://www.amazon.com/dp/1789136679) 52 | 53 | * Generative Adversarial Networks Cookbook [[Packt]](https://prod.packtpub.com/in/big-data-and-business-intelligence/generative-adversarial-networks-cookbook?utm_source=github&utm_medium=repository&utm_campaign=9781789139907) [[Amazon]](https://www.amazon.com/dp/1789139902) 54 | 55 | ## Get to Know the Author 56 | **Francisco Juretig** has worked for over a decade in a variety of industries such as retail, gambling and finance deploying data-science solutions. He has written several R packages, and is a frequent contributor to the open source community. 57 | 58 | 59 | ### Suggestions and Feedback 60 | [Click here](https://docs.google.com/forms/d/e/1FAIpQLSdy7dATC6QmEL81FIUuymZ0Wy9vH1jHkvpY57OiMeKGqib_Ow/viewform) if you have any feedback or suggestions. 61 | ### Download a free PDF 62 | 63 | If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.
64 |

https://packt.link/free-ebook/9781789802566

-------------------------------------------------------------------------------- /Chapter03/shoes_sales.csv: -------------------------------------------------------------------------------- 1 | Sales,women_apparel_price,male_apparel_price,shoes_female_price,shoes_male_price,shoes_kids_prices,shoes_male_price_b,prices_shoes 2 | 733,101.522256963703,123.522256963703,29,10,37,10,76 3 | 764,75.6337286151567,99.6337286151567,17,29,24,29,70 4 | 487,81.4096037618633,108.409603761863,12,10,18,10,40 5 | 648,79.6547921841075,109.654792184107,12,24,20,24,56 6 | 569,98.6176381759938,128.617638175994,13,13,16,13,42 7 | 590,85.7508835240628,96.7508835240628,11,21,20,21,52 8 | 763,75.5145745470355,100.514574547036,24,23,32,23,79 9 | 831,117.330513296075,144.330513296075,29,19,34,19,82 10 | 605,69.6591874534066,89.6591874534066,21,13,29,13,63 11 | 587,36.609477622768,66.609477622768,23,17,28,17,68 12 | 708,106.910416973556,116.910416973556,27,14,32,14,73 13 | 675,120.246185206747,139.246185206747,13,21,18,21,52 14 | 737,91.3480232037557,112.348023203756,20,25,23,25,68 15 | 721,98.5768111544583,122.576811154458,21,19,30,19,70 16 | 467,49.8008697641539,76.8008697641539,14,11,21,11,46 17 | 783,125.833585735312,142.833585735312,22,19,30,19,71 18 | 674,97.745877258861,121.745877258861,16,19,24,19,59 19 | 714,102.177915221486,121.177915221486,20,22,25,22,67 20 | 743,94.2494483424059,108.249448342406,29,14,33,14,76 21 | 573,74.7747802931341,84.7747802931341,14,17,23,17,54 22 | 887,102.011702053966,126.011702053966,30,26,35,26,91 23 | 790,99.438207849109,116.438207849109,16,30,22,30,68 24 | 627,118.614682594558,131.614682594558,20,13,23,13,56 25 | 704,110.680379362652,124.680379362652,12,26,18,26,56 26 | 857,118.912678666812,133.912678666812,22,27,30,27,79 27 | 845,107.83694778134,136.83694778134,28,21,36,21,85 28 | 922,150.188691073569,178.188691073569,24,21,33,21,78 29 | 677,54.8849949485408,73.8849949485409,18,28,23,28,69 30 | 632,119.553600986545,130.553600986545,10,18,17,18,45 31 | 777,93.3731819158813,103.373181915881,30,18,35,18,83 32 | 772,100.451894794051,122.451894794051,27,22,31,22,80 33 | 598,105.197188552337,134.197188552337,17,12,22,12,51 34 | 545,70.7509600515471,87.7509600515471,19,12,25,12,56 35 | 745,142.947385374715,162.947385374715,15,18,20,18,53 36 | 615,82.0480083145985,99.0480083145985,21,15,29,15,65 37 | 584,116.075558953225,133.075558953225,11,15,20,15,46 38 | 648,98.5136715901238,121.513671590124,13,22,18,22,53 39 | 781,80.8562829941054,105.856282994105,25,24,34,24,83 40 | 617,101.091026867063,127.091026867063,16,16,20,16,52 41 | 402,52.4624499374522,76.4624499374522,10,12,15,12,37 42 | 1016,144.933308840353,163.933308840353,25,30,34,30,89 43 | 614,142.350414956376,165.350414956376,15,10,18,10,43 44 | 609,140.365990883539,150.365990883539,15,11,19,11,45 45 | 561,43.1380307278586,55.1380307278586,29,11,32,11,72 46 | 707,112.401911170561,132.401911170561,16,19,23,19,58 47 | 690,52.4893461844818,72.4893461844818,29,16,35,16,80 48 | 602,122.632474083246,150.632474083246,10,15,16,15,41 49 | 477,35.5375905608796,64.5375905608796,20,11,24,11,55 50 | 940,177.152061535702,198.152061535702,27,17,36,17,80 51 | 602,123.492212910667,140.492212910667,13,13,22,13,48 52 | 761,111.358240890253,121.358240890253,21,19,30,19,70 53 | 772,83.7000018380398,107.70000183804,20,30,23,30,73 54 | 588,99.3413351159313,119.341335115931,14,18,20,18,52 55 | 826,99.3910314916568,126.391031491657,19,30,28,30,77 56 | 593,155.428517093059,181.428517093059,10,12,16,12,38 57 | 595,110.066924977856,127.066924977856,13,18,18,18,49 58 | 777,128.159700213788,139.159700213788,18,24,25,24,67 59 | 773,75.7355324451546,96.7355324451546,25,24,31,24,80 60 | 917,116.582153540398,144.582153540398,28,26,31,26,85 61 | 857,100.569899480672,115.569899480672,24,30,27,30,81 62 | 603,89.8288042016055,118.828804201605,12,18,19,18,49 63 | 863,104.985267135647,128.985267135647,26,22,33,22,81 64 | 706,119.089309348372,142.089309348372,23,10,30,10,63 65 | 651,128.160444497948,155.160444497948,11,20,14,20,45 66 | 832,99.1113618331379,116.111361833138,25,27,29,27,81 67 | 910,112.29887519794,134.29887519794,29,26,33,26,88 68 | 1047,161.592080973963,180.592080973963,30,27,35,27,92 69 | 759,131.397889119,156.397889119,21,17,30,17,68 70 | 746,62.6311319786135,80.6311319786135,22,28,28,28,78 71 | 650,118.150777105476,132.150777105476,18,12,24,12,54 72 | 799,81.8103491326454,95.8103491326454,26,23,35,23,84 73 | 542,5.11606133192141,22.1160613319214,19,21,24,21,64 74 | 804,132.751358497863,143.751358497863,24,18,29,18,71 75 | 700,68.3702200057875,90.3702200057875,21,21,29,21,71 76 | 836,91.5565045758449,120.556504575845,24,24,31,24,79 77 | 575,93.0985089783212,119.098508978321,17,10,23,10,50 78 | 722,107.929153287696,132.929153287696,20,17,24,17,61 79 | 643,108.081498390115,135.081498390115,18,18,23,18,59 -------------------------------------------------------------------------------- /Chapter10/subway_data.csv: -------------------------------------------------------------------------------- 1 | id,people,state,weather 2 | 1,51,open,sunny 3 | 2,60,open,sunny 4 | 3,45,open,sunny 5 | 4,65,open,sunny 6 | 5,53,open,sunny 7 | 6,1,closed,sunny 8 | 7,0,closed,rainy 9 | 8,0,closed,sunny 10 | 9,0,closed,sunny 11 | 10,1,closed,sunny 12 | 11,10,closed,sunny 13 | 12,15,closed,sunny 14 | 13,20,closed,sunny 15 | 14,40,closed,sunny 16 | 15,41,open,sunny 17 | 16,47,open,sunny 18 | 17,46,open,sunny 19 | 18,57,open,sunny 20 | 19,62,open,sunny 21 | 20,44,open,sunny 22 | 21,46,open,sunny 23 | 22,54,open,sunny 24 | 23,41,open,sunny 25 | 24,51,open,sunny 26 | 25,45,open,sunny 27 | 26,60,open,sunny 28 | 27,51,open,sunny 29 | 28,43,open,sunny 30 | 29,57,open,sunny 31 | 30,46,open,sunny 32 | 31,44,open,sunny 33 | 32,33,open,sunny 34 | 33,59,open,sunny 35 | 34,45,open,sunny 36 | 35,48,open,sunny 37 | 36,54,open,sunny 38 | 37,53,open,sunny 39 | 38,39,open,sunny 40 | 39,47,open,sunny 41 | 40,52,open,sunny 42 | 41,54,open,sunny 43 | 42,54,open,sunny 44 | 43,51,open,sunny 45 | 44,38,open,sunny 46 | 45,66,open,sunny 47 | 46,53,open,sunny 48 | 47,40,open,sunny 49 | 48,57,open,sunny 50 | 49,48,open,sunny 51 | 50,63,open,sunny 52 | 51,38,open,sunny 53 | 52,47,open,sunny 54 | 53,41,open,sunny 55 | 54,45,open,sunny 56 | 55,46,open,sunny 57 | 56,56,open,sunny 58 | 57,2,closed,sunny 59 | 58,3,closed,sunny 60 | 59,13,closed,sunny 61 | 60,1,closed,rainy 62 | 61,2,closed,sunny 63 | 62,25,closed,sunny 64 | 63,19,closed,sunny 65 | 64,2,closed,sunny 66 | 65,5,closed,sunny 67 | 66,51,open,sunny 68 | 67,47,open,sunny 69 | 68,42,open,sunny 70 | 69,55,open,sunny 71 | 70,49,open,sunny 72 | 71,53,open,sunny 73 | 72,57,open,sunny 74 | 73,44,open,sunny 75 | 74,39,open,sunny 76 | 75,60,open,sunny 77 | 76,55,open,sunny 78 | 77,53,open,sunny 79 | 78,41,open,sunny 80 | 79,59,open,sunny 81 | 80,53,open,sunny 82 | 81,53,open,sunny 83 | 82,50,open,sunny 84 | 83,18,open,rainy 85 | 84,60,open,sunny 86 | 85,56,open,sunny 87 | 86,58,open,sunny 88 | 87,44,open,sunny 89 | 88,56,open,sunny 90 | 89,3,closed,sunny 91 | 90,4,closed,sunny 92 | 91,13,closed,sunny 93 | 92,1,closed,sunny 94 | 93,3,closed,sunny 95 | 94,20,closed,sunny 96 | 95,10,closed,sunny 97 | 96,1,closed,sunny 98 | 97,0,closed,sunny 99 | 98,57,open,sunny 100 | 99,51,open,sunny 101 | 100,54,open,sunny 102 | 101,51,open,sunny 103 | 102,55,open,sunny 104 | 103,49,open,sunny 105 | 104,4,open,rainy 106 | 105,5,open,rainy 107 | 106,4,open,rainy 108 | 107,39,open,sunny 109 | 108,47,open,sunny 110 | 109,40,open,sunny 111 | 110,56,open,sunny 112 | 111,43,open,sunny 113 | 112,0,closed,rainy 114 | 113,13,closed,sunny 115 | 114,10,closed,sunny 116 | 115,19,closed,sunny 117 | 116,17,closed,sunny 118 | 117,1,closed,sunny 119 | 118,9,closed,sunny 120 | 119,19,closed,sunny 121 | 120,12,closed,sunny 122 | 121,48,open,sunny 123 | 122,46,open,sunny 124 | 123,37,open,sunny 125 | 124,51,open,sunny 126 | 125,44,open,sunny 127 | 126,53,open,sunny 128 | 127,47,open,sunny 129 | 128,51,open,sunny 130 | 129,43,open,sunny 131 | 130,52,open,sunny 132 | 131,26,open,sunny 133 | 132,10,open,sunny 134 | 133,7,closed,sunny 135 | 134,1,closed,sunny 136 | 135,9,closed,sunny 137 | 136,5,closed,sunny 138 | 137,15,closed,sunny 139 | 138,13,closed,sunny 140 | 139,53,open,sunny 141 | 140,51,open,sunny 142 | 141,43,open,sunny 143 | 142,41,open,sunny 144 | 143,49,open,sunny 145 | 144,58,open,sunny 146 | 145,49,open,sunny 147 | 146,41,open,sunny 148 | 147,50,open,sunny 149 | 148,50,open,sunny 150 | 149,48,open,sunny 151 | 150,49,open,sunny 152 | 151,51,open,sunny 153 | 152,62,open,sunny 154 | 153,54,open,sunny 155 | 154,51,open,sunny 156 | 155,59,open,sunny 157 | 156,50,open,sunny 158 | 157,39,open,sunny 159 | 158,56,open,sunny 160 | 159,51,open,sunny 161 | 160,51,open,sunny 162 | 161,55,open,sunny 163 | 162,55,open,sunny 164 | 163,45,open,sunny 165 | 164,50,open,sunny 166 | 165,58,open,sunny 167 | 166,48,open,sunny 168 | 167,50,open,sunny 169 | 168,42,open,sunny 170 | 169,45,open,sunny 171 | 170,60,open,sunny 172 | 171,43,open,sunny 173 | 172,48,open,sunny 174 | 173,49,open,sunny 175 | 174,53,open,sunny 176 | 175,53,open,sunny 177 | 176,51,open,sunny 178 | 177,58,open,sunny 179 | 178,49,open,sunny 180 | 179,41,open,sunny 181 | 180,45,open,sunny 182 | 181,50,open,sunny 183 | 182,56,open,sunny 184 | 183,54,open,sunny 185 | 184,54,open,sunny 186 | 185,55,open,sunny 187 | 186,43,open,sunny 188 | 187,54,open,sunny 189 | 188,45,open,sunny 190 | 189,44,open,sunny 191 | 190,51,open,sunny 192 | 191,53,open,sunny 193 | 192,48,open,sunny 194 | 193,40,open,sunny 195 | 194,57,open,sunny 196 | 195,37,open,sunny 197 | 196,56,open,sunny 198 | 197,51,open,sunny 199 | 198,56,open,sunny 200 | 199,42,open,sunny 201 | 200,52,open,sunny 202 | -------------------------------------------------------------------------------- /Chapter10/subway_data_extended.csv: -------------------------------------------------------------------------------- 1 | id,people,state,weather,machinery_road 2 | 1,51,open,sunny,0 3 | 2,60,open,sunny,0 4 | 3,45,open,sunny,0 5 | 4,65,open,sunny,0 6 | 5,53,open,sunny,0 7 | 6,1,closed,sunny,1 8 | 7,0,closed,rainy,0 9 | 8,0,closed,sunny,1 10 | 9,0,closed,sunny,1 11 | 10,1,closed,sunny,1 12 | 11,10,closed,sunny,1 13 | 12,15,closed,sunny,1 14 | 13,20,closed,sunny,0 15 | 14,40,closed,sunny,1 16 | 15,41,open,sunny,1 17 | 16,47,open,sunny,0 18 | 17,46,open,sunny,0 19 | 18,57,open,sunny,1 20 | 19,62,open,sunny,0 21 | 20,44,open,sunny,0 22 | 21,46,open,sunny,1 23 | 22,54,open,sunny,0 24 | 23,41,open,sunny,0 25 | 24,51,open,sunny,0 26 | 25,45,open,sunny,0 27 | 26,60,open,sunny,0 28 | 27,51,open,sunny,0 29 | 28,43,open,sunny,0 30 | 29,57,open,sunny,0 31 | 30,46,open,sunny,0 32 | 31,44,open,sunny,0 33 | 32,33,open,sunny,0 34 | 33,59,open,sunny,0 35 | 34,45,open,sunny,0 36 | 35,48,open,sunny,0 37 | 36,54,open,sunny,0 38 | 37,53,open,sunny,0 39 | 38,39,open,sunny,0 40 | 39,47,open,sunny,0 41 | 40,52,open,sunny,0 42 | 41,54,open,sunny,0 43 | 42,54,open,sunny,0 44 | 43,51,open,sunny,0 45 | 44,38,open,sunny,0 46 | 45,66,open,sunny,0 47 | 46,53,open,sunny,0 48 | 47,40,open,sunny,0 49 | 48,57,open,sunny,0 50 | 49,48,open,sunny,0 51 | 50,63,open,sunny,0 52 | 51,38,open,sunny,0 53 | 52,47,open,sunny,1 54 | 53,41,open,sunny,1 55 | 54,45,open,sunny,1 56 | 55,46,open,sunny,0 57 | 56,56,open,sunny,0 58 | 57,2,closed,sunny,1 59 | 58,3,closed,sunny,1 60 | 59,13,closed,sunny,0 61 | 60,1,closed,rainy,1 62 | 61,2,closed,sunny,1 63 | 62,25,closed,sunny,1 64 | 63,19,closed,sunny,1 65 | 64,2,closed,sunny,1 66 | 65,5,closed,sunny,0 67 | 66,51,open,sunny,1 68 | 67,47,open,sunny,0 69 | 68,42,open,sunny,0 70 | 69,55,open,sunny,0 71 | 70,49,open,sunny,0 72 | 71,53,open,sunny,0 73 | 72,57,open,sunny,0 74 | 73,44,open,sunny,0 75 | 74,39,open,sunny,0 76 | 75,60,open,sunny,0 77 | 76,55,open,sunny,0 78 | 77,53,open,sunny,0 79 | 78,41,open,sunny,0 80 | 79,59,open,sunny,0 81 | 80,53,open,sunny,0 82 | 81,53,open,sunny,0 83 | 82,50,open,sunny,0 84 | 83,18,open,rainy,0 85 | 84,60,open,sunny,0 86 | 85,56,open,sunny,0 87 | 86,58,open,sunny,0 88 | 87,44,open,sunny,1 89 | 88,56,open,sunny,0 90 | 89,3,closed,sunny,1 91 | 90,4,closed,sunny,0 92 | 91,13,closed,sunny,1 93 | 92,1,closed,sunny,0 94 | 93,3,closed,sunny,1 95 | 94,20,closed,sunny,1 96 | 95,10,closed,sunny,1 97 | 96,1,closed,sunny,1 98 | 97,0,closed,sunny,0 99 | 98,57,open,sunny,1 100 | 99,51,open,sunny,0 101 | 100,54,open,sunny,0 102 | 101,51,open,sunny,0 103 | 102,55,open,sunny,0 104 | 103,49,open,sunny,0 105 | 104,4,open,rainy,0 106 | 105,5,open,rainy,0 107 | 106,4,open,rainy,0 108 | 107,39,open,sunny,0 109 | 108,47,open,sunny,0 110 | 109,40,open,sunny,0 111 | 110,56,open,sunny,0 112 | 111,43,open,sunny,0 113 | 112,0,closed,rainy,0 114 | 113,13,closed,sunny,0 115 | 114,10,closed,sunny,0 116 | 115,19,closed,sunny,0 117 | 116,17,closed,sunny,0 118 | 117,1,closed,sunny,0 119 | 118,9,closed,sunny,0 120 | 119,19,closed,sunny,0 121 | 120,12,closed,sunny,0 122 | 121,48,open,sunny,0 123 | 122,46,open,sunny,0 124 | 123,37,open,sunny,0 125 | 124,51,open,sunny,0 126 | 125,44,open,sunny,0 127 | 126,53,open,sunny,0 128 | 127,47,open,sunny,0 129 | 128,51,open,sunny,0 130 | 129,43,open,sunny,0 131 | 130,52,open,sunny,0 132 | 131,26,open,sunny,1 133 | 132,10,open,sunny,1 134 | 133,7,closed,sunny,1 135 | 134,1,closed,sunny,0 136 | 135,9,closed,sunny,1 137 | 136,5,closed,sunny,1 138 | 137,15,closed,sunny,1 139 | 138,13,closed,sunny,1 140 | 139,53,open,sunny,0 141 | 140,51,open,sunny,0 142 | 141,43,open,sunny,0 143 | 142,41,open,sunny,1 144 | 143,49,open,sunny,1 145 | 144,58,open,sunny,0 146 | 145,49,open,sunny,0 147 | 146,41,open,sunny,0 148 | 147,50,open,sunny,0 149 | 148,50,open,sunny,0 150 | 149,48,open,sunny,0 151 | 150,49,open,sunny,0 152 | 151,51,open,sunny,0 153 | 152,62,open,sunny,0 154 | 153,54,open,sunny,0 155 | 154,51,open,sunny,0 156 | 155,59,open,sunny,0 157 | 156,50,open,sunny,0 158 | 157,39,open,sunny,0 159 | 158,56,open,sunny,0 160 | 159,51,open,sunny,0 161 | 160,51,open,sunny,0 162 | 161,55,open,sunny,0 163 | 162,55,open,sunny,0 164 | 163,45,open,sunny,0 165 | 164,50,open,sunny,0 166 | 165,58,open,sunny,0 167 | 166,48,open,sunny,0 168 | 167,50,open,sunny,0 169 | 168,42,open,sunny,0 170 | 169,45,open,sunny,0 171 | 170,60,open,sunny,0 172 | 171,43,open,sunny,0 173 | 172,48,open,sunny,0 174 | 173,49,open,sunny,0 175 | 174,53,open,sunny,0 176 | 175,53,open,sunny,0 177 | 176,51,open,sunny,0 178 | 177,58,open,sunny,0 179 | 178,49,open,sunny,0 180 | 179,41,open,sunny,0 181 | 180,45,open,sunny,0 182 | 181,50,open,sunny,0 183 | 182,56,open,sunny,0 184 | 183,54,open,sunny,0 185 | 184,54,open,sunny,0 186 | 185,55,open,sunny,0 187 | 186,43,open,sunny,0 188 | 187,54,open,sunny,0 189 | 188,45,open,sunny,0 190 | 189,44,open,sunny,0 191 | 190,51,open,sunny,0 192 | 191,53,open,sunny,0 193 | 192,48,open,sunny,0 194 | 193,40,open,sunny,0 195 | 194,57,open,sunny,0 196 | 195,37,open,sunny,0 197 | 196,56,open,sunny,0 198 | 197,51,open,sunny,0 199 | 198,56,open,sunny,0 200 | 199,42,open,sunny,0 201 | 200,52,open,sunny,0 -------------------------------------------------------------------------------- /Chapter02/2wayanova.csv: -------------------------------------------------------------------------------- 1 | Sales,Colour,Font 2 | 51.55528956,Red,Classic 3 | 61.38271415,Red,Classic 4 | 72.03133996,Red,Classic 5 | 75.66350407,Red,Classic 6 | 77.6912943,Red,Classic 7 | 73.01666182,Red,Classic 8 | 88.12315086,Red,Classic 9 | 55.43563912,Red,Classic 10 | 28.55012605,Red,Classic 11 | 53.1329597,Red,Classic 12 | 80.87247584,Red,Classic 13 | 81.1032854,Red,Classic 14 | 85.02793428,Red,Classic 15 | 69.45256788,Red,Classic 16 | 72.8589866,Red,Classic 17 | 69.03194631,Red,Classic 18 | 48.30321887,Red,Classic 19 | 72.60983225,Red,Classic 20 | 80.29253359,Red,Classic 21 | 38.13197027,Red,Classic 22 | 95.57704874,Red,Classic 23 | 340,Red,Classic 24 | 119.9797984,Red,Classic 25 | 102.4241779,Red,Classic 26 | 59.47177924,Red,Classic 27 | 125.5849859,Red,Classic 28 | 51.08005768,Red,Classic 29 | 78.05811458,Red,Classic 30 | 100.8839395,Red,Classic 31 | 78.34179527,Red,Classic 32 | 69.19009556,Red,Classic 33 | 94.98213407,Red,Classic 34 | 42.30437966,Red,Classic 35 | 58.35207069,Red,Classic 36 | 63.61682857,Red,Classic 37 | 88.01569873,Red,Classic 38 | 61.42519074,Red,Classic 39 | 55.44160561,Red,Classic 40 | 103.9091035,Red,Classic 41 | 42.15401976,Red,Classic 42 | 53.81758438,Red,Classic 43 | 67.92610819,Red,Classic 44 | 85.00395348,Red,Classic 45 | 193,Red,Classic 46 | 81.10414273,Red,Classic 47 | 77.47056729,Red,Classic 48 | 132.9080144,Red,Classic 49 | 63.48108774,Red,Classic 50 | 67.37208265,Red,Classic 51 | 104.5192714,Red,Modern 52 | 96.04833505,Red,Modern 53 | 96.53587877,Red,Modern 54 | 102.789017,Red,Modern 55 | 100.9757774,Red,Modern 56 | 65.91259942,Red,Modern 57 | 132.5932314,Red,Modern 58 | 110.0814009,Red,Modern 59 | 124.8885062,Red,Modern 60 | 83.55336245,Red,Modern 61 | 113.5669666,Red,Modern 62 | 86.15729296,Red,Modern 63 | 77.7310556,Red,Modern 64 | 79.15465668,Red,Modern 65 | 95.55362436,Red,Modern 66 | 105.5453313,Red,Modern 67 | 60.49157564,Red,Modern 68 | 70.67171315,Red,Modern 69 | 69.89487811,Red,Modern 70 | 113.3166476,Red,Modern 71 | 102.9987389,Red,Modern 72 | 113.6136972,Red,Modern 73 | 110.1874028,Red,Modern 74 | 88.74237436,Red,Modern 75 | 78.43056824,Red,Modern 76 | 90.65688084,Red,Modern 77 | 131.3726205,Red,Modern 78 | 120.4234878,Red,Modern 79 | 93.88790929,Red,Modern 80 | 69.22518779,Red,Modern 81 | 108.6442509,Red,Modern 82 | 104.2589783,Red,Modern 83 | 108.35622,Red,Modern 84 | 84.38102247,Red,Modern 85 | 78.55016855,Red,Modern 86 | 39.9071844,Red,Modern 87 | 91.13913691,Red,Modern 88 | 87.97156574,Red,Modern 89 | 81.15650365,Red,Modern 90 | 118.4352344,Red,Modern 91 | 97.12804057,Red,Modern 92 | 105.5502096,Red,Modern 93 | 88.33227143,Red,Modern 94 | 94.78788346,Red,Modern 95 | 90.62229798,Red,Modern 96 | 86.82568815,Red,Modern 97 | 83.4450526,Red,Modern 98 | 120.6465961,Red,Modern 99 | 91.79207583,Red,Modern 100 | 99.11007545,Red,Modern 101 | 111.2438738,Red,Modern 102 | 140.4640073,Blue,Classic 103 | 102.6954075,Blue,Classic 104 | 120.991474,Blue,Classic 105 | 103.7315772,Blue,Classic 106 | 101.1475404,Blue,Classic 107 | 110.6471933,Blue,Classic 108 | 104.6170756,Blue,Classic 109 | 112.280418,Blue,Classic 110 | 99.79331967,Blue,Classic 111 | 88.7871995,Blue,Classic 112 | 90.09740248,Blue,Classic 113 | 127.696931,Blue,Classic 114 | 125.731671,Blue,Classic 115 | 87.57916134,Blue,Classic 116 | 107.6455454,Blue,Classic 117 | 102.9891384,Blue,Classic 118 | 133.4178129,Blue,Classic 119 | 123.6875396,Blue,Classic 120 | 110.5625112,Blue,Classic 121 | 101.6165177,Blue,Classic 122 | 115.9985644,Blue,Classic 123 | 124.4791243,Blue,Classic 124 | 121.8930194,Blue,Classic 125 | 134.0959853,Blue,Classic 126 | 119.8919433,Blue,Classic 127 | 96.81985946,Blue,Classic 128 | 117.0584973,Blue,Classic 129 | 82.04259053,Blue,Classic 130 | 119.5440029,Blue,Classic 131 | 104.3035904,Blue,Classic 132 | 115.5666446,Blue,Classic 133 | 121.0640142,Blue,Classic 134 | 105.9814432,Blue,Classic 135 | 117.1033201,Blue,Classic 136 | 88.48067147,Blue,Classic 137 | 90.2894294,Blue,Classic 138 | 99.93900631,Blue,Classic 139 | 124.9366695,Blue,Classic 140 | 157.1150896,Blue,Classic 141 | 127.19668,Blue,Classic 142 | 124.2860847,Blue,Classic 143 | 121.8317774,Blue,Classic 144 | 78.23823575,Blue,Classic 145 | 132.9054338,Blue,Classic 146 | 165.811094,Blue,Classic 147 | 92.77855602,Blue,Classic 148 | 132.4926963,Blue,Classic 149 | 95.36707185,Blue,Classic 150 | 109.2402274,Blue,Classic 151 | 95.69684469,Blue,Modern 152 | 146.4216712,Blue,Modern 153 | 123.6331063,Blue,Modern 154 | 130.0414087,Blue,Modern 155 | 173.5431346,Blue,Modern 156 | 137.5018845,Blue,Modern 157 | 144.1259938,Blue,Modern 158 | 121.1444083,Blue,Modern 159 | 118.9316116,Blue,Modern 160 | 118.3212928,Blue,Modern 161 | 128.254521,Blue,Modern 162 | 140.4922472,Blue,Modern 163 | 122.1303097,Blue,Modern 164 | 139.0856966,Blue,Modern 165 | 102.4937756,Blue,Modern 166 | 151.2655742,Blue,Modern 167 | 129.4190203,Blue,Modern 168 | 148.558303,Blue,Modern 169 | 165.6646252,Blue,Modern 170 | 130.9283228,Blue,Modern 171 | 116.1447149,Blue,Modern 172 | 116.2724516,Blue,Modern 173 | 161.2324523,Blue,Modern 174 | 125.0959929,Blue,Modern 175 | 111.2132314,Blue,Modern 176 | 136.2727547,Blue,Modern 177 | 102.1297392,Blue,Modern 178 | 135.2401051,Blue,Modern 179 | 98.21331784,Blue,Modern 180 | 147.8475899,Blue,Modern 181 | 114.8136805,Blue,Modern 182 | 175.1514637,Blue,Modern 183 | 150.8293959,Blue,Modern 184 | 137.428766,Blue,Modern 185 | 146.1118912,Blue,Modern 186 | 133.1269007,Blue,Modern 187 | 123.8858054,Blue,Modern 188 | 149.3338999,Blue,Modern 189 | 133.989672,Blue,Modern 190 | 139.1888548,Blue,Modern 191 | 156.8894928,Blue,Modern 192 | 122.3889526,Blue,Modern 193 | 138.8236471,Blue,Modern 194 | 126.710213,Blue,Modern 195 | 104.5430354,Blue,Modern 196 | 105.7531029,Blue,Modern 197 | 110.3617477,Blue,Modern 198 | 135.3837893,Blue,Modern 199 | 114.2864604,Blue,Modern 200 | 139.8091304,Blue,Modern 201 | 104.9228669,Blue,Modern 202 | 79.25003336,Blue,Modern 203 | -------------------------------------------------------------------------------- /Chapter07/beerprices.csv: -------------------------------------------------------------------------------- 1 | indice_tiempo,cervezas_m 2 | 1993-01-01,98.6051 3 | 1993-02-01,98.098 4 | 1993-03-01,98.098 5 | 1993-04-01,98.576 6 | 1993-05-01,98.401 7 | 1993-06-01,98.7044 8 | 1993-07-01,98.7044 9 | 1993-08-01,99.7083 10 | 1993-09-01,100.4999 11 | 1993-10-01,101.7951 12 | 1993-11-01,102.7983 13 | 1993-12-01,106.0116 14 | 1994-01-01,104.3543 15 | 1994-02-01,106.8155 16 | 1994-03-01,107.2155 17 | 1994-04-01,107.8689 18 | 1994-05-01,107.8689 19 | 1994-06-01,108.5251 20 | 1994-07-01,108.5251 21 | 1994-08-01,109.0517 22 | 1994-09-01,108.858 23 | 1994-10-01,109.1067 24 | 1994-11-01,111.0078 25 | 1994-12-01,111.9554 26 | 1995-01-01,111.9554 27 | 1995-02-01,112.833 28 | 1995-03-01,113.2224 29 | 1995-04-01,115.9852 30 | 1995-05-01,113.0173 31 | 1995-06-01,113.4018 32 | 1995-07-01,116.24 33 | 1995-08-01,115.2709 34 | 1995-09-01,113.9032 35 | 1995-10-01,113.8977 36 | 1995-11-01,115.0788 37 | 1995-12-01,115.0788 38 | 1996-01-01,119.4317 39 | 1996-02-01,120.6492 40 | 1996-03-01,120.6492 41 | 1996-04-01,120.6492 42 | 1996-05-01,120.6492 43 | 1996-06-01,120.6492 44 | 1996-07-01,121.3813 45 | 1996-08-01,121.9415 46 | 1996-09-01,123.4009 47 | 1996-10-01,123.4009 48 | 1996-11-01,124.8534 49 | 1996-12-01,125.2059 50 | 1997-01-01,125.2059 51 | 1997-02-01,125.2059 52 | 1997-03-01,125.2059 53 | 1997-04-01,125.2059 54 | 1997-05-01,125.2059 55 | 1997-06-01,125.2059 56 | 1997-07-01,125.2059 57 | 1997-08-01,125.9861 58 | 1997-09-01,126.9846 59 | 1997-10-01,126.9846 60 | 1997-11-01,127.1601 61 | 1997-12-01,128.6719 62 | 1998-01-01,128.6719 63 | 1998-02-01,128.6719 64 | 1998-03-01,128.6719 65 | 1998-04-01,129.4563 66 | 1998-05-01,128.6719 67 | 1998-06-01,128.6719 68 | 1998-07-01,129.4563 69 | 1998-08-01,130.0505 70 | 1998-09-01,130.0505 71 | 1998-10-01,130.0505 72 | 1998-11-01,130.0505 73 | 1998-12-01,130.9105 74 | 1999-01-01,131.5187 75 | 1999-02-01,131.414 76 | 1999-03-01,131.414 77 | 1999-04-01,131.414 78 | 1999-05-01,131.414 79 | 1999-06-01,126.925 80 | 1999-07-01,124.0696 81 | 1999-08-01,124.0696 82 | 1999-09-01,124.0696 83 | 1999-10-01,124.0696 84 | 1999-11-01,121.913 85 | 1999-12-01,124.5435 86 | 2000-01-01,130.5071 87 | 2000-02-01,130.923 88 | 2000-03-01,130.923 89 | 2000-04-01,128.1974 90 | 2000-05-01,128.1974 91 | 2000-06-01,128.7899 92 | 2000-07-01,128.7075 93 | 2000-08-01,128.7075 94 | 2000-09-01,128.7075 95 | 2000-10-01,128.7075 96 | 2000-11-01,128.7075 97 | 2000-12-01,128.7075 98 | 2001-01-01,128.7075 99 | 2001-02-01,128.7075 100 | 2001-03-01,128.7075 101 | 2001-04-01,128.7075 102 | 2001-05-01,128.7075 103 | 2001-06-01,128.7075 104 | 2001-07-01,128.7075 105 | 2001-08-01,128.7075 106 | 2001-09-01,128.7075 107 | 2001-10-01,128.7075 108 | 2001-11-01,128.7075 109 | 2001-12-01,128.7075 110 | 2002-01-01,129.9842 111 | 2002-02-01,128.9362 112 | 2002-03-01,126.2033 113 | 2002-04-01,126.2033 114 | 2002-05-01,136.8031 115 | 2002-06-01,182.2238 116 | 2002-07-01,182.2238 117 | 2002-08-01,184.262 118 | 2002-09-01,183.8017 119 | 2002-10-01,183.8017 120 | 2002-11-01,183.0764 121 | 2002-12-01,180.9927 122 | 2003-01-01,182.1063 123 | 2003-02-01,183.8275 124 | 2003-03-01,241.7157 125 | 2003-04-01,246.3917 126 | 2003-05-01,246.5157 127 | 2003-06-01,247.1408 128 | 2003-07-01,247.1408 129 | 2003-08-01,247.1408 130 | 2003-09-01,315.4069 131 | 2003-10-01,322.0898 132 | 2003-11-01,322.0898 133 | 2003-12-01,322.0898 134 | 2004-01-01,322.08975544482 135 | 2004-02-01,333.28909962754 136 | 2004-03-01,333.28909962754 137 | 2004-04-01,333.28909962754 138 | 2004-05-01,333.28909962754 139 | 2004-06-01,333.28909962754 140 | 2004-07-01,333.28909962754 141 | 2004-08-01,333.28909962754 142 | 2004-09-01,330.73017545707 143 | 2004-10-01,330.73017545707 144 | 2004-11-01,330.73017545707 145 | 2004-12-01,352.34302325638 146 | 2005-01-01,352.34302325638 147 | 2005-02-01,351.26134751513 148 | 2005-03-01,351.26134751513 149 | 2005-04-01,354.13430657822 150 | 2005-05-01,354.13430657822 151 | 2005-06-01,354.13430657822 152 | 2005-07-01,353.71333419198 153 | 2005-08-01,366.34691618622 154 | 2005-09-01,367.80587552381 155 | 2005-10-01,367.80587552381 156 | 2005-11-01,389.11774572187 157 | 2005-12-01,389.11774572187 158 | 2006-01-01,396.24949915607 159 | 2006-02-01,394.7694759268 160 | 2006-03-01,394.7694759268 161 | 2006-04-01,394.7694759268 162 | 2006-05-01,396.24949915607 163 | 2006-06-01,396.24949915607 164 | 2006-07-01,396.24949915607 165 | 2006-08-01,396.24949915607 166 | 2006-09-01,396.24949915607 167 | 2006-10-01,396.24949915607 168 | 2006-11-01,396.24949915607 169 | 2006-12-01,396.3226737404 170 | 2007-01-01,420.63194490222 171 | 2007-02-01,426.65263668473 172 | 2007-03-01,426.65263668473 173 | 2007-04-01,426.79360126166 174 | 2007-05-01,426.79360126166 175 | 2007-06-01,426.93267074494 176 | 2007-07-01,426.93 177 | 2007-08-01,445.13 178 | 2007-09-01,445.13 179 | 2007-10-01,445.13 180 | 2007-11-01,445.13 181 | 2007-12-01,445.13 182 | 2008-01-01,456.2 183 | 2008-02-01,456.2 184 | 2008-03-01,456.2 185 | 2008-04-01,456.2 186 | 2008-05-01,464.75 187 | 2008-06-01,468.75 188 | 2008-07-01,469.89 189 | 2008-08-01,473.54 190 | 2008-09-01,475.55 191 | 2008-10-01,475.55 192 | 2008-11-01,475.55 193 | 2008-12-01,478.82 194 | 2009-01-01,478.91 195 | 2009-02-01,478.91 196 | 2009-03-01,478.82 197 | 2009-04-01,485.56 198 | 2009-05-01,487.5 199 | 2009-06-01,487.5 200 | 2009-07-01,487.5 201 | 2009-08-01,490.01 202 | 2009-09-01,493.94 203 | 2009-10-01,493.94 204 | 2009-11-01,497.74 205 | 2009-12-01,497.74 206 | 2010-01-01,507.75 207 | 2010-02-01,517.23 208 | 2010-03-01,548.53 209 | 2010-04-01,548.53 210 | 2010-05-01,556.36 211 | 2010-06-01,560.94 212 | 2010-07-01,560.94 213 | 2010-08-01,556.99 214 | 2010-09-01,561.11 215 | 2010-10-01,567.19 216 | 2010-11-01,567.19 217 | 2010-12-01,556.5 218 | 2011-01-01,556.5 219 | 2011-02-01,566.01 220 | 2011-03-01,566.01 221 | 2011-04-01,566.01 222 | 2011-05-01,566.01 223 | 2011-06-01,566.01 224 | 2011-07-01,571.31 225 | 2011-08-01,583.71 226 | 2011-09-01,583.71 227 | 2011-10-01,583.71 228 | 2011-11-01,594.9 229 | 2011-12-01,594.9 230 | 2012-01-01,594.9 231 | 2012-02-01,594.9 232 | 2012-03-01,594.9 233 | 2012-04-01,599.33 234 | 2012-05-01,624.15 235 | 2012-06-01,623.49 236 | 2012-07-01,624.15 237 | 2012-08-01,628.27 238 | 2012-09-01,641.26 239 | 2012-10-01,641.26 240 | 2012-11-01,646.54 241 | 2012-12-01,648.85 242 | 2013-01-01,648.85 243 | 2013-02-01,648.85 244 | 2013-03-01,648.85 245 | 2013-04-01,648.85 246 | 2013-05-01,648.85 247 | 2013-06-01,662.14 248 | 2013-07-01,662.14 249 | 2013-08-01,662.14 250 | 2013-09-01,662.14 251 | 2013-10-01,652.56 252 | 2013-11-01,652.56 253 | 2013-12-01,663.14 254 | 2014-01-01,657.72 255 | 2014-02-01,657.72 256 | 2014-03-01,657.72 257 | 2014-04-01,703.13 258 | 2014-05-01,711.24 259 | 2014-06-01,711.07 260 | 2014-07-01,710.75 261 | 2014-08-01,744.77 262 | 2014-09-01,762.91 263 | 2014-10-01,762.91 264 | 2014-11-01,762.91 265 | 2014-12-01,781.27 266 | 2015-01-01,781.27 267 | 2015-02-01,764.67 268 | 2015-03-01,779.72 269 | 2015-04-01,779.72 270 | 2015-05-01,817.19 271 | 2015-06-01,817.19 272 | 2015-07-01,816.58 273 | 2015-08-01,834.89 274 | 2015-09-01,849.41 275 | 2015-10-01,856.65 -------------------------------------------------------------------------------- /Chapter02/clients.csv: -------------------------------------------------------------------------------- 1 | Sales,Strategy,Client,Salesman 2 | 67.32011352,Modern,1,1 3 | 56.79989164,Modern,1,2 4 | 47.27248509,Modern,2,3 5 | 76.64601144,Modern,2,4 6 | 19.73813347,Modern,3,5 7 | 68.61806915,Modern,3,6 8 | 77.30717323,Modern,4,7 9 | 46.55627104,Modern,4,8 10 | 70.32093621,Modern,5,9 11 | 30.9874878,Modern,5,10 12 | 41.44885686,Modern,6,1 13 | 45.70541513,Modern,6,2 14 | 69.93240192,Modern,7,3 15 | 77.10555635,Modern,7,4 16 | 44.56150862,Modern,8,5 17 | 88.44848944,Modern,8,6 18 | 76.1459073,Modern,9,7 19 | 72.39783824,Modern,9,8 20 | 97.41454767,Modern,10,9 21 | 42.26556104,Modern,10,10 22 | 44.4425227,Modern,11,1 23 | 49.2219572,Modern,11,2 24 | 55.03036583,Modern,12,3 25 | 87.04922453,Modern,12,4 26 | 27.11820534,Modern,13,5 27 | 60.25233361,Modern,13,6 28 | 76.9585084,Modern,14,7 29 | 51.75424747,Modern,14,8 30 | 75.4751774,Modern,15,9 31 | 22.62212953,Modern,15,10 32 | 35.6770064,Modern,16,1 33 | 29.64053142,Modern,16,2 34 | 32.62965897,Modern,17,3 35 | 75.64980965,Modern,17,4 36 | 49.3395557,Modern,18,5 37 | 64.49357618,Modern,18,6 38 | 80.10768107,Modern,19,7 39 | 61.88658518,Modern,19,8 40 | 64.28724652,Modern,20,9 41 | 28.62474372,Modern,20,10 42 | 38.22748061,Modern,21,1 43 | 33.46158028,Modern,21,2 44 | 40.35561576,Modern,22,3 45 | 57.03379138,Modern,22,4 46 | 46.22719311,Modern,23,5 47 | 69.7732065,Modern,23,6 48 | 84.82406766,Modern,24,7 49 | 57.07004888,Modern,24,8 50 | 80.23250093,Modern,25,9 51 | 11.25468384,Modern,25,10 52 | 39.14399088,Modern,26,1 53 | 59.58440303,Modern,26,2 54 | 62.04617594,Modern,27,3 55 | 81.46707233,Modern,27,4 56 | 64.10632926,Modern,28,5 57 | 96.21432486,Modern,28,6 58 | 65.90365869,Modern,29,7 59 | 47.09310131,Modern,29,8 60 | 66.34422799,Modern,30,9 61 | 38.49754073,Modern,30,10 62 | 103.3379185,Traditional,31,1 63 | 102.8418302,Traditional,31,2 64 | 96.90423479,Traditional,32,3 65 | 109.4357455,Traditional,32,4 66 | 102.8033645,Traditional,33,5 67 | 118.9828915,Traditional,33,6 68 | 120.7944038,Traditional,34,7 69 | 89.45292142,Traditional,34,8 70 | 94.93423531,Traditional,35,9 71 | 65.24818593,Traditional,35,10 72 | 81.26385909,Traditional,36,1 73 | 91.48315814,Traditional,36,2 74 | 68.33449658,Traditional,37,3 75 | 97.27653388,Traditional,37,4 76 | 106.4223642,Traditional,38,5 77 | 120.2128726,Traditional,38,6 78 | 127.2239163,Traditional,39,7 79 | 96.10117912,Traditional,39,8 80 | 101.555664,Traditional,40,9 81 | 74.93456366,Traditional,40,10 82 | 95.65530987,Traditional,41,1 83 | 88.2574385,Traditional,41,2 84 | 72.08035185,Traditional,42,3 85 | 104.8866569,Traditional,42,4 86 | 73.17832203,Traditional,43,5 87 | 107.0344089,Traditional,43,6 88 | 134.6160957,Traditional,44,7 89 | 86.24048189,Traditional,45,8 90 | 106.8710275,Traditional,45,9 91 | 80.89725842,Traditional,46,10 92 | 116.7723075,Traditional,46,1 93 | 107.4075905,Traditional,47,2 94 | 98.2532534,Traditional,47,3 95 | 100.588367,Traditional,48,4 96 | 59.93723572,Traditional,48,5 97 | 112.4158919,Traditional,49,6 98 | 108.0158253,Traditional,49,7 99 | 86.29808666,Traditional,50,8 100 | 106.5794899,Traditional,50,9 101 | 78.45480485,Traditional,51,10 102 | 84.98833976,Traditional,51,1 103 | 94.99488991,Traditional,52,2 104 | 83.72836858,Traditional,52,3 105 | 114.1652527,Traditional,53,4 106 | 92.20974448,Traditional,53,5 107 | 119.5875094,Traditional,54,6 108 | 129.2045287,Traditional,54,7 109 | 85.94887985,Traditional,55,8 110 | 111.753126,Traditional,55,9 111 | 67.21742242,Traditional,56,10 112 | 74.3934674,Traditional,56,1 113 | 98.98926611,Traditional,57,2 114 | 101.0988172,Traditional,57,3 115 | 95.25635402,Traditional,58,4 116 | 98.77095223,Traditional,58,5 117 | 114.3695963,Traditional,59,6 118 | 103.472043,Traditional,59,7 119 | 98.49104142,Traditional,60,8 120 | 106.1308909,Traditional,60,9 121 | 70.940888,Traditional,61,10 122 | 87.72016972,Traditional,61,1 123 | 89.01070289,Traditional,62,2 124 | 88.6068046,Traditional,62,3 125 | 127.6424854,Traditional,63,4 126 | 86.25304081,Traditional,63,5 127 | 119.0404262,Traditional,64,6 128 | 122.3658911,Traditional,64,7 129 | 107.6819255,Traditional,65,8 130 | 110.0255639,Traditional,65,9 131 | 84.80139001,Traditional,66,10 132 | 90.29440961,Traditional,66,1 133 | 97.56780305,Traditional,67,2 134 | 104.360555,Traditional,67,3 135 | 118.6963116,Traditional,68,4 136 | 98.94648689,Traditional,68,5 137 | 96.72026055,Traditional,69,6 138 | 116.4256602,Traditional,69,7 139 | 112.6873917,Traditional,70,8 140 | 130.3957371,Traditional,70,9 141 | 71.05505956,Traditional,71,10 142 | 104.5148953,Traditional,71,1 143 | 96.10632704,Traditional,72,2 144 | 104.2172563,Traditional,72,3 145 | 111.3165025,Traditional,73,4 146 | 65.41955818,Traditional,73,5 147 | 104.9917611,Traditional,74,6 148 | 110.1538726,Traditional,74,7 149 | 93.53041083,Traditional,75,8 150 | 102.4969757,Traditional,75,9 151 | 57.11775161,Traditional,76,10 152 | 73.53451201,Traditional,76,1 153 | 105.2190693,Traditional,77,2 154 | 81.34534596,Traditional,77,3 155 | 137.0802562,Traditional,78,4 156 | 64.54703792,Traditional,78,5 157 | 123.4190907,Traditional,79,6 158 | 119.2142095,Traditional,79,7 159 | 116.6572016,Traditional,80,8 160 | 110.8028553,Traditional,80,9 161 | 70.94887985,Discount_driven,55,8 162 | 96.753126,Discount_driven,55,9 163 | 52.21742242,Discount_driven,56,10 164 | 59.3934674,Discount_driven,56,1 165 | 83.98926611,Discount_driven,57,2 166 | 86.0988172,Discount_driven,57,3 167 | 80.25635402,Discount_driven,58,4 168 | 83.77095223,Discount_driven,58,5 169 | 99.3695963,Discount_driven,59,6 170 | 88.472043,Discount_driven,59,7 171 | 83.49104142,Discount_driven,60,8 172 | 91.1308909,Discount_driven,60,9 173 | 55.940888,Discount_driven,61,10 174 | 72.72016972,Discount_driven,61,1 175 | 74.01070289,Discount_driven,62,2 176 | 73.6068046,Discount_driven,62,3 177 | 112.6424854,Discount_driven,63,4 178 | 71.25304081,Discount_driven,63,5 179 | 104.0404262,Discount_driven,64,6 180 | 107.3658911,Discount_driven,64,7 181 | 92.6819255,Discount_driven,65,8 182 | 95.0255639,Discount_driven,65,9 183 | 69.80139001,Discount_driven,66,10 184 | 75.29440961,Discount_driven,66,1 185 | 82.56780305,Discount_driven,67,2 186 | 89.360555,Discount_driven,67,3 187 | 103.6963116,Discount_driven,68,4 188 | 83.94648689,Discount_driven,68,5 189 | 81.72026055,Discount_driven,69,6 190 | 101.4256602,Discount_driven,69,7 191 | 97.6873917,Discount_driven,70,8 192 | 115.3957371,Discount_driven,70,9 193 | 56.05505956,Discount_driven,71,10 194 | 89.5148953,Discount_driven,71,1 195 | 81.10632704,Discount_driven,72,2 196 | 89.2172563,Discount_driven,72,3 197 | 96.3165025,Discount_driven,73,4 198 | 50.41955818,Discount_driven,73,5 199 | 89.9917611,Discount_driven,74,6 200 | 95.1538726,Discount_driven,74,7 201 | 78.53041083,Discount_driven,75,8 202 | 87.4969757,Discount_driven,75,9 203 | 42.11775161,Discount_driven,76,10 204 | 58.53451201,Discount_driven,76,1 205 | 90.2190693,Discount_driven,77,2 206 | 66.34534596,Discount_driven,77,3 207 | 122.0802562,Discount_driven,78,4 208 | 49.54703792,Discount_driven,78,5 209 | 108.4190907,Discount_driven,79,6 210 | 104.2142095,Discount_driven,79,7 211 | 101.6572016,Discount_driven,80,8 212 | 95.8028553,Discount_driven,80,9 213 | 95.8028553,Discount_driven,80,9 214 | -------------------------------------------------------------------------------- /Chapter07/steel.csv: -------------------------------------------------------------------------------- 1 | indice_tiempo,valor 2 | 1993-01-01,214500 3 | 1993-02-01,169000 4 | 1993-03-01,238700 5 | 1993-04-01,250200 6 | 1993-05-01,261200 7 | 1993-06-01,256500 8 | 1993-07-01,251300 9 | 1993-08-01,267000 10 | 1993-09-01,260700 11 | 1993-10-01,266900 12 | 1993-11-01,247400 13 | 1993-12-01,202000 14 | 1994-01-01,229200 15 | 1994-02-01,185800 16 | 1994-03-01,277900 17 | 1994-04-01,291900 18 | 1994-05-01,276500 19 | 1994-06-01,268400 20 | 1994-07-01,283500 21 | 1994-08-01,312000 22 | 1994-09-01,294300 23 | 1994-10-01,327100 24 | 1994-11-01,286100 25 | 1994-12-01,272300 26 | 1995-01-01,262100 27 | 1995-02-01,230800 28 | 1995-03-01,306700 29 | 1995-04-01,293900 30 | 1995-05-01,305000 31 | 1995-06-01,300400 32 | 1995-07-01,322400 33 | 1995-08-01,317000 34 | 1995-09-01,302800 35 | 1995-10-01,333700 36 | 1995-11-01,330600 37 | 1995-12-01,263100 38 | 1996-01-01,271200 39 | 1996-02-01,305700 40 | 1996-03-01,361500 41 | 1996-04-01,336100 42 | 1996-05-01,345600 43 | 1996-06-01,350100 44 | 1996-07-01,352700 45 | 1996-08-01,353000 46 | 1996-09-01,339100 47 | 1996-10-01,373300 48 | 1996-11-01,364200 49 | 1996-12-01,322600 50 | 1997-01-01,272330 51 | 1997-02-01,280150 52 | 1997-03-01,355410 53 | 1997-04-01,366250 54 | 1997-05-01,353630 55 | 1997-06-01,357740 56 | 1997-07-01,380350 57 | 1997-08-01,358870 58 | 1997-09-01,359420 59 | 1997-10-01,384250 60 | 1997-11-01,364880 61 | 1997-12-01,336590 62 | 1998-01-01,328440 63 | 1998-02-01,331000 64 | 1998-03-01,332290 65 | 1998-04-01,370310 66 | 1998-05-01,388090 67 | 1998-06-01,373030 68 | 1998-07-01,357170 69 | 1998-08-01,387410 70 | 1998-09-01,351720 71 | 1998-10-01,362130 72 | 1998-11-01,343090 73 | 1998-12-01,290720 74 | 1999-01-01,253660 75 | 1999-02-01,239920 76 | 1999-03-01,279270 77 | 1999-04-01,298120 78 | 1999-05-01,316130 79 | 1999-06-01,310640 80 | 1999-07-01,346930 81 | 1999-08-01,350230 82 | 1999-09-01,347850 83 | 1999-10-01,361890 84 | 1999-11-01,361440 85 | 1999-12-01,338620 86 | 2000-01-01,302160 87 | 2000-02-01,324710 88 | 2000-03-01,388020 89 | 2000-04-01,379710 90 | 2000-05-01,352840 91 | 2000-06-01,338290 92 | 2000-07-01,371880 93 | 2000-08-01,397810 94 | 2000-09-01,408130 95 | 2000-10-01,413760 96 | 2000-11-01,407680 97 | 2000-12-01,394230 98 | 2001-01-01,327850 99 | 2001-02-01,317630 100 | 2001-03-01,386920 101 | 2001-04-01,387180 102 | 2001-05-01,396450 103 | 2001-06-01,375240 104 | 2001-07-01,360090 105 | 2001-08-01,275920 106 | 2001-09-01,349780 107 | 2001-10-01,336120 108 | 2001-11-01,312470 109 | 2001-12-01,282350 110 | 2002-01-01,255250 111 | 2002-02-01,305920 112 | 2002-03-01,341140 113 | 2002-04-01,391660 114 | 2002-05-01,389870 115 | 2002-06-01,357690 116 | 2002-07-01,378540 117 | 2002-08-01,393210 118 | 2002-09-01,388440 119 | 2002-10-01,411030 120 | 2002-11-01,372200 121 | 2002-12-01,375600 122 | 2003-01-01,362710 123 | 2003-02-01,383970 124 | 2003-03-01,447980 125 | 2003-04-01,428610 126 | 2003-05-01,442090 127 | 2003-06-01,420440 128 | 2003-07-01,423750 129 | 2003-08-01,438110 130 | 2003-09-01,410790 131 | 2003-10-01,448120 132 | 2003-11-01,417440 133 | 2003-12-01,409170 134 | 2004-01-01,384700 135 | 2004-02-01,410300 136 | 2004-03-01,419800 137 | 2004-04-01,409000 138 | 2004-05-01,426000 139 | 2004-06-01,410200 140 | 2004-07-01,434200 141 | 2004-08-01,428900 142 | 2004-09-01,417300 143 | 2004-10-01,476900 144 | 2004-11-01,465700 145 | 2004-12-01,450320 146 | 2005-01-01,410100 147 | 2005-02-01,420400 148 | 2005-03-01,465900 149 | 2005-04-01,462600 150 | 2005-05-01,482100 151 | 2005-06-01,441400 152 | 2005-07-01,454700 153 | 2005-08-01,460800 154 | 2005-09-01,408200 155 | 2005-10-01,448000 156 | 2005-11-01,466600 157 | 2005-12-01,464780 158 | 2006-01-01,412300 159 | 2006-02-01,445900 160 | 2006-03-01,505100 161 | 2006-04-01,479700 162 | 2006-05-01,492100 163 | 2006-06-01,490500 164 | 2006-07-01,481600 165 | 2006-08-01,464300 166 | 2006-09-01,481000 167 | 2006-10-01,484200 168 | 2006-11-01,409300 169 | 2006-12-01,386730 170 | 2007-01-01,335900 171 | 2007-02-01,415600 172 | 2007-03-01,476600 173 | 2007-04-01,472800 174 | 2007-05-01,444600 175 | 2007-06-01,446300 176 | 2007-07-01,356500 177 | 2007-08-01,485000 178 | 2007-09-01,475900 179 | 2007-10-01,497500 180 | 2007-11-01,490500 181 | 2007-12-01,489910 182 | 2008-01-01,417000 183 | 2008-02-01,441900 184 | 2008-03-01,509200 185 | 2008-04-01,501000 186 | 2008-05-01,499200 187 | 2008-06-01,493900 188 | 2008-07-01,528700 189 | 2008-08-01,524000 190 | 2008-09-01,488400 191 | 2008-10-01,480800 192 | 2008-11-01,391200 193 | 2008-12-01,266090 194 | 2009-01-01,284200 195 | 2009-02-01,256600 196 | 2009-03-01,258900 197 | 2009-04-01,278900 198 | 2009-05-01,268810 199 | 2009-06-01,311390 200 | 2009-07-01,355330 201 | 2009-08-01,371300 202 | 2009-09-01,390800 203 | 2009-10-01,430650 204 | 2009-11-01,414500 205 | 2009-12-01,391710 206 | 2010-01-01,338100 207 | 2010-02-01,380500 208 | 2010-03-01,442800 209 | 2010-04-01,427900 210 | 2010-05-01,438400 211 | 2010-06-01,420600 212 | 2010-07-01,437300 213 | 2010-08-01,473400 214 | 2010-09-01,450800 215 | 2010-10-01,468300 216 | 2010-11-01,449500 217 | 2010-12-01,411500 218 | 2011-01-01,361500 219 | 2011-02-01,440400 220 | 2011-03-01,471100 221 | 2011-04-01,474000 222 | 2011-05-01,495800 223 | 2011-06-01,470000 224 | 2011-07-01,491000 225 | 2011-08-01,489400 226 | 2011-09-01,472900 227 | 2011-10-01,505900 228 | 2011-11-01,483700 229 | 2011-12-01,455500 230 | 2012-01-01,395900 231 | 2012-02-01,450000 232 | 2012-03-01,496700 233 | 2012-04-01,480000 234 | 2012-05-01,458400 235 | 2012-06-01,451100 236 | 2012-07-01,344000 237 | 2012-08-01,379900 238 | 2012-09-01,396100 239 | 2012-10-01,413700 240 | 2012-11-01,395400 241 | 2012-12-01,333900 242 | 2013-01-01,320000 243 | 2013-02-01,320800 244 | 2013-03-01,467600 245 | 2013-04-01,428900 246 | 2013-05-01,448700 247 | 2013-06-01,416500 248 | 2013-07-01,461500 249 | 2013-08-01,478900 250 | 2013-09-01,462600 251 | 2013-10-01,477300 252 | 2013-11-01,469200 253 | 2013-12-01,433600 254 | 2014-01-01,397100 255 | 2014-02-01,380300 256 | 2014-03-01,471800 257 | 2014-04-01,485800 258 | 2014-05-01,482900 259 | 2014-06-01,477400 260 | 2014-07-01,476700 261 | 2014-08-01,467400 262 | 2014-09-01,463800 263 | 2014-10-01,477500 264 | 2014-11-01,461300 265 | 2014-12-01,446200 266 | 2015-01-01,385900 267 | 2015-02-01,376700 268 | 2015-03-01,429800 269 | 2015-04-01,383800 270 | 2015-05-01,410900 271 | 2015-06-01,444600 272 | 2015-07-01,431000 273 | 2015-08-01,473500 274 | 2015-09-01,446400 275 | 2015-10-01,468700 276 | 2015-11-01,404900 277 | 2015-12-01,371600 278 | 2016-01-01,329500 279 | 2016-02-01,338800 280 | 2016-03-01,317700 281 | 2016-04-01,319100 282 | 2016-05-01,379100 283 | 2016-06-01,372400 284 | 2016-07-01,356100 285 | 2016-08-01,343200 286 | 2016-09-01,322100 287 | 2016-10-01,376600 288 | 2016-11-01,359300 289 | 2016-12-01,312600 290 | 2017-01-01,291300 291 | 2017-02-01,305100 292 | 2017-03-01,392300 293 | 2017-04-01,367400 294 | 2017-05-01,394100 295 | 2017-06-01,372200 296 | 2017-07-01,398800 297 | 2017-08-01,417400 298 | 2017-09-01,422700 299 | 2017-10-01,447100 300 | 2017-11-01,435000 301 | 2017-12-01,380800 302 | 2018-01-01,343800 303 | 2018-02-01,417300 304 | 2018-03-01,473900 305 | 2018-04-01,463000 306 | 2018-05-01,438100 307 | 2018-06-01,413500 308 | 2018-07-01,463800 309 | 2018-08-01,455300 310 | 2018-09-01,434700 311 | 2018-10-01,446200 312 | 2018-11-01,456000 313 | 2018-12-01,356100 -------------------------------------------------------------------------------- /Chapter01/14/data__model.csv: -------------------------------------------------------------------------------- 1 | Sex,Age,Week1,Week2,Week3,Week4,Week5,Week6,Week7,Week8,Week9,Week10,Week11,Week12,Week13,Week14,Week15,Week16,Week17,Week18,Week19,Week20 2 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1 3 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 4 | M,18-25,L1,L1,L1,L1,L1,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 5 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 6 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1 7 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 8 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L1,L1,L1,L1,L1,L1 9 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 10 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L1,L1,L1,L1,L1,L1 11 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L1,L1,L1,L1,L1 12 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L3,L3,L3,L3,L3,L3,CLOSED,CLOSED 13 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 14 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 15 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L1,L1,L1,L1,L1 16 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1 17 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 18 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 19 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 20 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1 21 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 22 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L1,L1,L1,L1,L1,L1 23 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 24 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1 25 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L1,L1,L1,L1,L1 26 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L2,L1,L3,L3,CLOSED,CLOSED 27 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1 28 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 29 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L1,L1,L1,L1,L1 30 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1 31 | F,18-25,L1,L1,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 32 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 33 | F,18-25,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 34 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3 35 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 36 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2 37 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 38 | F,18-25,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 39 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 40 | F,18-25,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L1,L1 41 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L3,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 42 | F,18-25,L1,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 43 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2 44 | F,18-25,L1,L1,L1,L1,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3 45 | F,18-25,L1,L1,L1,L1,L1,L1,L3,L1,L1,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 46 | F,18-25,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 47 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L1 48 | F,18-25,L1,L1,L1,L1,L1,L1,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 49 | F,18-25,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 50 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L3,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 51 | F,18-25,L1,L1,L1,L1,L1,L2,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L1 52 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 53 | F,18-25,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 54 | F,18-25,L1,L1,L1,L1,L1,L1,L2,L1,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 55 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2 56 | F,18-25,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 57 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2 58 | M,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 59 | M,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 60 | M,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 61 | M,26-45,L1,L1,L1,L1,L1,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 62 | M,26-45,L1,L1,L1,L1,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 63 | M,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 64 | M,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 65 | M,26-45,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 66 | M,26-45,L1,L2,L1,L1,L1,L3,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 67 | M,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 68 | M,26-45,L1,L1,L3,L1,L1,L2,L1,L1,L1,L1,L1,L1,L1,L3,L1,L1,L1,L1,L1,L1 69 | M,26-45,L1,L1,L1,L3,L1,L1,L1,L1,L2,L3,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1 70 | M,26-45,L1,L2,L1,L2,L2,L2,L1,L3,L1,L2,L3,L1,L1,L1,L3,L1,L1,L1,L2,L2 71 | M,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 72 | M,26-45,L1,L2,L3,L3,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 73 | M,26-45,L1,L1,L1,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 74 | M,26-45,L1,L1,L1,L1,L1,L1,L3,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L1,L1 75 | M,26-45,L1,L1,L2,L3,L1,L1,L1,L1,L3,L3,L3,L3,L3,L1,L1,L1,L1,L1,L1,L3 76 | M,26-45,L1,L3,L1,L1,L1,L1,L1,L3,L3,L2,L2,L2,L2,L3,L3,L1,L1,L1,L1,L1 77 | M,26-45,L1,L1,L1,L1,L3,L3,L2,L3,L2,L3,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1 78 | M,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 79 | F,26-45,L2,L3,L3,L3,L3,L3,L3,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2 80 | F,26-45,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3 81 | F,26-45,L2,L2,L2,L2,L2,L2,L2,L2,L2,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3 82 | F,26-45,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2 83 | F,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 84 | F,26-45,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 85 | F,26-45,L1,L3,L3,L3,L3,L1,L2,L2,L2,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1 86 | F,26-45,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L2,L2,L2,L2,L2,L2,L2,L2,L1,L1 87 | F,26-45,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L1,L1,L1,L1,L1,L1,L1 88 | F,26-45,L1,L3,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 89 | F,26-45,L3,L3,L3,L3,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L1,L1,L1 90 | F,26-45,L1,L1,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L1,L1,L1,L1,L1,L1 91 | F,26-45,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 92 | F,26-45,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L1,L1,L1,L1 93 | F,26-45,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L1,L1,L1,L1 94 | F,26-45,L3,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,CLOSED,CLOSED,CLOSED -------------------------------------------------------------------------------- /Chapter01/15/data__model.csv: -------------------------------------------------------------------------------- 1 | Sex,Age,Week1,Week2,Week3,Week4,Week5,Week6,Week7,Week8,Week9,Week10,Week11,Week12,Week13,Week14,Week15,Week16,Week17,Week18,Week19,Week20 2 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1 3 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 4 | M,18-25,L1,L1,L1,L1,L1,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 5 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 6 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1 7 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 8 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L1,L1,L1,L1,L1,L1 9 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 10 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L1,L1,L1,L1,L1,L1 11 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L1,L1,L1,L1,L1 12 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L3,L3,L3,L3,L3,L3,CLOSED,CLOSED 13 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 14 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 15 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L1,L1,L1,L1,L1 16 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1 17 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 18 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 19 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 20 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1 21 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 22 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L1,L1,L1,L1,L1,L1 23 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 24 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1 25 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L1,L1,L1,L1,L1 26 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L2,L1,L3,L3,CLOSED,CLOSED 27 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1 28 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 29 | M,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L1,L1,L1,L1,L1 30 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1 31 | F,18-25,L1,L1,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 32 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 33 | F,18-25,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 34 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3 35 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 36 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2 37 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 38 | F,18-25,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 39 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 40 | F,18-25,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L1,L1 41 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L3,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 42 | F,18-25,L1,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 43 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2 44 | F,18-25,L1,L1,L1,L1,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3 45 | F,18-25,L1,L1,L1,L1,L1,L1,L3,L1,L1,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 46 | F,18-25,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 47 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L1 48 | F,18-25,L1,L1,L1,L1,L1,L1,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 49 | F,18-25,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 50 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L3,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 51 | F,18-25,L1,L1,L1,L1,L1,L2,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L1 52 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 53 | F,18-25,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 54 | F,18-25,L1,L1,L1,L1,L1,L1,L2,L1,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 55 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2 56 | F,18-25,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 57 | F,18-25,L1,L1,L1,L1,L1,L1,L1,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2 58 | M,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 59 | M,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 60 | M,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 61 | M,26-45,L1,L1,L1,L1,L1,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 62 | M,26-45,L1,L1,L1,L1,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 63 | M,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 64 | M,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 65 | M,26-45,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 66 | M,26-45,L1,L2,L1,L1,L1,L3,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 67 | M,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 68 | M,26-45,L1,L1,L3,L1,L1,L2,L1,L1,L1,L1,L1,L1,L1,L3,L1,L1,L1,L1,L1,L1 69 | M,26-45,L1,L1,L1,L3,L1,L1,L1,L1,L2,L3,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1 70 | M,26-45,L1,L2,L1,L2,L2,L2,L1,L3,L1,L2,L3,L1,L1,L1,L3,L1,L1,L1,L2,L2 71 | M,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 72 | M,26-45,L1,L2,L3,L3,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 73 | M,26-45,L1,L1,L1,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 74 | M,26-45,L1,L1,L1,L1,L1,L1,L3,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L1,L1 75 | M,26-45,L1,L1,L2,L3,L1,L1,L1,L1,L3,L3,L3,L3,L3,L1,L1,L1,L1,L1,L1,L3 76 | M,26-45,L1,L3,L1,L1,L1,L1,L1,L3,L3,L2,L2,L2,L2,L3,L3,L1,L1,L1,L1,L1 77 | M,26-45,L1,L1,L1,L1,L3,L3,L2,L3,L2,L3,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1 78 | M,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 79 | F,26-45,L2,L3,L3,L3,L3,L3,L3,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2 80 | F,26-45,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3 81 | F,26-45,L2,L2,L2,L2,L2,L2,L2,L2,L2,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3 82 | F,26-45,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2 83 | F,26-45,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 84 | F,26-45,L1,L1,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 85 | F,26-45,L1,L3,L3,L3,L3,L1,L2,L2,L2,L2,L2,L1,L1,L1,L1,L1,L1,L1,L1,L1 86 | F,26-45,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L2,L2,L2,L2,L2,L2,L2,L2,L1,L1 87 | F,26-45,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L1,L1,L1,L1,L1,L1,L1 88 | F,26-45,L1,L3,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1 89 | F,26-45,L3,L3,L3,L3,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L1,L1,L1 90 | F,26-45,L1,L1,L1,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L1,L1,L1,L1,L1,L1 91 | F,26-45,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED,CLOSED 92 | F,26-45,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L2,L1,L1,L1,L1 93 | F,26-45,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L3,L1,L1,L1,L1 94 | F,26-45,L3,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,L1,CLOSED,CLOSED,CLOSED -------------------------------------------------------------------------------- /Chapter02/employee_time_bonus.csv: -------------------------------------------------------------------------------- 1 | Performance,Time,Employee,x_Bonus,x_Sector 2 | 84.04090431,1,1,boost_bonus,sales 3 | 92.82135802,2,1,boost_bonus,sales 4 | 98.67893416,3,1,boost_bonus,sales 5 | 105.6645756,4,1,boost_bonus,sales 6 | 74.22031127,1,2,boost_bonus,sales 7 | 78.23674025,2,2,boost_bonus,sales 8 | 86.84533382,3,2,boost_bonus,sales 9 | 86.29458001,4,2,boost_bonus,sales 10 | 83.96062918,1,3,boost_bonus,sales 11 | 87.41130151,2,3,standard,sales 12 | 94.95465731,3,3,standard,sales 13 | 100.7866526,4,3,standard,sales 14 | 81.57320814,1,4,standard,sales 15 | 86.45529423,2,4,standard,sales 16 | 79.43931812,3,4,standard,HR 17 | 84.51681192,4,4,standard,HR 18 | 73.24649385,1,5,standard,HR 19 | 76.30549922,2,5,standard,HR 20 | 81.60616664,3,5,standard,HR 21 | 86.74725902,4,5,standard,HR 22 | 73.26155578,1,6,standard,HR 23 | 79.68813477,2,6,standard,HR 24 | 85.8851035,3,6,standard,HR 25 | 86.72633532,4,6,standard,HR 26 | 79.26404186,1,7,standard,HR 27 | 87.6425235,2,7,standard,HR 28 | 90.37173813,3,7,standard,HR 29 | 90.51386991,4,7,standard,HR 30 | 69.95397541,1,8,standard,engineering 31 | 74.9913261,2,8,standard,engineering 32 | 81.29734331,3,8,standard,engineering 33 | 87.71832452,4,8,standard,engineering 34 | 67.43468085,1,9,standard,engineering 35 | 73.2109319,2,9,standard,engineering 36 | 72.89201031,3,9,standard,engineering 37 | 75.23927535,4,9,standard,engineering 38 | 73.46148155,1,10,standard,engineering 39 | 73.56713396,2,10,standard,engineering 40 | 80.67587994,3,10,standard,engineering 41 | 88.31375821,4,10,standard,engineering 42 | 60.01931361,1,11,standard,engineering 43 | 63.11649026,2,11,standard,engineering 44 | 72.50907501,3,11,standard,engineering 45 | 79.20579933,4,11,standard,engineering 46 | 90.008337,1,12,standard,sales 47 | 96.8173288,2,12,standard,sales 48 | 103.9745449,3,12,standard,sales 49 | 112.0956806,4,12,standard,sales 50 | 86.68579811,1,13,standard,sales 51 | 90.68384754,2,13,standard,sales 52 | 96.60727836,3,13,standard,sales 53 | 102.8079048,4,13,standard,sales 54 | 97.04213955,1,14,standard,sales 55 | 101.1809613,2,14,standard,sales 56 | 105.7675163,3,14,standard,sales 57 | 108.8152317,4,14,standard,sales 58 | 83.64073063,1,15,standard,sales 59 | 92.84030486,2,15,standard,sales 60 | 84.99833688,3,15,standard,HR 61 | 93.20643195,4,15,standard,HR 62 | 77.02984405,1,16,standard,HR 63 | 78.91932946,2,16,standard,HR 64 | 87.31813888,3,16,standard,HR 65 | 84.9641481,4,16,standard,HR 66 | 70.53703891,1,17,standard,HR 67 | 76.61581677,2,17,standard,HR 68 | 76.51465966,3,17,standard,HR 69 | 78.06978833,4,17,standard,HR 70 | 79.04267655,1,18,standard,HR 71 | 82.5848687,2,18,standard,HR 72 | 91.55625105,3,18,standard,HR 73 | 94.20095817,4,18,standard,HR 74 | 62.90210757,1,19,standard,engineering 75 | 68.05961532,2,19,standard,engineering 76 | 75.51840999,3,19,standard,engineering 77 | 83.08739444,4,19,standard,engineering 78 | 59.32553562,1,20,standard,engineering 79 | 68.29503141,2,20,standard,engineering 80 | 73.00275157,3,20,standard,engineering 81 | 69.79300395,4,20,standard,engineering 82 | 71.7554856,1,21,standard,engineering 83 | 76.99409453,2,21,standard,engineering 84 | 79.27080673,3,21,standard,engineering 85 | 84.28937108,4,21,standard,engineering 86 | 68.65468323,1,22,standard,engineering 87 | 71.94907543,2,22,standard,engineering 88 | 77.79131475,3,22,standard,engineering 89 | 83.71021822,4,22,standard,engineering 90 | 89.88957654,1,23,standard,sales 91 | 96.1657177,2,23,standard,sales 92 | 102.7963968,3,23,standard,sales 93 | 103.2223067,4,23,standard,sales 94 | 82.61457639,1,24,standard,sales 95 | 87.92176108,2,24,standard,sales 96 | 91.6515894,3,24,standard,sales 97 | 96.33963642,4,24,standard,sales 98 | 97.41086435,1,25,standard,sales 99 | 95.56878365,2,25,standard,sales 100 | 103.2755849,3,25,standard,sales 101 | 141.8865756,4,25,boost_bonus,sales 102 | 113.4093581,1,26,boost_bonus,sales 103 | 119.4098769,2,26,boost_bonus,sales 104 | 113.5925561,3,26,boost_bonus,HR 105 | 120.8960159,4,26,boost_bonus,HR 106 | 103.4139443,1,27,boost_bonus,HR 107 | 107.8616071,2,27,boost_bonus,HR 108 | 113.1017878,3,27,boost_bonus,HR 109 | 119.8011874,4,27,boost_bonus,HR 110 | 110.4918285,1,28,boost_bonus,HR 111 | 113.2141654,2,28,boost_bonus,HR 112 | 114.0920467,3,28,boost_bonus,HR 113 | 122.5554533,4,28,boost_bonus,HR 114 | 110.4301859,1,29,boost_bonus,HR 115 | 114.1218973,2,29,boost_bonus,HR 116 | 117.8826417,3,29,boost_bonus,HR 117 | 122.5572114,4,29,boost_bonus,HR 118 | 93.99102201,1,30,boost_bonus,engineering 119 | 100.4922409,2,30,boost_bonus,engineering 120 | 107.5817568,3,30,boost_bonus,engineering 121 | 111.6247785,4,30,boost_bonus,engineering 122 | 96.89704435,1,31,boost_bonus,engineering 123 | 99.16878727,2,31,boost_bonus,engineering 124 | 105.6443379,3,31,boost_bonus,engineering 125 | 109.5550697,4,31,boost_bonus,engineering 126 | 95.40896033,1,32,boost_bonus,engineering 127 | 98.99782496,2,32,boost_bonus,engineering 128 | 100.7874021,3,32,boost_bonus,engineering 129 | 106.650385,4,32,boost_bonus,engineering 130 | 97.61280525,1,33,boost_bonus,engineering 131 | 99.28406049,2,33,boost_bonus,engineering 132 | 104.2853013,3,33,boost_bonus,engineering 133 | 111.6632538,4,33,boost_bonus,engineering 134 | 111.132938,1,34,boost_bonus,sales 135 | 119.2835907,2,34,boost_bonus,sales 136 | 121.8393827,3,34,boost_bonus,sales 137 | 130.3988995,4,34,boost_bonus,sales 138 | 120.7850537,1,35,boost_bonus,sales 139 | 127.5160964,2,35,boost_bonus,sales 140 | 132.511245,3,35,boost_bonus,sales 141 | 132.6766097,4,35,boost_bonus,sales 142 | 112.4583943,1,36,boost_bonus,sales 143 | 123.2678638,2,36,boost_bonus,sales 144 | 125.4162436,3,36,boost_bonus,sales 145 | 130.2237948,4,36,boost_bonus,sales 146 | 109.3946013,1,37,boost_bonus,sales 147 | 112.0385554,2,37,boost_bonus,sales 148 | 109.6171113,3,37,boost_bonus,HR 149 | 113.7573296,4,37,boost_bonus,HR 150 | 107.795847,1,38,boost_bonus,HR 151 | 111.6334127,2,38,boost_bonus,HR 152 | 112.2565184,3,38,boost_bonus,HR 153 | 118.4307561,4,38,boost_bonus,HR 154 | 113.0608873,1,39,boost_bonus,HR 155 | 114.3297311,2,39,boost_bonus,HR 156 | 116.1179923,3,39,boost_bonus,HR 157 | 122.9024538,4,39,boost_bonus,HR 158 | 107.0611081,1,40,boost_bonus,HR 159 | 111.8957405,2,40,boost_bonus,HR 160 | 119.5569996,3,40,boost_bonus,HR 161 | 118.8824537,4,40,boost_bonus,HR 162 | 86.20261003,1,41,boost_bonus,engineering 163 | 93.27152285,2,41,boost_bonus,engineering 164 | 103.4401761,3,41,boost_bonus,engineering 165 | 109.7975974,4,41,boost_bonus,engineering 166 | 88.36340383,1,42,boost_bonus,engineering 167 | 101.6227482,2,42,boost_bonus,engineering 168 | 105.5018297,3,42,boost_bonus,engineering 169 | 110.3261072,4,42,boost_bonus,engineering 170 | 87.7523515,1,43,boost_bonus,engineering 171 | 96.65928026,2,43,boost_bonus,engineering 172 | 101.2074356,3,43,boost_bonus,engineering 173 | 105.4604014,4,43,boost_bonus,engineering 174 | 89.08742882,1,44,boost_bonus,engineering 175 | 96.8341958,2,44,boost_bonus,engineering 176 | 110.4825666,3,44,boost_bonus,engineering 177 | 108.8490844,4,44,boost_bonus,engineering 178 | 123.5401797,1,45,boost_bonus,sales 179 | 124.8357959,2,45,boost_bonus,sales 180 | 127.876989,3,45,boost_bonus,sales 181 | 132.0540463,4,45,boost_bonus,sales 182 | 123.8951436,1,46,boost_bonus,sales 183 | 128.9283936,2,46,boost_bonus,sales 184 | 128.3302552,3,46,boost_bonus,sales 185 | 139.1499397,4,46,boost_bonus,sales 186 | 118.9668521,1,47,boost_bonus,sales 187 | 123.9720137,2,47,boost_bonus,sales 188 | 131.3591067,3,47,boost_bonus,sales 189 | 137.0286758,4,47,boost_bonus,sales 190 | 110.0399166,1,48,boost_bonus,sales 191 | 112.229763,2,48,boost_bonus,sales 192 | 107.9377809,3,48,boost_bonus,HR 193 | 120.7918038,4,48,boost_bonus,HR 194 | 109.4548513,1,49,boost_bonus,HR 195 | 113.6791429,2,49,boost_bonus,HR 196 | 113.2934584,3,49,boost_bonus,HR 197 | 121.0103764,4,49,boost_bonus,HR 198 | 115.0593826,1,50,boost_bonus,HR 199 | 119.4211285,2,50,boost_bonus,HR 200 | 119.1556911,3,50,boost_bonus,HR 201 | 123.734033,4,50,boost_bonus,HR 202 | -------------------------------------------------------------------------------- /Chapter03/house_prices_aug.csv: -------------------------------------------------------------------------------- 1 | Property_price,size,number.bathrooms,number.bedrooms,number.entrances,size_balcony,size_entrance 2 | 220,36,7,5,2,9,10 3 | 46.41907632,4.898979486,2,1,3,9,18 4 | 60.60797548,11.91637529,7,1,4,5,11 5 | 62.07797423,10.39230485,3,2,5,7,16 6 | 90.16924595,13.74772708,1,5,2,6,12 7 | 72.05899165,10.48808848,7,2,1,8,12 8 | 61.63508259,11.13552873,1,2,4,5,13 9 | 84.22851391,12.60952021,6,3,3,9,14 10 | 48.54054629,6.480740698,5,1,3,7,20 11 | 59.45236119,9.219544457,4,5,3,9,12 12 | 48.37483716,6.633249581,4,5,1,6,12 13 | 65.46812609,9.643650761,7,3,1,5,17 14 | 67.95690755,10.72380529,7,1,3,6,11 15 | 62.99423612,9.695359715,7,4,2,9,13 16 | 42.52083122,4.472135955,6,1,5,7,14 17 | 74.26251695,12.60952021,6,3,4,7,12 18 | 70.26972201,10.48808848,5,6,5,7,10 19 | 89.1645952,13.49073756,5,6,2,6,12 20 | 40.43612361,4.69041576,5,2,1,6,15 21 | 82.35373979,10.58300524,3,5,3,7,20 22 | 71.77601395,11.13552873,1,5,5,9,14 23 | 103.1586788,13.41640786,5,6,3,6,18 24 | 69.65160857,9.949874371,7,5,2,8,14 25 | 92.44144055,13.74772708,2,3,3,5,10 26 | 53.09649297,7.416198487,4,1,5,9,20 27 | 85.22804783,13.6381817,3,4,3,5,20 28 | 37.23406967,5.099019514,5,3,3,8,14 29 | 55.80781226,8.185352772,7,6,1,5,17 30 | 89.18551112,12.60952021,2,6,1,8,10 31 | 102.1660259,13.6381817,5,6,2,6,14 32 | 82.88948351,11.70469991,4,6,5,9,20 33 | 89.12019103,13.60147051,7,2,1,9,16 34 | 36.81469227,6.164414003,4,2,5,6,11 35 | 49.34911991,5.291502622,4,6,5,9,18 36 | 85.64732919,12.28820573,7,5,1,8,16 37 | 73.40118732,10.44030651,4,2,4,9,15 38 | 46.43665292,5.477225575,4,5,2,5,17 39 | 43.77359262,4.472135955,3,5,4,9,16 40 | 65.40563671,10.86278049,4,2,1,8,11 41 | 66.25603595,11.22497216,1,2,5,6,16 42 | 87.9837631,13.52774926,6,4,1,5,10 43 | 49.67850168,9,3,4,2,5,16 44 | 82.14378665,12.24744871,7,2,2,5,15 45 | 88.30672679,13.49073756,4,5,4,9,17 46 | 82.61064324,13.37908816,2,1,3,9,20 47 | 74.29448528,10.58300524,6,3,4,9,20 48 | 60.9418918,11.26942767,3,4,3,5,12 49 | 76.78468129,11.78982612,6,2,1,8,17 50 | 91.99943475,13.82027496,3,6,4,7,15 51 | 49.63646715,8.660254038,5,3,2,5,13 52 | 56.19776441,10.44030651,2,4,3,6,20 53 | 72.30702759,10.67707825,5,3,5,6,15 54 | 94.89008868,13.07669683,7,4,2,5,14 55 | 90.96429415,13.7113092,5,4,1,5,20 56 | 37.48466627,4.582575695,2,4,5,9,17 57 | 69.67233025,12.68857754,1,4,1,6,19 58 | 50.10403082,7.280109889,1,2,2,9,18 59 | 67.25358047,10.24695077,4,5,3,9,20 60 | 38.66358117,7.416198487,2,1,5,5,20 61 | 71.36796048,11.74734012,2,4,1,6,12 62 | 88.92344016,13.96424004,1,6,4,7,13 63 | 46.17789763,5.830951895,7,1,1,9,20 64 | 45.54573489,6,3,3,1,9,19 65 | 48.76270426,7.937253933,7,2,4,6,13 66 | 51.9235996,7.280109889,3,1,4,8,17 67 | 68.35157133,10.58300524,2,1,2,6,11 68 | 90.3151922,13.6381817,7,4,5,5,10 69 | 59.06808277,6.92820323,1,2,2,9,12 70 | 40.17288762,4.472135955,5,4,4,5,13 71 | 109.1516542,13.85640646,6,5,1,9,20 72 | 68.29282779,10.34408043,6,5,5,9,20 73 | 43.53182147,5.196152423,2,6,3,9,12 74 | 76.63803336,11.53256259,6,5,4,7,19 75 | 94.80630771,13.85640646,3,3,2,8,15 76 | 76.3331215,11.74734012,3,2,2,7,18 77 | 69.24119855,9.797958971,7,1,5,5,12 78 | 59.23686643,8.185352772,7,4,5,9,19 79 | 97.22968129,14.10673598,2,6,5,6,10 80 | 66.98151902,9.219544457,5,6,1,7,14 81 | 55.39357696,8.426149773,1,1,4,7,19 82 | 68.446089,11.04536102,3,6,1,7,11 83 | 67.31520737,10.29563014,4,2,4,5,20 84 | 82.13349643,13.92838828,1,4,2,8,19 85 | 57.55704695,8.426149773,5,4,4,9,11 86 | 63.55420726,10.09950494,2,6,5,6,18 87 | 68.69615508,9.899494937,6,5,4,8,16 88 | 82.78690003,12.24744871,7,5,2,5,19 89 | 41.34250864,5.099019514,6,6,2,9,14 90 | 94.72372933,13.52774926,2,5,3,7,19 91 | 81.05248862,12.9614814,1,3,5,6,12 92 | 58.44795179,6.480740698,1,6,5,6,18 93 | 46.4976433,6,6,1,5,6,12 94 | 90.34842554,13.41640786,6,6,2,6,20 95 | 80.1826777,13.26649916,1,6,2,7,16 96 | 78.04743029,13.74772708,1,1,2,8,10 97 | 81.46429152,13.85640646,3,1,2,5,14 98 | 52.54901257,8.366600265,6,2,5,5,16 99 | 60.98635457,9.486832981,2,6,4,8,11 100 | 81.9424168,13.19090596,3,6,3,9,10 101 | 51.23753313,7.745966692,6,5,5,6,10 102 | 70.42733324,11.13552873,2,3,3,6,17 103 | 91.2896567,13.3041347,4,3,1,9,10 104 | 60.64627736,8.602325267,5,6,2,6,17 105 | 68.29845599,11.83215957,2,1,2,6,18 106 | 48.03902664,8.831760866,5,4,4,8,11 107 | 57.59025317,8.185352772,1,4,4,6,17 108 | 77.9528505,12.36931688,2,2,1,7,10 109 | 45.52350141,4.69041576,4,3,5,6,10 110 | 54.21913506,6.92820323,1,4,5,6,20 111 | 51.7843783,7.211102551,5,5,2,8,15 112 | 43.84755675,7.348469228,3,4,3,6,11 113 | 81.94412028,13.7113092,2,3,3,8,11 114 | 54.49312309,9.38083152,4,2,1,9,12 115 | 92.05693649,13.67479433,4,5,3,5,17 116 | 64.49652543,8.485281374,7,3,1,7,15 117 | 90.09874054,13.22875656,6,1,2,6,14 118 | 74.67043532,12.32882801,3,3,2,5,12 119 | 55.92785261,6.633249581,2,5,5,6,15 120 | 38.87116379,6.403124237,1,4,2,6,13 121 | 73.97394834,12.08304597,7,4,2,5,16 122 | 90.6568081,12.76714533,4,6,5,7,14 123 | 72.24384156,10.72380529,5,1,4,7,14 124 | 79.14162052,10.90871211,7,4,3,8,10 125 | 88.72140432,12.80624847,4,6,3,6,18 126 | 57.2451302,8.717797887,5,5,2,8,13 127 | 86.7298421,12.28820573,4,6,3,6,12 128 | 81.71335796,13.3041347,3,2,5,6,16 129 | 76.74353704,10.72380529,7,4,1,7,20 130 | 92.3979868,12.4498996,7,6,3,9,20 131 | 58.99802611,9.433981132,7,4,2,7,16 132 | 40.24360916,7.874007874,2,1,3,5,16 133 | 67.30482213,12.9614814,2,2,2,6,20 134 | 48.0674403,5,6,4,5,6,13 135 | 55.57840431,6.403124237,6,5,3,5,11 136 | 33.00077116,4.472135955,5,2,4,6,12 137 | 83.28522857,13.26649916,1,6,1,6,14 138 | 47.61967058,4.472135955,2,6,4,5,17 139 | 100.3030607,14.10673598,6,6,2,9,20 140 | 41.93659852,5.916079783,6,5,5,8,11 141 | 53.58414316,6.557438524,3,5,4,8,18 142 | 62.66175055,10.14889157,2,2,1,9,13 143 | 82.6781033,13.19090596,1,6,1,5,15 144 | 88.55675811,14.07124728,4,1,4,5,16 145 | 45.41450008,7.874007874,5,3,1,6,14 146 | 60.84201572,6.08276253,6,6,3,9,14 147 | 93.3415584,13,4,4,5,7,11 148 | 47.2178384,8.246211251,2,2,2,8,16 149 | 64.99571253,9.949874371,7,3,5,6,14 150 | 69.15476758,11.26942767,7,1,3,9,13 151 | 54.28772249,5.744562647,5,1,3,5,20 152 | 45.50511741,8.366600265,3,1,1,5,12 153 | 58.1482452,7.549834435,7,3,1,6,19 154 | 58.35072232,6.8556546,6,6,3,9,19 155 | 62.78067726,7.280109889,4,5,5,5,12 156 | 76.00321173,12.88409873,4,4,5,6,18 157 | 86.67611745,12.72792206,1,6,4,9,19 158 | 77.56445873,11.26942767,7,2,3,5,11 159 | 72.24932949,13.41640786,4,1,5,8,15 160 | 71.78808153,11.04536102,6,3,1,5,11 161 | 69.53675597,10.67707825,3,3,4,7,18 162 | 86.63252033,12.36931688,5,4,5,8,10 163 | 94.7697148,12.92284798,4,4,2,8,18 164 | 77.60891844,11.70469991,6,2,1,6,18 165 | 42.53033985,4.69041576,5,2,5,5,17 166 | 87.52323953,13.6381817,5,4,2,7,12 167 | 47.52102704,5,2,6,5,9,12 168 | 81.67307775,12,7,5,3,8,18 169 | 48.10284101,7.141428429,6,1,2,7,20 170 | 93.29246823,13.34166406,5,3,2,8,19 171 | 62.81437307,9.327379053,1,1,4,9,20 172 | 57.60089412,8.366600265,5,1,1,6,10 173 | 79.19723877,11.61895004,4,6,5,6,10 174 | 38.58106428,7.745966692,2,6,1,5,17 175 | 63.08420343,9.110433579,7,4,4,9,16 176 | 80.29322851,12.56980509,4,1,2,6,14 177 | 68.50999408,9.327379053,6,5,5,8,11 178 | 38.90352816,7.071067812,6,1,3,6,19 179 | 48.49675906,6.32455532,1,4,1,8,15 180 | 56.74378801,9.273618495,1,6,1,7,18 181 | 93.401674,12.52996409,4,4,4,9,15 182 | 63.51053518,10.72380529,1,2,3,7,15 183 | 84.43605308,12.16552506,4,4,1,8,18 184 | 43.64731106,8.062257748,4,1,3,8,10 185 | 74.80729686,11.09053651,3,2,3,6,17 186 | 70.58067056,10.53565375,4,6,3,5,10 187 | 71.62921144,10.44030651,2,4,3,6,10 188 | 69.76657743,10.58300524,1,6,4,6,20 189 | 58.93534189,8.366600265,6,3,5,9,18 190 | 54.64493291,5.744562647,3,5,3,8,16 191 | 46.93728591,8,4,3,2,7,16 192 | 58.91569044,7.280109889,2,6,1,6,19 193 | 47.77322643,8.774964387,4,6,2,6,14 194 | 97.57078193,12.88409873,5,6,2,8,20 195 | 53.55055386,5.477225575,2,6,3,9,13 196 | 84.81088528,13.45362405,2,3,1,5,12 197 | 46.15037198,4.898979486,7,1,1,8,10 198 | 85.33346215,13.11487705,3,5,2,7,16 199 | 49.33866015,5.196152423,4,6,3,9,14 200 | 87.81383104,12.80624847,2,1,5,8,17 201 | 50.27487586,7.483314774,3,4,5,6,19 202 | 44.89233235,7.745966692,1,5,3,7,10 203 | 66.36191074,9.38083152,6,3,3,7,20 204 | 59.7657871,7.681145748,6,3,3,8,15 205 | 84.86465677,12.489996,1,2,3,9,20 206 | 82.26327134,13.41640786,4,1,4,7,10 207 | 57.83164611,9.643650761,4,5,1,5,18 208 | 51.93158298,6.92820323,5,3,4,9,12 209 | 63.81597589,8.774964387,7,2,3,8,18 210 | 47.98204066,6.92820323,7,4,4,8,16 211 | 88.11607453,13,7,2,5,6,12 212 | 71.92405764,12.28820573,4,3,4,5,14 213 | 54.58249128,7.348469228,4,6,4,8,10 214 | 92.64204093,13.89244399,5,5,3,5,19 215 | 84.5219908,13.52774926,4,3,3,5,13 216 | 68.67214089,9.110433579,4,3,4,5,12 217 | 98.80270799,14.10673598,5,2,2,8,17 218 | 54.86981023,7,4,3,5,9,15 219 | 39.98929912,5.477225575,6,4,4,8,13 220 | 40.77541393,5.567764363,3,4,5,7,11 221 | 55.81745638,7.745966692,7,3,1,8,15 222 | 49.57264172,9.16515139,1,1,1,8,12 223 | 79.26399415,12.4498996,3,4,4,6,19 224 | 74.97651245,12.40967365,3,2,1,7,18 225 | 77.33205989,11.83215957,1,3,1,9,18 226 | 53.88816154,8.888194417,6,2,5,5,13 227 | 85.07201454,12.28820573,7,3,3,7,13 228 | 69.38099785,11.5758369,7,1,3,6,11 229 | 39.27149979,6.8556546,3,2,1,6,17 230 | 72.65032581,11.48912529,5,3,4,8,20 231 | 46.01185598,8.246211251,3,1,2,5,20 232 | 72.20115814,12.76714533,5,4,1,5,15 233 | 76.69170968,10.77032961,2,6,5,7,11 234 | 47.2761099,6.633249581,7,2,4,5,13 235 | 49.84541767,5.744562647,1,6,3,7,14 236 | 59.5808761,10.67707825,4,4,1,6,10 237 | 37.77987352,4.898979486,1,3,2,9,11 238 | 57.06719761,9.591663047,7,2,3,6,10 239 | 86.31480293,13.52774926,2,3,2,7,16 240 | 55.62903671,8.246211251,5,5,2,8,10 241 | 74.90366902,10.72380529,7,2,5,6,20 242 | 64.32255883,11.66190379,1,3,4,7,10 243 | 46.93912932,8.426149773,5,3,3,5,14 244 | 43.79805968,7.071067812,1,3,3,8,12 245 | 100.7037981,13.41640786,7,4,4,9,14 246 | 58.32272581,11.09053651,2,5,2,5,18 247 | 54.03610358,4.795831523,5,2,2,7,17 248 | 62.26871335,11.66190379,2,1,3,6,14 249 | 46.40429298,6.92820323,1,2,2,9,13 250 | 65.82750888,11.13552873,6,4,1,5,20 251 | 50.32454177,8.544003745,4,4,2,9,12 252 | 77.10062773,11.66190379,3,3,1,9,15 253 | 69.37050017,12.489996,2,2,5,9,10 254 | 67.95169958,8,5,3,5,8,19 255 | 85.33828905,12.9614814,2,5,2,7,10 256 | 59.35317734,10.86278049,1,5,1,9,19 257 | 67.77740724,9.539392014,6,4,1,9,14 258 | 48.05165282,7.211102551,2,1,5,6,18 259 | 47.5728034,5.291502622,6,1,3,9,18 260 | 62.26219455,9.899494937,1,5,5,9,11 261 | 92.60077262,14.10673598,6,5,4,7,17 262 | 75.12536857,11.26942767,7,4,3,5,16 263 | 88.65303602,13.52774926,4,3,1,5,13 264 | 80.04572527,11.87434209,2,6,2,8,15 265 | 88.52046192,14.14213562,1,2,1,7,20 266 | 56.17006259,8.185352772,7,5,2,7,15 267 | 81.43029852,11.48912529,1,1,5,9,14 268 | 83.34524044,9.643650761,7,6,2,9,19 269 | 81.35875184,12.52996409,6,2,4,8,15 270 | 66.98425717,12,4,2,2,8,13 271 | 35.47469526,7.348469228,2,2,2,6,17 272 | 94.63643263,13.3041347,4,4,5,6,12 273 | 82.67520368,12,6,1,2,7,20 274 | 60.63062075,9.899494937,3,4,4,8,12 275 | 78.21429341,10.24695077,4,6,3,8,17 276 | 69.46108545,12,6,1,1,6,10 277 | 73.05462461,11.87434209,3,2,4,7,12 278 | 50.47882581,4.472135955,5,6,1,6,16 279 | 65.46625553,11,6,2,1,5,14 280 | 49.84296841,6.8556546,7,6,3,6,16 281 | 52.82883999,4.472135955,5,1,5,8,19 282 | 38.35270839,5.477225575,6,2,4,8,20 283 | 84.52674451,10.53565375,7,4,5,7,19 284 | 88.0569466,14,2,4,1,7,10 285 | 83.80552516,11.91637529,6,5,3,7,19 286 | 96.84512939,13.34166406,7,5,3,9,14 287 | 90.43933256,12.72792206,6,4,4,7,10 288 | 53.43417139,7,1,5,3,6,12 289 | 40.10549145,6.32455532,7,4,3,8,11 290 | 101.9203178,13.89244399,6,3,3,8,16 291 | 42.68973284,5.196152423,3,4,2,7,18 292 | 64.49048273,7.810249676,3,4,3,8,17 293 | 101.0752949,13.78404875,4,4,1,7,19 294 | 88.12846282,12.92284798,6,5,3,6,12 295 | 77.94407525,13.19090596,4,3,1,7,18 296 | 77.24622729,10.77032961,6,6,5,9,14 297 | 62.84652491,7.141428429,6,6,4,9,17 298 | 53.22057419,8.124038405,7,2,4,8,20 299 | 91.0138021,13.45362405,6,5,1,5,19 300 | 41.47284709,9,6,2,5,5,15 301 | 71.94771226,9.746794345,6,4,5,8,20 302 | 64.41338857,11.48912529,2,2,4,6,12 303 | 58.43170653,9.16515139,3,3,5,9,14 304 | 79.15269191,13.22875656,5,3,3,8,12 305 | 53.81271383,7.615773106,5,5,3,8,20 306 | 59.0743727,9.746794345,6,5,1,5,12 307 | 100.3274731,14,5,5,1,8,18 308 | 60.52573774,9.949874371,3,4,4,5,14 309 | 83.16152818,11.13552873,6,6,5,7,15 310 | 30.97671917,4.898979486,2,3,2,5,11 311 | 82.84908856,10.95445115,6,3,4,5,20 312 | 105.1093002,13.82027496,2,6,4,7,18 313 | 79.83251921,13.03840481,1,1,1,5,10 314 | 77.98157227,12.489996,5,3,4,5,15 315 | 77.68341732,13.85640646,3,4,3,7,18 316 | 46.51585819,4.582575695,3,5,4,7,18 317 | 85.96873656,11.83215957,5,5,1,8,11 318 | 69.27846489,11.35781669,7,1,4,6,14 319 | 75.7969017,10.95445115,5,4,4,9,19 320 | 42.54574623,5.385164807,6,1,5,8,13 321 | 48.46063026,7.141428429,3,2,1,7,13 322 | 61.72401022,8.185352772,5,1,5,6,12 323 | 85.41608097,13.15294644,3,6,1,9,20 324 | 69.34810949,10.86278049,4,3,1,9,11 325 | 56.0397292,9.899494937,4,1,2,7,10 326 | 59.49195664,7.745966692,4,6,3,9,14 327 | 62.10745539,9.486832981,2,2,4,6,14 328 | 50.44216192,4.582575695,7,5,5,8,16 329 | 67.86111358,13.52774926,3,1,3,6,19 330 | 93.33766786,12.489996,7,1,4,9,15 331 | 49.15797791,8,3,2,1,8,14 332 | 82.223346,13.45362405,3,2,5,9,18 333 | 74.89314236,10.63014581,3,5,3,6,20 334 | 103.7503073,13.96424004,2,6,4,7,18 335 | 63.9044882,10.86278049,4,6,2,5,16 336 | 91.50718471,13.15294644,3,6,4,7,17 337 | 51.86235353,7.483314774,1,6,1,7,11 338 | 51.92777028,6.8556546,2,4,4,7,17 339 | 70.53672153,11.44552314,5,2,5,6,15 340 | 69.69720485,11.78982612,2,1,2,5,11 341 | 40.64235439,5.196152423,7,1,4,7,17 342 | 91.62463369,14,1,4,5,6,19 343 | 85.80816462,13.56465997,7,1,4,6,11 344 | 67.52988952,9.848857802,6,1,5,9,15 345 | 75.07395302,11.74734012,2,6,5,6,13 346 | 52.00683898,5.385164807,2,3,3,9,13 347 | 76.05507484,12.72792206,1,2,4,8,11 348 | 48.72428794,8.717797887,2,4,2,5,16 349 | 84.22219549,12.76714533,3,3,5,5,14 350 | 58.39666356,10.24695077,2,2,4,9,13 351 | 78.89812495,13,6,2,5,6,14 352 | 70.07262415,9.055385138,6,2,4,6,16 353 | 76.20384746,11.66190379,6,6,4,7,19 354 | 46.65865947,6.32455532,5,3,2,7,15 355 | 57.77429637,8.602325267,5,5,4,6,19 356 | 84.95157722,12.04159458,7,2,5,6,17 357 | 74.54633198,13.19090596,2,6,1,6,10 358 | 57.92058152,9.848857802,2,6,4,5,17 359 | 65.49433472,11.40175425,1,2,1,5,10 360 | 63.64742545,8.544003745,1,4,5,9,20 361 | 88.86017163,13.3041347,2,6,4,8,14 362 | 51.1181097,6.782329983,6,5,4,9,11 363 | 66.30054634,11.09053651,2,4,5,7,10 364 | 92.51512715,13.92838828,2,6,5,7,18 365 | 41.83044897,5.099019514,1,3,4,9,12 366 | 29.86929733,6.782329983,1,1,4,7,20 367 | 77.77555244,11.70469991,2,6,4,6,18 368 | 80.72144426,12.9614814,2,6,4,8,13 369 | 48.597305,9.539392014,3,5,1,6,17 370 | 92.80182301,14.03566885,7,4,3,6,10 371 | 58.66263886,8.602325267,1,4,2,8,13 372 | 53.51353639,8.94427191,2,3,5,5,11 373 | 54.21656221,10.58300524,2,1,2,6,17 374 | 65.86190485,11.22497216,1,2,1,9,12 375 | 50.34276819,6.782329983,7,2,5,6,10 376 | 72.75951437,10.81665383,4,1,5,8,10 377 | 47.66242849,7.745966692,2,4,1,7,16 378 | 59.92145051,9.219544457,3,4,4,5,10 379 | 61.05559987,10.19803903,3,2,4,8,19 380 | 108.8155536,13.3041347,7,5,5,8,20 381 | 85.39509372,12.72792206,6,2,3,9,14 382 | 43.38336033,6.8556546,5,1,2,8,14 383 | 81.05161766,12.20655562,4,5,5,5,12 384 | 44.46941822,5.744562647,6,1,3,6,19 385 | 66.01306494,11.18033989,7,1,1,5,19 386 | 58.08559834,4.582575695,2,5,3,9,20 387 | 51.96337015,8,2,6,2,8,15 388 | 89.66670722,12.40967365,6,3,3,6,18 389 | 78.39227571,10.48808848,5,1,4,9,12 390 | 67.14115858,9.38083152,7,5,4,8,10 391 | 52.59408678,9.486832981,2,1,4,7,15 392 | 83.42723062,13.11487705,7,2,2,6,14 393 | 48.71471196,5.385164807,4,2,5,9,16 394 | 62.14631081,10.90871211,2,5,3,9,13 395 | 77.39172982,11.3137085,7,5,2,9,17 396 | 91.74795466,13.19090596,6,1,1,8,20 397 | 42.75594204,6,1,6,1,8,20 398 | 33.45363649,5.385164807,1,6,2,7,11 399 | 63.91093931,9.219544457,7,3,5,8,13 400 | 92.77409609,13.96424004,1,4,3,5,17 401 | 75.00939742,9.899494937,5,4,3,7,12 402 | 54.55877135,5.916079783,3,4,1,8,18 403 | 66.94683875,8.831760866,7,5,2,7,18 404 | 46.92659153,5.830951895,6,6,3,6,18 405 | 65.96151676,11.22497216,6,1,1,6,10 406 | 47.32570275,9.273618495,1,4,3,5,13 407 | 42.14448212,5.916079783,1,2,3,9,18 408 | 89.52307723,13.07669683,2,6,5,9,18 409 | 5,19,8,2,4,13,25 410 | 53.54290157,9.38083152,7,5,5,7,19 411 | 48.47748817,5.477225575,6,1,1,8,18 412 | 47.33785694,4.69041576,2,3,4,9,17 413 | 76.74547184,11.78982612,1,2,4,6,16 414 | 88.51366913,12.9614814,1,4,3,9,18 415 | 53.27843848,5.656854249,4,4,2,9,16 416 | 81.01866007,13.34166406,2,4,1,9,13 417 | 85.37860547,13.41640786,2,1,3,5,11 418 | 78.86246689,13.26649916,1,6,1,5,17 419 | 64.80224017,11.61895004,3,4,5,5,16 420 | 62.80974633,7.615773106,4,4,5,9,14 421 | 62.01849255,8.774964387,6,5,2,5,13 422 | 89.64758675,14.10673598,6,6,5,5,11 423 | 42.91833816,9.38083152,1,1,4,6,10 424 | 96.11716798,13.67479433,6,5,4,5,16 425 | 49.41415595,6.557438524,2,3,4,9,19 426 | 57.56513568,10.81665383,2,4,1,8,17 427 | 62.3945107,9.949874371,5,5,1,9,10 428 | 60.37936041,11.40175425,4,4,2,7,10 429 | 67.43781025,10.14889157,7,3,5,7,16 430 | 36.76219705,5.916079783,4,2,2,6,17 431 | 89.03842964,12.28820573,6,2,3,9,17 432 | 52.46256273,8.602325267,4,5,3,6,10 433 | 84.78203378,13.56465997,1,4,5,8,11 434 | 73.59907548,11.13552873,5,3,2,9,15 435 | 49.1580322,5.099019514,7,5,1,8,10 436 | 66.43761449,11.35781669,2,5,4,7,10 437 | 69.06791264,9.433981132,5,5,3,7,13 438 | 62.91160785,11.3137085,6,1,2,9,13 439 | 43.75406458,8.426149773,7,1,1,6,13 440 | 83.74480681,10.53565375,6,5,1,7,20 441 | 54.10987767,7.874007874,2,2,5,8,16 442 | 69.74134354,10.48808848,2,2,2,9,16 443 | 46.21090567,7.416198487,2,2,3,8,18 444 | 46.3017452,8.426149773,7,2,1,6,20 445 | 60.49269192,9,3,3,2,9,11 446 | 86.17297584,12.88409873,5,3,4,7,16 447 | 57.85138335,9.643650761,2,6,2,6,13 448 | 49.8139834,7.141428429,1,5,4,6,18 449 | 29.33205324,5.099019514,1,4,1,7,14 450 | 52.02204519,8.544003745,5,3,3,6,14 451 | 77.64942527,11.61895004,7,4,1,8,13 452 | 72.397163,12.04159458,4,5,5,5,16 453 | 91.20853227,13,5,4,5,6,18 454 | 31.40480326,5.477225575,1,3,1,5,12 455 | 50.80322829,7.348469228,5,3,2,9,14 456 | 86.37383921,11.78982612,5,4,3,8,18 457 | 80.65553491,12.80624847,2,2,4,6,12 458 | 73.03222021,12.72792206,1,1,4,7,14 459 | 46.56290492,8.306623863,3,2,5,8,20 460 | 64.35297915,8.366600265,6,4,5,6,19 461 | 35.4412353,4.898979486,7,1,2,5,13 462 | 81.66210513,12.72792206,3,3,2,9,15 463 | 85.16225652,13.41640786,3,2,2,8,15 464 | 67.36693766,8.602325267,5,6,1,9,15 465 | 66.23578666,10,6,1,1,8,14 466 | 53.78540917,7.810249676,7,2,4,7,14 467 | 82.17353619,10.90871211,5,2,1,7,19 468 | 65.92341309,12.04159458,4,4,5,5,11 469 | 39.04520645,6.403124237,5,6,2,9,10 470 | 54.23701703,8.246211251,1,4,5,6,16 471 | 59.49583764,10.58300524,1,1,1,6,20 472 | 76.36665212,12.08304597,4,4,5,6,20 473 | 55.3662953,9.055385138,4,3,1,7,20 474 | 41.24825238,4.795831523,4,4,2,7,18 475 | 55.99374269,7.211102551,6,6,4,6,11 476 | 73.02802899,9.433981132,7,2,4,6,13 477 | 68.0689176,11.40175425,2,3,3,8,10 478 | 42.55575862,8.717797887,1,2,3,7,10 479 | 62.07384175,9.899494937,6,4,1,6,10 480 | 89.43808728,13.34166406,4,2,2,7,19 481 | 63.71955483,11.04536102,4,1,1,8,10 482 | 66.9916165,10.14889157,5,3,3,7,13 --------------------------------------------------------------------------------