[Eventstudies-commits] r170 - in pkg: R vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Feb 14 04:03:09 CET 2014


Author: vikram
Date: 2014-02-14 04:03:08 +0100 (Fri, 14 Feb 2014)
New Revision: 170

Modified:
   pkg/R/eventstudy.R
   pkg/R/inference.bootstrap.R
   pkg/vignettes/eventstudies.Rnw
Log:
Modified eventstudy function, updating man pages for eventstudy, Work in progress 

Modified: pkg/R/eventstudy.R
===================================================================
--- pkg/R/eventstudy.R	2014-02-13 14:45:45 UTC (rev 169)
+++ pkg/R/eventstudy.R	2014-02-14 03:03:08 UTC (rev 170)
@@ -7,10 +7,6 @@
                        remap = "cumsum",
                        inference = TRUE,
                        inference.strategy = "bootstrap",
-                       to.plot = TRUE,
-                       xlab = "Event time",
-                       ylab = "Cumulative returns of response series",
-                       main = "Event study plot",
                        ...) {
                                         # type = "marketResidual", "excessReturn", "AMM", "None"
   if (type == "None" && !is.null(firm.returns)) {
@@ -87,21 +83,21 @@
   if(inference == TRUE){
     ## Bootstrap
     if(inference.strategy == "bootstrap"){
-      result <- inference.bootstrap(es.w = es.w, to.plot = to.plot, xlab = xlab,
-                                    ylab = ylab, main = main)
+      result <- inference.bootstrap(es.w = es.w, to.plot = FALSE)
     }
     ## Wilcoxon
     if(inference.strategy == "wilcoxon"){
-      result <- inference.wilcox(es.w = es.w, to.plot = to.plot, xlab = xlab,
-                                 ylab = ylab, main = main)
+      result <- inference.wilcox(es.w = es.w, to.plot = FALSE)
     }
   } else {
     ## Providing event frame as default output
     result <- es.w
   }
+  if(to.remap==TRUE){remapping <- remap} else {remapping <- "None"}
     final.result <- list(eventstudy.output=result,
                          outcomes=as.character(es$outcomes),
-                         inference=inference.strategy, nlags=nlags)
+                         inference=inference.strategy,
+                         width=width, remap=remapping)
   class(final.result) <- "es"
   return(final.result)
 }
@@ -109,17 +105,33 @@
 #########################
 ## Functions for class es
 #########################
-print.es <- function(){
-
-
+print.es <- function(es.object){
+  cat("The", es.object$inference, "inference output for CI and",
+      colnames(es.object$eventstudy.output)[2], "response:", "\n")
+  es.object$eventstudy.output
 }
 
-summary.es <- function(){
-
-
+summary.es <- function(es.object){
+  cat("Event study", colnames(es.object$eventstudy.output)[2], "response with",
+      es.object$inference, "inference for CI:\n")
+  print(es.object$eventstudy.output)
+  cat("\n","Event outcome has",length(which(es.object$outcomes=="success")),
+      "successful outcomes out of", length(es.object$outcomes),"events:","\n")
+  es.object$outcomes
 }
 
-plot.es <- function(){
-
-
+plot.es <- function(es.object, xlab="Event time",
+                    ylab="", main="", col.es="dark slate blue"){
+  big <- max(abs(es.object$eventstudy.output))
+  hilo <- c(-big,big)
+  width <- (nrow(es.object$eventstudy.output)-1)/2
+  plot(-width:width, es.object$eventstudy.output[,2], type="l", lwd=2, ylim=hilo,
+       col=col.es,xlab= xlab, ylab = ylab,
+       main=paste(main))
+  points(-width:width, es.object$eventstudy.output[,2])
+  lines(-width:width, es.object$eventstudy.output[,"2.5%"],
+        lwd=1, lty=2, col=col.es)
+  lines(-width:width, es.object$eventstudy.output[,"97.5%"],
+        lwd=1, lty=2, col=col.es)
+  abline(h=0,v=0)
 }

Modified: pkg/R/inference.bootstrap.R
===================================================================
--- pkg/R/inference.bootstrap.R	2014-02-13 14:45:45 UTC (rev 169)
+++ pkg/R/inference.bootstrap.R	2014-02-14 03:03:08 UTC (rev 170)
@@ -30,17 +30,19 @@
 }
 
 # Plotting inference
-plotInference <- function(inference, xlab, ylab, main){
-  big <- max(abs(inference))
+plot.es <- function(es.object, xlab="Event time",
+                    ylab="", main="", col.es="dark slate blue"){
+  big <- max(abs(es.object$eventstudy.output))
   hilo <- c(-big,big)
-  width <- (nrow(inference)-1)/2
-  plot(-width:width, inference[,2], type="l", lwd=2, ylim=hilo,
-       col="dark slate blue",
-       xlab= xlab, ylab = ylab,
+  width <- (nrow(es.object$eventstudy.output)-1)/2
+  plot(-width:width, es.object$eventstudy.output[,2], type="l", lwd=2, ylim=hilo,
+       col=col.es,xlab= xlab, ylab = ylab,
        main=paste(main))
-  points(-width:width, inference[,2])
-  lines(-width:width, inference[,"2.5%"], lwd=1, lty=2, col="dark slate blue")
-  lines(-width:width, inference[,"97.5%"], lwd=1, lty=2, col="dark slate blue")
+  points(-width:width, es.object$eventstudy.output[,2])
+  lines(-width:width, es.object$eventstudy.output[,"2.5%"],
+        lwd=1, lty=2, col=col.es)
+  lines(-width:width, es.object$eventstudy.output[,"97.5%"],
+        lwd=1, lty=2, col=col.es)
   abline(h=0,v=0)
 }
 
@@ -66,7 +68,7 @@
   rownames(results) <- rownames(es.w)
   colnames(results) <- c("2.5%","Mean","97.5%")
   if(to.plot==TRUE){
-    plotInference(inference=results, xlab, ylab, main)
+    plot.es(inference=results, xlab, ylab, main)
   }
   return(results)
 }
@@ -101,7 +103,7 @@
   colnames(result) <- c("2.5%","Median","97.5%")
   rownames(result) <- rownames(Median)
   if(to.plot == TRUE){
-    plotInference(inference = result, xlab, ylab, main)
+    plot.es(inference = result, xlab, ylab, main)
   }
   return(result)  
 }

Modified: pkg/vignettes/eventstudies.Rnw
===================================================================
--- pkg/vignettes/eventstudies.Rnw	2014-02-13 14:45:45 UTC (rev 169)
+++ pkg/vignettes/eventstudies.Rnw	2014-02-14 03:03:08 UTC (rev 170)
@@ -317,34 +317,31 @@
 ## Event study without adjustment 
 es.na <- eventstudy(firm.returns = StockPriceReturns, eventList =
                     SplitDates, width = 10, to.remap = TRUE, 
-                    remap = "cumsum", 
-                    to.plot = TRUE, inference = TRUE, 
+                    remap = "cumsum", inference = TRUE, 
                     inference.strategy = "wilcoxon", type = "None")
                     
 
 ## Event study using market residual and bootstrap 
 es.mm <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, 
                     width = 10, to.remap = TRUE, remap = "cumsum", 
-                    to.plot = FALSE, inference = TRUE, 
-                    inference.strategy = "bootstrap", 
+                    inference = TRUE, inference.strategy = "bootstrap", 
                     type = "marketResidual", market.returns = nifty.index) 
-es.mm
 
 ## Event study using excess return and bootstrap 
 es.er <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, 
                     width = 10, to.remap = TRUE, remap = "cumsum", 
-                    to.plot = FALSE, inference = TRUE, 
-                    inference.strategy = "bootstrap", type = "excessReturn", 
-                    market.returns = nifty.index)
+                    inference = TRUE, inference.strategy = "bootstrap",
+                    type = "excessReturn", market.returns = nifty.index)
 
 ## Event study using augmented market model (AMM) and bootstrap
 es.amm <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, 
                      width = 10, to.remap = TRUE, remap = "cumsum", 
-                     to.plot = FALSE, inference = TRUE, 
-                     inference.strategy = "bootstrap", 
+                     inference = TRUE, inference.strategy = "bootstrap", 
                      type = "AMM", market.returns = nifty.index, 
                      others=inrusd, verbose=FALSE, 
                      switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1)
+print(es.na)
+summary(es.na)
 
 @
 



More information about the Eventstudies-commits mailing list