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
# minor changes from script by dsparks | |
# Letting plyr do the work for us. | |
# | |
# Install and load needed packages | |
doInstall <- TRUE # Change to FALSE if you don't want packages installed. | |
toInstall <- c("foreign", "plyr", "Hmisc", "ggplot2") | |
toInstall <- toInstall[!toInstall%in%library()$results[,1]] #check if present | |
if(doInstall&length(toInstall)!=0) | |
{install.packages(toInstall, repos = "http://cran.r-project.org")} |
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
gastwirth <- function(x,...){ | |
# gastwirth's location estimator | |
# discussed in Ronald Pearson's Exploring Data in Engineering, the Sciences, and Medicine | |
# and at http://exploringdatablog.blogspot.com/2012/03/gastwirths-location-estimator.html | |
ordstats = quantile(x, probs=c(1/3,1/2,2/3),...) | |
weights = c(0.3,0.4,0.3) | |
sum(weights*ordstats) | |
# | |
} |
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
# Copyright 2012 Felix Schönbrodt | |
# All rights reserved. | |
# | |
# FreeBSD License | |
# | |
# Redistribution and use in source and binary forms, with or without | |
# modification, are permitted provided that the following conditions are | |
# met: | |
# | |
# 1. Redistributions of source code must retain the above copyright |
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
cria.tau <- function(data){ | |
# Giolo, Suely Ruiz. "Turnbull's nonparametric estimator for interval-censored data'." | |
# Department of Statistics, Federal University of Paraná (2004): 1-10. | |
l <- data$left | |
r <- data$right | |
tau <- sort(unique(c(l,r[is.finite(r)]))) | |
return(tau) | |
} |
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
############################################################################################### | |
## Function washer.AV in R-language | |
## Original Author : Andrea Venturini ([email protected]) | |
## Venturini, A. (2011). Time Series Outlier Detection: A New Non Parametric Methodology | |
## (Washer). Statistica 71: 329-344. | |
################################################################################################ | |
washer.AV = function( dati ) # p t i y | |
{ # dati structure: phenom./date/series/values/... other | |
# example: Phenomenon Time Zone Value ... | |
# ----------- -------- -- ----- -------- |
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
arch_test <- function (x, order=10){ | |
# AutoRegressive Conditional Heteroskedasticity (ARCH) estimator | |
xsq <- x^2 | |
nobs <- length(x) | |
inds <- outer(0:(nobs - order - 1), order:1, "+") | |
xmat <- xsq[inds] | |
dim(xmat) <- dim(inds) | |
xreg <- lm(xsq[-1:-order] ~ xmat) | |
summary(xreg)$r.squared * (nobs - order) | |
} |
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
# improved list of objects | |
.ls.objects <- function (pos = 1, pattern, order.by, | |
decreasing=FALSE, head=FALSE, n=5) { | |
napply <- function(names, fn) sapply(names, function(x) | |
fn(get(x, pos = pos))) | |
names <- ls(pos = pos, pattern = pattern) | |
obj.class <- napply(names, function(x) as.character(class(x))[1]) | |
obj.mode <- napply(names, mode) | |
obj.type <- ifelse(is.na(obj.class), obj.mode, obj.class) | |
obj.size <- napply(names, object.size) |
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
####################### | |
# | |
# short investigation of id'ing breakpoints in data | |
# | |
# [email protected] | |
library("bcp") | |
library("ggplot2") | |
library("changepoint") | |
library("reshape") |
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
## | |
## demonstration of distributions overlapping on lineplots | |
## [email protected] | |
## Dec 11, 2012 | |
## | |
## in response to: http://stats.stackexchange.com/questions/45591/r-plot-time-indexed-densities/45614#45614 | |
library(ggplot2) # for plotting | |
library(lubridate) # for getting year from dates in dataset | |
library(plyr) # for getting annual mean easily |
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
## | |
## Sample code to teach about timezones in R | |
## [email protected] | |
## Dec 13, 2012 | |
## Time zones are important to understand when working with dates | |
## because the most common date class for R, POSIX, is actually a date/time | |
## class. (POSIX = "Portable Operating System Interface, | |
## an IEEE standard) | |
## |
OlderNewer