Skip to content

Instantly share code, notes, and snippets.

View eduardszoecs's full-sized avatar

Eduard Szöcs eduardszoecs

View GitHub Profile
X.1,AGS,Gemeinde,Land,bvlkg_2019,cx,cy,20200310,20200311,20200312,20200313,20200314,20200315,20200316
2,7131000,Ahrweiler,7,129727,7.07017,50.49524,0,0,0,2,2,3,8
3,7132000,Altenkirchen (Westerwald),7,128705,7.839916,50.79483,0,0,0,0,1,1,2
27,7331000,Alzey-Worms,7,129244,8.109496,49.78882,0,0,0,2,2,2,8
28,7332000,Bad Dürkheim,7,132660,8.155013,49.48546,4,4,6,7,8,14,17
4,7133000,Bad Kreuznach,7,158080,7.657812,49.81823,0,0,0,0,0,13,13
13,7231000,Bernkastel-Wittlich,7,112262,7.015531,49.93051,0,0,3,3,4,4,5
5,7134000,Birkenfeld,7,80720,7.281271,49.7158,0,0,0,0,0,0,0
6,7135000,Cochem-Zell,7,61587,7.178459,50.14493,0,0,0,2,3,6,23
29,7333000,Donnersbergkreis,7,75101,7.864106,49.64187,0,0,0,2,2,2,2
library(tidyverse)
## Something ------------------------------------
# plain sample
foo1 <- function(x, n){
s <- sample(c(-1, 1), n, replace = TRUE)
min(which(cumsum(s) == 0))
}
# addaptive sample length
foo2 <- function(nmax, step = 10000, start = 0) {
s <- sample(c(-1, 1), step, replace = TRUE)
# get data ----------------------------------------------------------------
library(Ecdat)
data("CRANpackages")
df <- rbind(CRANpackages,
data.frame(Version = c("3.2", "3.3") ,
Date = as.Date(c("2016-04-27", "2016-12-22")),
Packages = c(8329, 9687),
Source = c("Andrie de Vries", "Eduard Szöcs")
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@eduardszoecs
eduardszoecs / Deriv.R
Created July 27, 2016 13:58 — forked from gavinsimpson/Deriv.R
R functions to compute and plot the first derivative of a spline term in a GAM(M) fitted by `gam()` or `gamm()` in package mgcv
################################################
## Functions for derivatives of GAM(M) models ##
################################################
Deriv <- function(mod, n = 200, eps = 1e-7, newdata, term) {
if(inherits(mod, "gamm"))
mod <- mod$gam
m.terms <- attr(terms(mod), "term.labels")
if(missing(newdata)) {
newD <- sapply(model.frame(mod)[, m.terms, drop = FALSE],
function(x) seq(min(x), max(x), length = n))
@eduardszoecs
eduardszoecs / derivSimulCI.R
Created July 27, 2016 13:58 — forked from gavinsimpson/derivSimulCI.R
First derivatives and simultaneous confidence intervals for GAM spline terms
`derivSimulCI` <- function(mod, n = 200, eps = 1e-7, newdata, term,
samples = 10000) {
stopifnot(require("MASS"))
if(inherits(mod, "gamm"))
mod <- mod$gam
m.terms <- attr(terms(mod), "term.labels")
if(missing(newdata)) {
newD <- sapply(model.frame(mod)[, m.terms, drop = FALSE],
function(x) seq(min(x), max(x) - (2*eps), length = n))
names(newD) <- m.terms
@eduardszoecs
eduardszoecs / plt.R
Created December 3, 2015 18:41
plot data & model
plt <- function(df, mod){
# predict only for range in site
sites <- levels(df$site)
value_0p <- c(sapply(sites, function(y) seq(min(df$value_0[df$site == y]),
max(df$value_0[df$site == y]),
length.out = 333)))
# use the mean for init
pdat <- data.frame(value_0 = value_0p,
site = rep(sites, each = 333),
init = mean(df$init)
### Type1 Error
require(plyr)
require(reshape2)
require(MASS)
require(ggplot2)
nsims <- 100
# sample sizes
N <- c(3,6,9,12)
ctrl <- 2^(1:10)
# both as grid
require(plyr)
require(reshape2)
require(MASS)
require(ggplot2)
### Power
### Simulate data
# no of simulated datasets
nsims <- 100
# sample sizes