Skip to content

Instantly share code, notes, and snippets.

View Martin-Jung's full-sized avatar
🦆
Fixing bugs and saving ducks...

Martin Jung Martin-Jung

🦆
Fixing bugs and saving ducks...
View GitHub Profile
# Test of Significance, takes the same arguments as t.test() .
signif.test <- function(x, ...) {
p <- t.test(x, ...)$p.value
# List of p excuses retrieved from http://mchankins.wordpress.com/2013/04/21/still-not-significant-2/
p_excuses <- c(
"(barely) not statistically significant <p>",
"a barely detectable statistically significant difference <p>",
"a borderline significant trend <p>",
"a certain trend toward significance <p>",
---
title: "Reproducible R coding"
author: "Martin Jung"
date: "12.02.2015"
output:
ioslides_presentation:
highlight: zenburn
highlighter: highlight.js
hitheme: zenburn
slidy_presentation:
# By Martin Jung (2015)
# http://conservationecology.wordpress.com/
# Takes a IUCN species id code as input, which
# can ether be queried from the api (http://api.iucnredlist.org/)
# or directly from the full database downloadable here:
# http://api.iucnredlist.org/index/all.csv
isForestSpecialist <- function (inputID)
{
print(paste("Now processing ID",inputID))
[1] "Key farm variables: area, livestock (LSU), labour force and standard output (SO) by agricultural size of farm (UAA), legal status of holding and NUTS 2 regions"
[2] "Key variables: area, livestock (LSU), labour force and standard output (SO) by economic size of farm (SO in Euro), legal status of holding and NUTS 2 regions"
[3] "Key variables: area, livestock (LSU), labour force and standard output (SO) by type of farming (2-digit) and NUTS 2 regions"
[4] "Land use: number of farms and areas of different crops by agricultural size of farm (UAA) and NUTS 2 regions"
[5] "Land use: number of farms and areas of different crops by economic size of farm (SO in Euro) and NUTS 2 regions"
[6] "Permanent crops: number of farms and areas by size of permanent crop area and NUTS 2 regions"
# Include BAAD data
#http://www.esajournals.org/doi/abs/10.1890/14-1889.1
library(dplyr)
library(ggplot2)
fd <- tempfile()
download.file("http://www.esapubs.org/archive/ecol/E096/128/baad_data.zip",destfile = fd)
b <- unzip(fd)
data <- read.csv("baad_data/baad_data.csv",header=T) # the data
meta <- read.csv("baad_data/baad_dictionary.csv",header=T) # the column explanations
# Filter those out without an age
import os
import sys
import requests
basefname = 'Hansen_GFC2013_lossyear_%d%s_%03d%s.tif'
baseurl = 'http://commondatastorage.googleapis.com/earthenginepartners-hansen/GFC2013/%s'
def download(url, output):
@Martin-Jung
Martin-Jung / CreateMetrics.R
Last active December 15, 2015 00:16
Calculate average altmetric
# MJ 14/12/2015
#### Load or install packages ####
if(!require(devtools))install.packages("devtools");library(devtools)
if(!require(rAltmetric))install.packages("rAltmetric");library(rAltmetric)
if(!require(plyr))install.packages("plyr");library(plyr)
if(!require(ggplot2))install.packages("ggplot2");library(ggplot2)
# This script expects a csv file with title / year / journal / doi
refs <- read.csv("ScharlemannlabPublications.csv",header = T,stringsAsFactors = F)
# Arguments:
# - model = a clmm model
# - newdata = a dataframe of new data to apply the model to
# Returns a dataframe of predicted probabilities for each row and response level
fake.predict.clmm <- function(model, newdata) {
# Actual prediction function
pred <- function(eta, theta, cat = 1:(length(theta) + 1), inv.link = plogis) {
Theta <- c(-1000, theta, 1000)
sapply(cat, function(j) inv.link(Theta[j + 1] - eta) - inv.link(Theta[j] - eta))
}
stat_smooth_func <- function(mapping = NULL, data = NULL,
geom = "smooth", position = "identity",
...,
method = "auto",
formula = y ~ x,
se = TRUE,
n = 80,
span = 0.75,
fullrange = FALSE,
level = 0.95,