[Eventstudies-commits] r47 - in pkg: . R man tests
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Apr 3 14:03:56 CEST 2013
Author: vikram
Date: 2013-04-03 14:03:56 +0200 (Wed, 03 Apr 2013)
New Revision: 47
Added:
pkg/tests/inr_inference.R
Removed:
pkg/WISHLIST
pkg/man/sp500.Rd
pkg/tests/subbarao.R
Modified:
pkg/DESCRIPTION
pkg/R/inference.Ecar.R
pkg/man/identifyextremeevents.Rd
pkg/man/inference.Ecar.Rd
pkg/man/inr.Rd
pkg/man/phys2eventtime.Rd
pkg/tests/test_eventstudy.R
Log:
Modified documentation files; removed WISHLIST, Changelog; Added a to.plot functionality in inference.Ecar; Data: Added eventstudy data-set and removed sp500.rda
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2013-03-14 12:11:15 UTC (rev 46)
+++ pkg/DESCRIPTION 2013-04-03 12:03:56 UTC (rev 47)
@@ -2,11 +2,11 @@
Type: Package
Title: Event study and extreme event analysis
Version: 0.04
-Date: 2011-06-20
+Date: 2013-04-02
Author: Ajay Shah, Vimal Balasubramaniam, Vikram Bahure
-Maintainer: Vimal Balasubramaniam <vimsaa at gmail.com>, Vikram Bahure <economics.vikram at gmail.com>
+Maintainer: Vikram Bahure <economics.vikram at gmail.com>
Depends: R (>= 2.12.0), zoo, xts, boot
Description: Implementation of short and long term event study methodology
License: GPL-2
LazyLoad: yes
-Packaged: 2013-02-14 10:33:06 UTC; t136
+Packaged: 2013-04-02 10:33:06 UTC; t136
Modified: pkg/R/inference.Ecar.R
===================================================================
--- pkg/R/inference.Ecar.R 2013-03-14 12:11:15 UTC (rev 46)
+++ pkg/R/inference.Ecar.R 2013-04-03 12:03:56 UTC (rev 47)
@@ -30,11 +30,25 @@
list(est=b$t0, lo=ci$bca[1,4], hi=ci$bca[1,5])
}
+# Plotting inference
+plotInference <- function(inference){
+ big <- max(abs(inference))
+ hilo <- c(-big,big)
+ width <- (nrow(inference)-1)/2
+ plot(-width:width, inference[,"Mean"], type="l", lwd=2, ylim=hilo, col="blue",
+ xlab="Event time", ylab="Cumulative returns of response series",
+ main=paste("Eventstudy plot"))
+ points(-width:width, inference[,"Mean"])
+ lines(-width:width, inference[,"2.5%"], lwd=1, lty=2, col="blue")
+ lines(-width:width, inference[,"97.5%"], lwd=1, lty=2, col="blue")
+ abline(h=0,v=0)
+}
+
# z.e is a zoo object with certain rows (e.g. from -10 to 10)
# that define the event window, and columns with data for units.
# This function does bootstrap inference for the entire
# Ecar, i.e. main graph of the event study.
-inference.Ecar <- function(z.e) {
+inference.Ecar <- function(z.e,to.plot=FALSE) {
Ecar <- function(transposed, d) {
colMeans(transposed[d,], na.rm=TRUE)
}
@@ -48,5 +62,8 @@
results <- cbind(results[,1], b$t0, results[,2])
rownames(results) <- rownames(z.e)
colnames(results) <- c("2.5%","Mean","97.5%")
- results
+ if(to.plot=TRUE){
+ plotInference(inference=results)
+ }
+ return(results)
}
Deleted: pkg/WISHLIST
===================================================================
--- pkg/WISHLIST 2013-03-14 12:11:15 UTC (rev 46)
+++ pkg/WISHLIST 2013-04-03 12:03:56 UTC (rev 47)
@@ -1,11 +0,0 @@
-Some of the modifications we hope to make shortly:
-
-1. Introduce asymmetry in the width option in phys2eventtime
-2. Add parametric tests to the system.
-3.
-4.
-5.
-6.
-7.
-
-
Modified: pkg/man/identifyextremeevents.Rd
===================================================================
--- pkg/man/identifyextremeevents.Rd 2013-03-14 12:11:15 UTC (rev 46)
+++ pkg/man/identifyextremeevents.Rd 2013-04-03 12:03:56 UTC (rev 47)
@@ -34,7 +34,7 @@
}
\examples{
-data(sp500)
-input <- diff(log(sp500))
+data(eventstudyData)
+input <- eventstudyData$sp500
output <- identifyextremeevents(input, prob.value=5)
}
Modified: pkg/man/inference.Ecar.Rd
===================================================================
--- pkg/man/inference.Ecar.Rd 2013-03-14 12:11:15 UTC (rev 46)
+++ pkg/man/inference.Ecar.Rd 2013-04-03 12:03:56 UTC (rev 47)
@@ -10,11 +10,12 @@
}
\usage{
-inference.Ecar(z.e)
+inference.Ecar(z.e,to.plot=FALSE)
}
\arguments{
\item{z.e}{z.e is the first component of the list returned by the function phys2eventtime.}
+ \item{to.plot}{This argument will generate an eventstudy plot of the inference estimated. If to.plot is equal to TRUE then function would generate the plot else it would not. }
}
\value{
@@ -26,22 +27,8 @@
}
\examples{
-## The function is currently defined as
-function (z.e)
-{
- Ecar <- function(transposed, d) {
- colMeans(transposed[d, ], na.rm = TRUE)
- }
- tmp <- t(as.matrix(z.e))
- b <- boot(tmp, Ecar, R = 1000)
- results <- NULL
- for (i in 1:ncol(b$t)) {
- results <- rbind(results, quantile(b$t[, i], prob = c(0.025,
- 0.975)))
- }
- results <- cbind(results[, 1], b$t0, results[, 2])
- rownames(results) <- rownames(z.e)
- colnames(results) <- c("2.5\%", "Mean", "97.5\%")
- results
- }
+data(eventDays)
+data(eventstudyData)
+eventtime <- phys2eventtime(z=eventstudyData, events=eventDays,width=5)
+inference.Ecar(z.e=eventtime, to.plot=FALSE)
}
\ No newline at end of file
Modified: pkg/man/inr.Rd
===================================================================
--- pkg/man/inr.Rd 2013-03-14 12:11:15 UTC (rev 46)
+++ pkg/man/inr.Rd 2013-04-03 12:03:56 UTC (rev 47)
@@ -2,17 +2,16 @@
\alias{inr}
\docType{data}
\title{
-INR/USD
+Exchange rate for Indian rupee: INR/USD
}
\description{
A sample of INR/USD rates from 1990 to 2011. It is stored as an xts object.
}
\usage{data(inr)}
-\format{ It is an xts object containing daily data from 1990 to 2011. The format is: chr "inr.rda"
+\format{ It is an xts object containing daily data from 1990 to 2011. The format is: chr 'inr.rda'
}
\examples{
data(inr)
-str(inr)
## maybe str(inr.rda) ; plot(inr.rda) ...
}
\keyword{datasets}
Modified: pkg/man/phys2eventtime.Rd
===================================================================
--- pkg/man/phys2eventtime.Rd 2013-03-14 12:11:15 UTC (rev 46)
+++ pkg/man/phys2eventtime.Rd 2013-04-03 12:03:56 UTC (rev 47)
@@ -28,61 +28,9 @@
\author{Ajay Shah, Vimal Balasubramaniam}
\examples{
-##---- Should be DIRECTLY executable !! ----
-##-- ==> Define data, use random,
-##-- or do help(data=index) for the standard data sets.
-
-## The function is currently defined as
-function (z, events, width = 10)
-{
- events$unit <- as.character(events$unit)
- timeshift <- function(x, when) {
- location <- findInterval(when, index(x))
- if ((location <= 1) | (location >= length(x))) {
- return(list(result = NULL, outcome = "wrongspan"))
- }
- remapped <- zoo(as.numeric(x), order.by = (-location +
- 1):(length(x) - location))
- list(result = remapped, outcome = "success")
- }
- outcomes <- character(nrow(events))
- z.e <- zoo(1, order.by = as.integer(1))
- for (eventnum in 1:nrow(events)) {
- if (!(events$unit[eventnum] \%in\% colnames(z))) {
- outcomes[eventnum] <- "unitmissing"
- next
- }
- attempt <- timeshift(z[, events$unit[eventnum]], events$when[eventnum])
- if (attempt$outcome == "success") {
- z.e <- cbind(z.e, attempt$result)
- }
- outcomes[eventnum] <- attempt$outcome
- }
- outcomes <- outcomes
- z.e <- z.e[, -1]
- colnames(z.e) <- which(outcomes == "success")
- badcolumns <- NULL
- if (width > 0) {
- for (i in 1:ncol(z.e)) {
- tmp <- z.e[, i]
- tmp <- na.locf(tmp, na.rm = FALSE, maxgap = 4)
- tmp <- na.locf(tmp, na.rm = FALSE, maxgap = 4, fromLast = TRUE)
- tmp2 <- window(tmp, start = -width, end = +width)
- if (any(is.na(tmp2))) {
- outcomes[as.numeric(colnames(z.e)[i])] <- "wdatamissing"
- badcolumns <- c(badcolumns, i)
- }
- else {
- z.e[, i] <- tmp
- }
- }
- if (any(outcomes == "wdatamissing")) {
- z.e <- z.e[, -badcolumns]
- }
- }
- stopifnot(sum(outcomes == "success") == NCOL(z.e))
- list(z.e = z.e, outcomes = factor(outcomes))
- }
+data(eventDays)
+data(eventstudyData)
+phys2eventtime(z=eventstudyData, events=eventDays,width=5)
}
\keyword{ phys2eventime }
Deleted: pkg/man/sp500.Rd
===================================================================
--- pkg/man/sp500.Rd 2013-03-14 12:11:15 UTC (rev 46)
+++ pkg/man/sp500.Rd 2013-04-03 12:03:56 UTC (rev 47)
@@ -1,20 +0,0 @@
-\name{sp500}
-
-\docType{data}
-
-\alias{sp500}
-
-\title{Times series data}
-
-\description{
- It is time series data for S&P 500 from 2000-02-10 to 2011-07-29.
-}
-
-\usage{data(sp500)}
-
-\format{An object with class attributes \code{xts} and \code{zoo} containing a variable with 2036 observations.}
-
-\examples{
- data(sp500)
-}
-\keyword{datasets}
Copied: pkg/tests/inr_inference.R (from rev 45, pkg/tests/subbarao.R)
===================================================================
--- pkg/tests/inr_inference.R (rev 0)
+++ pkg/tests/inr_inference.R 2013-04-03 12:03:56 UTC (rev 47)
@@ -0,0 +1,18 @@
+library(eventstudies)
+
+data(inr)
+inr_returns<-diff(log(inr))[-1]
+eventslist<-data.frame(unit=rep("inr",10),
+ when=as.Date(c(
+ "2010-04-20","2010-07-02","2010-07-27",
+ "2010-09-16","2010-11-02","2011-01-25",
+ "2011-03-17","2011-05-03","2011-06-16",
+ "2011-07-26")))
+event_time_data<-phys2eventtime(inr_returns,eventslist,width=10)
+w<-window(event_time_data$z.e,start=-10,end=10)
+
+all.equal(inference.Ecar(w)[,2],c(-.000015327,-.002526819,.0011990000,.001193535,.001846734,
+ -.000105473,-.001659772,.001644518,-0.001325236,.001546369,
+ -.000809734,-.001499191,-.000289414,-.000003273,-.000416662,
+ -.001150000,-.000759748,.002306711,-.000487299,.001122457,
+ .000635890))
Deleted: pkg/tests/subbarao.R
===================================================================
--- pkg/tests/subbarao.R 2013-03-14 12:11:15 UTC (rev 46)
+++ pkg/tests/subbarao.R 2013-04-03 12:03:56 UTC (rev 47)
@@ -1,18 +0,0 @@
-library(eventstudies)
-
-data(inr)
-inr_returns<-diff(log(inr))[-1]
-eventslist<-data.frame(unit=rep("inr",10),
- when=as.Date(c(
- "2010-04-20","2010-07-02","2010-07-27",
- "2010-09-16","2010-11-02","2011-01-25",
- "2011-03-17","2011-05-03","2011-06-16",
- "2011-07-26")))
-event_time_data<-phys2eventtime(inr_returns,eventslist,width=10)
-w<-window(event_time_data$z.e,start=-10,end=10)
-
-all.equal(inference.Ecar(w)[,2],c(-.000015327,-.002526819,.0011990000,.001193535,.001846734,
- -.000105473,-.001659772,.001644518,-0.001325236,.001546369,
- -.000809734,-.001499191,-.000289414,-.000003273,-.000416662,
- -.001150000,-.000759748,.002306711,-.000487299,.001122457,
- .000635890))
Modified: pkg/tests/test_eventstudy.R
===================================================================
--- pkg/tests/test_eventstudy.R 2013-03-14 12:11:15 UTC (rev 46)
+++ pkg/tests/test_eventstudy.R 2013-04-03 12:03:56 UTC (rev 47)
@@ -18,12 +18,6 @@
"2004-01-02", "2004-01-08", "2004-01-14",
"2005-01-15", "2004-01-01", "2005-01-01")))
eventslist$unit <- as.character(eventslist$unit)
-# 1 It's fine, but prior to event date there's only 1 reading
-# 2 It's fine
-# 3 It's fine, but after event date there's only 1 reading
-# 4 Unit is fine, date is off
-# 5 Unit is fine, date is off
-# 6 Unit does not exist
# What we expect if we don't worry about width --
rawres <- structure(list(z.e = structure(c(NA, NA, NA, NA, NA, NA,
More information about the Eventstudies-commits
mailing list