[Eventstudies-commits] r398 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Nov 28 12:27:18 CET 2014


Author: chiraganand
Date: 2014-11-28 12:27:18 +0100 (Fri, 28 Nov 2014)
New Revision: 398

Modified:
   pkg/R/eventstudy.R
Log:
Return model residuals as an attribute to the final object.

Modified: pkg/R/eventstudy.R
===================================================================
--- pkg/R/eventstudy.R	2014-11-28 10:38:32 UTC (rev 397)
+++ pkg/R/eventstudy.R	2014-11-28 11:27:18 UTC (rev 398)
@@ -98,6 +98,7 @@
             abnormal.returns <- abnormal.returns - (model$exposures[i] * firm$z.e[event.period, names.nonfirmreturns[i - 1]])
         }
 
+        attr(abnormal.returns, "residuals") <- model$residuals
         return(abnormal.returns)
       })
 
@@ -112,7 +113,8 @@
           warning("lmAMM() returned NULL\n")
           outputModel <- NULL
       } else {
-        outputModel <- do.call(merge.zoo, outputModel[!sapply(outputModel, is.null)])
+        outputResiduals <- lapply(outputModel, function(x) attributes(x)[["residuals"]])
+        outputModel <- do.call(merge.zoo, outputModel)
       }
     }
   } ## end AMM
@@ -147,6 +149,7 @@
           abnormal.returns <- firm$z.e[event.period, "firm.returns"] - model$coefficients["(Intercept)"] -
           (model$coefficients["market.returns"] * firm$z.e[event.period, "market.returns"])
 
+        attr(abnormal.returns, "residuals") <- model$residuals
         return(abnormal.returns)
       })
 
@@ -160,7 +163,8 @@
         warning("marketModel() returned NULL")
         outputModel <- NULL
       } else {
-        outputModel <- do.call(merge.zoo, outputModel[!sapply(outputModel, is.null)])
+        outputResiduals <- lapply(outputModel, function(x) attributes(x)[["residuals"]])
+        outputModel <- do.call(merge.zoo, outputModel)
       }
     }
 
@@ -231,7 +235,7 @@
   } ## end None
 
 
-  if (is.null(outputModel)) {
+  if (is.null(outputModel)) {           #:DOC
     final.result <- list(result = NULL,
                          outcomes = as.character(outcomes))
     class(final.result) <- "es"
@@ -276,6 +280,9 @@
   final.result <- list(result = outputModel,
                        outcomes = as.character(outcomes))
 
+  if (exists("outputResiduals")) {      # :DOC
+    attr(final.result, which = "model.residuals") <- outputResiduals
+  }
   attr(final.result, which = "event.window") <- event.window
   attr(final.result, which = "inference") <- inference
   if (inference == TRUE) {



More information about the Eventstudies-commits mailing list