This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| plot_model(fit.4, grid=T, type="diag") | |
| plot_model(fit.1, grid=T, sort.est="sort.all", y.offset=1.0) | |
| plot_model(fit.1, type="eff") | |
| plot_model(fit.1, show.values = TRUE, value.offset = .3) | |
| plot_model(fit.1, type="re") | |
| plot_model(fit.1, type="std") | |
| plot_model(fit.1, type="resid") | |
| plot_model(fit.1, type="pred", grid=T, terms=c("curve_day [all]")) | |
| tab_model(fit.1, | |
| show.std=T, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dfnew2<-dfnew%>%dplyr::select(curve_day, ogn_id, | |
| lcn_id, feed_provided, | |
| feed_provided_cum, newField, | |
| animals_actual)%>%na.omit | |
| fit.1<-lmer(feed_provided_cum~ns(curve_day,3)+ | |
| (0+ns(curve_day,2)|newField/lcn_id), | |
| data=dfnew2) | |
| fit.2<-lmer(feed_provided_cum~ns(curve_day,3)+ | |
| animals_actual+ | |
| (0+ns(curve_day,2)|newField/lcn_id), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| master_data_tbl <- dfnew %>% | |
| filter(date_interval>"2021-06-10")%>% | |
| dplyr::select(feed_provided, | |
| lcn_id, | |
| newField, | |
| date_interval)%>% | |
| filter(!is.na(date_interval))%>% | |
| distinct()%>% | |
| group_by(lcn_id, newField) %>% | |
| filter(n() >= 30)%>% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| master_data_tbl <- dfnew %>% | |
| filter(date_interval>"2021-06-10")%>% | |
| dplyr::select(feed_provided, | |
| lcn_id, | |
| newField, | |
| date_interval)%>% | |
| filter(!is.na(date_interval))%>% | |
| distinct()%>% | |
| group_by(lcn_id, newField) %>% | |
| imputeTS::na_kalman(.)%>% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #### DATA EXPLORATION #### | |
| ggplot(df,aes(x=date_interval, | |
| y=feed_provided, col=as.factor(lcn_id))) + | |
| geom_point(alpha=0.1) + | |
| theme_bw()+ | |
| facet_wrap(~ogn_id)+ | |
| theme(legend.position = "none") | |
| df%>% | |
| filter(feed_provided_cum>0)%>% | |
| ggplot(.,aes(x=date_interval)) + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Add run identifier for days | |
| dfcurve<-df%>% | |
| filter(!is.na(curve_day)) | |
| dfcurve<-dfcurve[, colSums(is.na(dfcurve)) != nrow(dfcurve)] | |
| dfnocurve<-df%>%filter(is.na(curve_day) & !is.na(feed_provided_cum)) | |
| dfnocurve%>% | |
| arrange(lcn_id, date_interval)%>% | |
| group_by(lcn_id)%>% | |
| mutate(curve_day = ifelse(min(feed_provided_cum), 1, 0))%>% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rm(list = ls()) | |
| #### LIBRARIES #### | |
| library(readr) | |
| library(readxl) | |
| library(tidyverse) | |
| library(DataExplorer) | |
| library(mice) | |
| library(naniar) | |
| library(skimr) | |
| library(grid) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rm(list = ls()) | |
| library(tidyverse) | |
| library(readr) | |
| library(ggthemes) | |
| library(lubridate) | |
| library(zoo) | |
| library(gganimate) | |
| getwd() | |
| data_folder <- file.path("C:/Users/marcj/Nutreco/StatisticsPlatform/Website/ELearning/Workshops/CausalAnalysis/Covid/") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(readr) | |
| library(ggplot2) | |
| library(gganimate) | |
| library(tidyverse) | |
| library(ggrepel) | |
| library(lubridate) | |
| library(tidymodels) | |
| library(modeltime) | |
| library(tsbox) | |
| library(TSstudio) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(readr) | |
| library(stringr) | |
| library(tidyverse) | |
| library(zoo) | |
| library(grid) | |
| library(gridExtra) | |
| mygrid <- read_csv("mygrid.csv") | |
| mygrid$icds | |
| datesplit<-str_split(mygrid$icds, "_") | |
| df <- data.frame(matrix(unlist(datesplit), nrow=length(datesplit), byrow=TRUE)) |