[Eventstudies-commits] r99 - in pkg: . R inst/tests man vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jul 23 12:54:21 CEST 2013


Author: vikram
Date: 2013-07-23 12:54:21 +0200 (Tue, 23 Jul 2013)
New Revision: 99

Modified:
   pkg/NAMESPACE
   pkg/R/ees.R
   pkg/R/eventstudy.R
   pkg/R/inference.bootstrap.R
   pkg/inst/tests/test_inr_inference.R
   pkg/man/eventstudy.Rd
   pkg/man/inference.bootstrap.Rd
   pkg/man/inference.wilcox.Rd
   pkg/vignettes/eventstudies.Rnw
Log:
Made some corrections; now check result is OK

Modified: pkg/NAMESPACE
===================================================================
--- pkg/NAMESPACE	2013-07-23 09:27:35 UTC (rev 98)
+++ pkg/NAMESPACE	2013-07-23 10:54:21 UTC (rev 99)
@@ -1,4 +1,4 @@
-export(inference.bootstrap, inference.wilcox, phys2eventtime,
+export(eventstudy, inference.bootstrap, inference.wilcox, phys2eventtime,
        remap.cumsum, remap.cumprod, remap.event.reindex, ees, eesPlot)
 export(marketResidual,
        excessReturn

Modified: pkg/R/ees.R
===================================================================
--- pkg/R/ees.R	2013-07-23 09:27:35 UTC (rev 98)
+++ pkg/R/ees.R	2013-07-23 10:54:21 UTC (rev 99)
@@ -817,7 +817,7 @@
   # Replaing NA's with zeroes
   es.w[is.na(es.w)] <- 0
   es.w <- remap.cumsum(es.w, is.pc=FALSE, base=0)
-  inference.Ecar(es.w)
+  inference.bootstrap(es.w)
 }
  
 #----------------------------------

Modified: pkg/R/eventstudy.R
===================================================================
--- pkg/R/eventstudy.R	2013-07-23 09:27:35 UTC (rev 98)
+++ pkg/R/eventstudy.R	2013-07-23 10:54:21 UTC (rev 99)
@@ -56,13 +56,13 @@
   if(inference == TRUE){
     ## Bootstrap
     if(inference.strategy == "bootstrap"){
-      result <- inference.bootstrap(z.e = es.w, to.plot = to.plot, xlab = xlab,
+      result <- inference.bootstrap(es.w = es.w, to.plot = to.plot, xlab = xlab,
                                     ylab = ylab, main = main)
     }
     ## Wilcoxon
     if(inference.strategy == "wilcoxon"){
-      result <- wilcox.CI(es.w = es.w, to.plot = to.plot, xlab = xlab,
-                          ylab = ylab, main = main)
+      result <- inference.wilcox(es.w = es.w, to.plot = to.plot, xlab = xlab,
+                                 ylab = ylab, main = main)
     }
   } else {
     ## Providing event frame as default output

Modified: pkg/R/inference.bootstrap.R
===================================================================
--- pkg/R/inference.bootstrap.R	2013-07-23 09:27:35 UTC (rev 98)
+++ pkg/R/inference.bootstrap.R	2013-07-23 10:54:21 UTC (rev 99)
@@ -4,7 +4,7 @@
 
 # This does bootstrap inference for the difference in the
 # average "car" between t1 and t2 (both in event time).
-# z.e is a zoo object, where rows are in event time
+# es.w is a zoo object, where rows are in event time
 # and columns are units of observation.
 # Sampling with replacement is done within the units of
 # observation. Each time, the Ecar(t1) and Ecar(t2) is
@@ -13,10 +13,10 @@
 #  Ecar(t2)/Ecar(t1)
 # But if operator="difference" is sent in, then the
 # statistic of interest shifts to Ecar(t2)-Ecar(t1).
-inference.change.boot <- function(z.e, t1, t2, operator="ratio", conf=.95) {
+inference.change.boot <- function(es.w, t1, t2, operator="ratio", conf=.95) {
   stopifnot(operator %in% c("ratio","difference"))
 
-  tmp <- t(as.matrix(z.e[c(t1,t2),]))
+  tmp <- t(as.matrix(es.w[c(t1,t2),]))
   if (operator=="ratio") {
     change <- tmp[,2]/tmp[,1]
   }
@@ -45,18 +45,18 @@
   abline(h=0,v=0)
 }
 
-# z.e is a zoo object with certain rows (e.g. from -10 to 10)
+# es.w 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.bootstrap <- function(z.e,to.plot=FALSE,
+inference.bootstrap <- function(es.w, to.plot=TRUE,
                                 xlab = "Event time",
                                 ylab = "Cumulative returns of response series",
-                                main = "Eventstudy plot") {
+                                main = "Event study plot") {
   Ecar <- function(transposed, d) {
     colMeans(transposed[d,], na.rm=TRUE)
   }
-  tmp <- t(as.matrix(z.e))
+  tmp <- t(as.matrix(es.w))
   b <- boot(tmp, Ecar, R=1000)
 
   results <- NULL
@@ -64,7 +64,7 @@
     results <- rbind(results, quantile(b$t[,i], prob=c(.025,.975)))
   }
   results <- cbind(results[,1], b$t0, results[,2])
-  rownames(results) <- rownames(z.e)
+  rownames(results) <- rownames(es.w)
   colnames(results) <- c("2.5%","Mean","97.5%")
   if(to.plot==TRUE){
     plotInference(inference=results, xlab, ylab, main)
@@ -77,7 +77,7 @@
 #####################
 inference.wilcox <- function(es.w, to.plot = TRUE, xlab = "Event time",
                       ylab = "Cumulative returns of response series",
-                      main = "Eventstudy plot"
+                      main = "Event study plot"
                       ){
   wx.res <- apply(es.w,1,function(x)
                   res <- wilcox.exact(x, alternative = "two.sided",
@@ -89,7 +89,7 @@
   result <- cbind(CI[,1], Mean, CI[,2])
   colnames(result) <- c("2.5%","Mean","97.5%")
   rownames(result) <- rownames(Mean)
-  if(to.plot = TRUE){
+  if(to.plot == TRUE){
     plotInference(inference = result, xlab, ylab, main)
   }
   return(result)

Modified: pkg/inst/tests/test_inr_inference.R
===================================================================
--- pkg/inst/tests/test_inr_inference.R	2013-07-23 09:27:35 UTC (rev 98)
+++ pkg/inst/tests/test_inr_inference.R	2013-07-23 10:54:21 UTC (rev 99)
@@ -19,13 +19,13 @@
 event_time_data <- phys2eventtime(inr_returns,eventslist,width=10)
 w <- window(event_time_data$z.e,start=-10,end=10)
 
-expect_that(inference.Ecar(w)[,2],
-                         equals(c(-0.00215361156303362, -0.00040191670837042, 0.00171845148444985, 
-                           0.00143799970419951, 0.00149260146357282, -0.00284892904228684, 
-                           0.0013220811191847, -0.000634983205805195, 0.00115930378269389, 
-                           -0.000508755768685365, -0.00190621828611177, 0.000128303517790052, 
-                           -0.000547070723466092, 0.000463708708964017, -0.00108666428087325, 
-                           -0.00121321855159642, 0.00216769754166339, -0.000166340225607797, 
-                           0.00117626759805196, 0.000207307545758795, 0.000602629204764948
-                           )))
+expect_that(inference.bootstrap(w)[,2],
+            equals(c(-0.00215361156303362, -0.00040191670837042, 0.00171845148444985, 
+                     0.00143799970419951, 0.00149260146357282, -0.00284892904228684, 
+                     0.0013220811191847, -0.000634983205805195, 0.00115930378269389, 
+                     -0.000508755768685365, -0.00190621828611177, 0.000128303517790052, 
+                     -0.000547070723466092, 0.000463708708964017, -0.00108666428087325, 
+                     -0.00121321855159642, 0.00216769754166339, -0.000166340225607797, 
+                     0.00117626759805196, 0.000207307545758795, 0.000602629204764948
+                     )))
 })

Modified: pkg/man/eventstudy.Rd
===================================================================
--- pkg/man/eventstudy.Rd	2013-07-23 09:27:35 UTC (rev 98)
+++ pkg/man/eventstudy.Rd	2013-07-23 10:54:21 UTC (rev 99)
@@ -7,10 +7,19 @@
 }
 
 \usage{
-eventstudy(inputData, eventList, width = 10, type = "marketResidual", 
-to.remap = TRUE, remap = "cumsum", levels = FALSE, inference = TRUE,
-inference.strategy = "bootstrap", to.plot = TRUE, xlab = "Event time",
-ylab = "Cumulative returns of response series", main = "Event study plot", ...)
+eventstudy(inputData = NULL,
+                       eventList,
+                       width = 10,
+                       levels =  FALSE,
+                       type = "marketResidual",
+                       to.remap = TRUE,
+                       remap = "cumsum",
+                       inference = TRUE,
+                       inference.strategy = "bootstrap",
+                       to.plot = TRUE,
+                       xlab = "Event time",
+                       ylab = "Cumulative returns of response series",
+                       main = "Event study plot", ...)
 }
 
 \arguments{
@@ -23,6 +32,7 @@
   \item{levels}{If the data is in returns format then levels is FALSE else TRUE}
   \item{inference}{This argument is used to compute confidence interval for the estimator}
   \item{inference.strategy}{If inference is TRUE then this argument gives an option to select different inference strategy to compute confidence intervals. Default to bootstrap.}
+  \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. }
   \item{xlab}{If to.plot is TRUE then the plot generated will take this X label}
   \item{ylab}{If to.plot is TRUE then the plot generated will take this Y label}	
   \item{main}{If to.plot is TRUE then the plot generated will take this as main title}
@@ -46,6 +56,7 @@
 
 \examples{ 
 ## Performing event study
+library(eventstudies)
 data("StockPriceReturns")
 data("SplitDates")
 

Modified: pkg/man/inference.bootstrap.Rd
===================================================================
--- pkg/man/inference.bootstrap.Rd	2013-07-23 09:27:35 UTC (rev 98)
+++ pkg/man/inference.bootstrap.Rd	2013-07-23 10:54:21 UTC (rev 99)
@@ -10,13 +10,13 @@
  }
 
 \usage{
-inference.bootstrap(z.e, to.plot = TRUE, xlab = "Event time", 
+inference.bootstrap(es.w, to.plot = TRUE, xlab = "Event time", 
 			 ylab = "Cumulative returns of response series", 
 			 main = "Event study plot")
 }
 
 \arguments{
-  \item{z.e}{z.e is the first component of the list returned by the function phys2eventtime.}
+  \item{es.w}{es.w 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. }
   \item{xlab}{If to.plot is TRUE then the plot generated will take this X label}
   \item{ylab}{If to.plot is TRUE then the plot generated will take this Y label}	
@@ -37,5 +37,5 @@
 es.results <- phys2eventtime(z=StockPriceReturns, events=SplitDates,width=5)
 es.w <- window(es.results$z.e, start=-5, end=+5)
 eventtime <- remap.cumsum(es.w, is.pc=FALSE, base=0)
-inference.bootstrap(z.e=eventtime, to.plot=FALSE)
+inference.bootstrap(es.w=eventtime, to.plot=FALSE)
 }
\ No newline at end of file

Modified: pkg/man/inference.wilcox.Rd
===================================================================
--- pkg/man/inference.wilcox.Rd	2013-07-23 09:27:35 UTC (rev 98)
+++ pkg/man/inference.wilcox.Rd	2013-07-23 10:54:21 UTC (rev 99)
@@ -10,13 +10,13 @@
  }
 
 \usage{
-inference.wilcox(z.e,to.plot = TRUE, xlab = "Event time", 
+inference.wilcox(es.w,to.plot = TRUE, xlab = "Event time", 
 			     ylab = "Cumulative returns of response series", 
 			     main = "Event study plot")
 }
 
 \arguments{
-  \item{z.e}{z.e is the first component of the list returned by the function phys2eventtime.}
+  \item{es.w}{es.w 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. }
   \item{xlab}{If to.plot is TRUE then the plot generated will take this X label}
   \item{ylab}{If to.plot is TRUE then the plot generated will take this Y label}	
@@ -39,5 +39,5 @@
 es.results <- phys2eventtime(z=StockPriceReturns, events=SplitDates,width=5)
 es.w <- window(es.results$z.e, start=-5, end=+5)
 eventtime <- remap.cumsum(es.w, is.pc=FALSE, base=0)
-inference.wilcox(z.e=eventtime, to.plot=FALSE)
+inference.wilcox(es.w=eventtime, to.plot=FALSE)
 }
\ No newline at end of file

Modified: pkg/vignettes/eventstudies.Rnw
===================================================================
--- pkg/vignettes/eventstudies.Rnw	2013-07-23 09:27:35 UTC (rev 98)
+++ pkg/vignettes/eventstudies.Rnw	2013-07-23 10:54:21 UTC (rev 99)
@@ -43,11 +43,11 @@
 
 In this package, there are three major functions
 \textit{phys2eventtime}, \textit{remap.cumsum} and
-\textit{inference.Ecar}. \textit{phys2eventtime} changes the
+\textit{inference.bootstrap}. \textit{phys2eventtime} changes the
 physical dates to event time frame on which event study analysis can
 be done with ease. \textit{remap.cumsum}
 can be used to convert returns to cumulative sum or product in the
-event time frame. \textit{inference.Ecar} generates bootstrap
+event time frame. \textit{inference.bootstrap} generates bootstrap
 inference for the event time response of the variable. 
 
 In the section below, we illustrate event study analysis using the
@@ -143,12 +143,12 @@
 inference. A detailed explanation of the methodology is presented in
 Patnaik, Shah and Singh (2013).
 This specific approach used here is based on
-\citet{davison1986efficient}. The \textit{inference.Ecar} function
+\citet{davison1986efficient}. The \textit{inference.bootstrap} function
 does the bootstrap to generate distribution of $\bar{CR}$. The
 bootstrap generates confidence interval at 2.5\% and 97.5\% for the estimate.
 
 <<>>=
-result <- inference.Ecar(z.e=es.cs, to.plot=TRUE)
+result <- inference.bootstrap(es.w=es.cs, to.plot=TRUE)
 @ 
 \begin{figure}[t]
   \begin{center}
@@ -156,7 +156,7 @@
     \setkeys{Gin}{width=0.8\linewidth}
     \setkeys{Gin}{height=0.8\linewidth}
 <<fig=TRUE,echo=FALSE>>=
-  result <- inference.Ecar(z.e=es.cs, to.plot=TRUE)
+  result <- inference.bootstrap(es.w=es.cs, to.plot=TRUE)
 @
 \end{center}
 \label{fig:one}



More information about the Eventstudies-commits mailing list