Skip to content

Instantly share code, notes, and snippets.

View oliviergimenez's full-sized avatar
🏠
Working from home

Olivier Gimenez oliviergimenez

🏠
Working from home
View GitHub Profile
# Kod modifierad från Rafael Irizarry
# https://simplystatistics.org/2017/08/08/code-for-my-educational-gifs/
library(dplyr)
library(magick)
library(ggplot2)
theme_set(theme_minimal())
# Simulera data.
N <- 100
Sigma <- matrix(c(1, 0.75, 0.75, 1), 2, 2) * 1.5
# AUTHOR: Shade Wilson
# EMAIL: shadew@uw.edu
# DESCRIPTION: The following function is a simulation of the random walk phenomena.
# It uses the runif() funtion to return a uniform random number from 0 to 1, which is then
# scaled up to between 0 and 2pi. The number is then used as an angle, and the coordinate
# changes are calculated using the sin and cos values. random_walk() has three optional
# arguments: time, gradient, and step_size.
# The time argument specifies how many points you want
# to create, or more generally, how long you want the simulation to run. There's a 1:1 ratio of
library(tidyverse)
url <- "https://www.metoffice.gov.uk/hadobs/hadcet/data/legacy/cetdl1772on.dat"
df_raw <- read_tsv(url, col_names = FALSE)
div_10 <- function(...){
.../10
}
# libraries needed
library(tidyverse)
library(viridis)
library(gganimate)
library(wbstats)
# rosling chart in one command
# pull the country data down from the World Bank - three indicators
library(glmmTMB)
library(mgcv)
library(magrittr)
## Continuous covariate
x <- seq(1,10, length=100)
## Set up penalized thin-plate regression spline for x
sm <- mgcv::smoothCon(s(x), data=as.data.frame(x))[[1]]
## null space columns
# The purpose of thise script is to generate a list of formula combinations,
# which can later be used for model fitting using unmarked::pcountOpen
library(tidyverse)
lambda_opts <- c("1","NorthCove")
gamma_opts <- c("1","NorthCove","Year")
omega_opts <- c("1","NorthCove","Year")
detec_opts <- c("1","NorthCove","Year")
param_list <- list(lambda_opts, gamma_opts, omega_opts, detec_opts)
################################################
## 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))
# Bioeconomic model from Milner-Gulland & Rowcliffe, p. 163-...
# define constants
K = 1000 # carrying capacity
r = 0.2 # intrinsic rate of increase
P = 105 # price
a = 200 # constant for cost calculation
b = 0.2 # constant for cost calculation
s = 10 # SD of the distribution for the cost
N1 = 500 # initial pop size
### Title: Back to basics: High quality plots using base R graphics
### An interactive tutorial for the Davis R Users Group meeting on April 24, 2015
###
### Date created: 20150418
### Last updated: 20150423
###
### Author: Michael Koontz
### Email: mikoontz@gmail.com
### Twitter: @michaeljkoontz
###
@oliviergimenez
oliviergimenez / lasso.R
Created October 25, 2023 13:57
Lasso for logistic regression
# Implements Lasso for logistic regression, both classical/bayesian ways
## 1. SIMULATION
# for reproducibility
set.seed(666)
# sample size
n <- 100