[Eventstudies-commits] r414 - in pkg: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Mar 31 21:35:06 CEST 2015


Author: chiraganand
Date: 2015-03-31 21:35:06 +0200 (Tue, 31 Mar 2015)
New Revision: 414

Modified:
   pkg/R/marketModel.R
   pkg/man/marketModel.Rd
Log:
Fixed assignment of colnames, added details of NA handling.

Modified: pkg/R/marketModel.R
===================================================================
--- pkg/R/marketModel.R	2015-03-31 19:18:21 UTC (rev 413)
+++ pkg/R/marketModel.R	2015-03-31 19:35:06 UTC (rev 414)
@@ -5,7 +5,7 @@
     if (NCOL(firm.returns) == 1) {
         merged.object <- merge.zoo(firm.returns, market.returns, all = TRUE) #:DOC
         reg <- lm(firm.returns ~ market.returns, data = merged.object,
-                  na.action = na.exclude) # :DOC: na.exclude: NAs can
+                  na.action = na.exclude) # na.exclude: NAs can
                                           # be seen in prediction
 
         if (residuals == TRUE) {
@@ -19,12 +19,13 @@
         reg <- list()
         resids <- list()
 
-        ## :DOC: we don't push the whole data.frame into lm() because it
+        ## we don't push the whole data.frame into lm() because it
         ## does na.omit, thereby removing rows from some firms even if
         ## they don't have NAs in them.
         for (i in 1:NCOL(firm.returns)) {
+            cat("i:", i, "\n")
             merged.object <- merge.zoo(firm.returns[, i], market.returns, all = TRUE)
-            colnames(merged.object)[i] <- "firm.returns"
+            colnames(merged.object)[1] <- "firm.returns"
             reg[[i]] <- lm(firm.returns ~ market.returns, data = merged.object,
                            na.action = na.exclude)
 

Modified: pkg/man/marketModel.Rd
===================================================================
--- pkg/man/marketModel.Rd	2015-03-31 19:18:21 UTC (rev 413)
+++ pkg/man/marketModel.Rd	2015-03-31 19:35:06 UTC (rev 414)
@@ -4,7 +4,12 @@
 \title{Extract residuals from a market model}
 
 \description{This function extracts residuals from a market model using
-  function \code{stats:lm}.}
+  function \code{stats:lm}. \sQuote{na.exclude} is passed as
+  \sQuote{na.action} for \sQuote{lm}. For more than one firm, the
+  function merges \dQuote{market.returns} with each element of
+  \dQuote{firm.returns} before passing to \sQuote{lm} so that rows of
+  firms without \sQuote{NA}s are not removed from the zoo object.
+}
 
 \usage{marketModel(firm.returns, market.returns, residuals = TRUE)}
 
@@ -21,7 +26,7 @@
 
 \value{Residual returns unexplained by market index returns.}
 
-\author{Vikram Bahure}
+\author{Chirag Anand, Vikram Bahure}
 
 \examples{ 
 data("StockPriceReturns")
@@ -31,7 +36,7 @@
                          market.returns = OtherReturns$NiftyIndex,
                          residuals = TRUE)
 
-comparison <- merge(MarketResidual = mm.result$Infosys,
+comparison <- merge(MarketModel = mm.result$Infosys,
                     Infosys = StockPriceReturns$Infosys,
                     NiftyIndex = OtherReturns$NiftyIndex,
                     all = FALSE)



More information about the Eventstudies-commits mailing list