Skip to content

Instantly share code, notes, and snippets.

View Ddedalus's full-sized avatar

Hubert Bereś Ddedalus

View GitHub Profile
@Ddedalus
Ddedalus / Henkel.Rmd
Created June 5, 2018 17:42
Remove some strange characters to form a valid column name
colnames()%<>% trimws %>% gsub("\\(%\\)", "pp", .) %>%
make.names %>% gsub("\\.+", "\\.", .)
# whitespace from the beginning/end is trimmed
# replaces (%) with a "pp" abbreviation for percentage
# all white chars are subed with a dot
# multiple dots are concatenated to a single one
require(magrittr)
@Ddedalus
Ddedalus / any.tex
Created May 22, 2018 16:52
LaTeX: Right alligned square
\raggedleft $ \square $
@Ddedalus
Ddedalus / Law of Large Numbers for Binomial.tex
Last active May 22, 2018 16:51
Multiline equations in LaTeX
\usepackage{amsmath}
% lazy numbering for aling*:
\newcommand{\numberthis}{\addtocounter{equation}{1}\tag{\theequation}}
%in the document:
\begin{align*}
&\Pb{X_n > n(p + \epsilon)} = \sum_{j = K}^{n} \Pb{X_n = j} \\
&\leq \sum_{j = K}^{n} \Pb{X_n = K} r_K ^{j-K}
\leq \sum_{j = K}^{\infty} \Pb{X_n = K} r_K ^{j-K} \\
&= \Pb{X_n = K} \cdot \frac{1}{1 - r_K} \numberthis \label{eq:bound}
@Ddedalus
Ddedalus / Law of Large Numbers for Binomial.tex
Created May 22, 2018 16:48
Sets and probability theory operators - commands for LaTeX preamble
% define basic sets:
\newcommand{\R}{\mathbb{R}} % real numbers
\newcommand{\N}{\mathbb{N}} % natural numbers
\newcommand{\Z}{\mathbb{Z}} % integers etc.
\newcommand{\bb}{\mathbb} % blackboard font
%and probability operators
\newcommand{\Pb}[1]{\mathbb{P}(#1)}
\newcommand{\Ex}[1]{\mathbb{E}(#1)}
@Ddedalus
Ddedalus / progressBar.Rmd
Created May 12, 2018 22:33
Progress bar by text in R
```{r}
pb <- txtProgressBar(min = 0, max = 20, style = 3)
for(i in 1:20){
Sys.sleep(0.1)
# update progress bar
setTxtProgressBar(pb, i)
}
close(pb)
```
@Ddedalus
Ddedalus / corrtest.Rmd
Created May 12, 2018 15:33
Check correlation between in/out degrees
```{r}
plot(degree(g5, mode = "in"), degree(n5, mode = "out"), type = "p")
cor.test(degree(g5, mode = "in"), degree(g5, mode = "out"))
```
@Ddedalus
Ddedalus / AssignAddin.R
Created May 10, 2018 15:40
A simple Addin template for R
AssignAddin <- function() {
rstudioapi::insertText(" <- ")
}
@Ddedalus
Ddedalus / mutual.multiple.loop.Rmd
Created May 7, 2018 23:51
Check various patologies in a graph R
which_mutual(g5) %>% table
which_multiple(g5) %>% table
which_loop(g5) %>% table
@Ddedalus
Ddedalus / density.Rmd
Created May 7, 2018 22:59
Get density function out of data in R
{plot(density(in_deg), col=2) # where in_deg is a list of degrees - one obs. per verticle
lines(density(out_deg), col=3)}
@Ddedalus
Ddedalus / qqmath.Rmd
Created May 7, 2018 22:48
Fit discrete distribution and qq plot in R
library(fitdistrplus)
library(lattice)
in_geom_fit <- fitdist(in_deg, "geom")
summary(in_geom_fit)
plot(in_geom_fit)
quantiles <- seq(0, 1, 0.05)
qqmath(~in_deg, distribution=function(p){ qgeom(p, prob = in_geom_fit$estimate)}, main="Q-Q plot against geometric distribution", xlab = "geometirc from estimate")