This file contains 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(tidyverse) | |
library(nlme) | |
# create a dummy dataframe | |
# Here the interruption takes place at week 51 | |
df<-tibble( | |
Time = 1:100, | |
Intervention = c(rep(0,50),rep(1,50)), | |
Post.intervention.time = c(rep(0,50),1:50), | |
quantity.x = c(sort(sample(200:300,size = 50,replace = T),decreasing = T)+sample(-20:20,50,replace = T),c(sort(sample(20:170,size = 50,replace = T),decreasing = T)+sample(-40:40,50,replace = T))) |
This file contains 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
# Example code to extract x and y values from a geom_smooth | |
library(tidyverse) | |
#make a dummy data set with 11 observations and increasing number | |
df<-tibble(month=1:11, | |
n = c(100,140,200,260,360,470,560,630,770,990,1100)) | |
This file contains 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
https://www.scribbr.com/statistics/akaike-information-criterion/ | |
An introduction to the Akaike information criterion | |
Published on March 26, 2020 by Rebecca Bevans. | |
The Akaike information criterion (AIC) is a mathematical method for evaluating how well a model fits the data it was generated from. In statistics, AIC is used to compare different possible models and determine which one is the best fit for the data. AIC is calculated from: | |
the number of independent variables used to build the model. | |
the maximum likelihood estimate of the model (how well the model reproduces the data). |
This file contains 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 (gtsummary) | |
Univariate Regression | |
The tbl_uvregression() function produces a table of univariate regression models. The function is a wrapper for tbl_regression(), and as a result, accepts nearly identical function arguments. The function’s results can be modified in similar ways to tbl_regression(). | |
trial %>% | |
select(response, age, grade) %>% | |
tbl_uvregression( | |
method = glm, | |
y = response, |
This file contains 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(ggplot2) | |
library(dplyr) | |
library(tidyr) | |
########################################################################################## | |
# Make a new kind of modelling which only predicts either right or left | |
########################################################################################## | |
{ | |
## decorate lm object with a new class lm_right |
This file contains 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
#return text after match | |
a <- "asdfgpopgazelle" | |
data.table::tstrsplit(a, "pop")[[2]] | |
"gazelle" | |
#return all splits | |
a <- "asdfgpopgazelle" | |
> data.table::tstrsplit(a, "g") |
This file contains 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
#Bare bones updater for R version control. | |
######################################### | |
# Takes the long way round, by creating an installer script for packages. | |
# Accounts for weird behaviour where installing packages from within loops or apply commands doesn't handle | |
# dependencies well an leads to lots of packages failing to install. | |
# This script contains some code from updateR package, which has never worked for me on its own | |
# This can take a while but does a much better job of comprehensively rebuilding your catalogue | |
# Obviously this only works with CRAN packages, but will spit out a list of packages you need | |
# to manually install at the end. |
This file contains 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(utf8) | |
# second entry is encoded in latin-1, but declared as UTF-8 | |
x <- c("fa\u00E7ile", "fa\xE7ile", "fa\xC3\xA7ile") | |
Encoding(x) <- c("UTF-8", "UTF-8", "bytes") | |
as_utf8(x) # fails | |
#> Error in as_utf8(x): entry 2 has wrong Encoding; marked as "UTF-8" but leading byte 0xE7 followed by invalid continuation byte (0x69) at position 4 | |
# mark the correct encoding |
This file contains 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
require(ggplot2) | |
bingo<-tibble( | |
IMD = c("IMD1","IMD2","IMD3","IMD4","IMD5"), | |
ABSOLUTE.CHANGE = c(-3.1,-6.6,-1.6,-2.0,-0.9), | |
LCI = c(-0.4,-4.4,0.49,-1.06,-0.2), | |
UCI = c(-5.7,-8.8,-3.62,-2.9,-1.5) | |
) | |
ggplot(bingo,aes(x=IMD,y=ABSOLUTE.CHANGE,colour=IMD))+ |
This file contains 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
ssh-copy-id -i ~/.ssh/mykey user@host |
NewerOlder