- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 eventstudies package .我正在使用 phys2eventtime(..)
设置我的数据。但是我得到
Error in `colnames<-`(`*tmp*`, value = integer(0)) :
attempt to set 'colnames' on an object with less than two dimensions
> es <- phys2eventtime(z=StockPriceReturns, events=SplitDates, width=10)
> (str(StockPriceReturns))
'zoo' series from 2000-04-03 to 2013-03-28
Data: num [1:3246, 1:30] NA NA NA NA NA NA NA NA NA NA ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:30] "Bajaj.Auto" "BHEL" "Bharti.Airtel" "Cipla" ...
Index: Date[1:3246], format: "2000-04-03" "2000-04-04" "2000-04-05" "2000-04-06" ...
NULL
> (str(zoo_Data))
'zoo' series from 2002-01-01 to 2013-08-20
Data: num [1:3036] 183 183 186 191 191 ...
Index: Date[1:3036], format: "2002-01-01" "2002-01-02" "2002-01-03" "2002-01-04" ...
NULL
- attr(*, "dimnames")=List of 2
之类的东西> (head(StockPriceReturns))
Bajaj.Auto BHEL Bharti.Airtel Cipla Coal.India Dr.Reddy
2000-04-03 NA 4.9171044 NA 6.810041 NA -3.2541653
2000-04-04 NA -8.3348496 NA -3.368606 NA -8.3353739
2000-04-05 NA 0.3305788 NA 0.836825 NA 0.2616345
2000-04-06 NA -2.7605266 NA -2.466056 NA -1.8941289
2000-04-07 NA 3.2543548 NA 7.690426 NA 7.6961041
2000-04-10 NA 3.3107586 NA 6.154276 NA 6.4769648
> (head(zoo_Data))
2002-01-01 2002-01-02 2002-01-03 2002-01-04 2002-01-07 2002-01-08
182.83 182.83 186.40 190.57 191.17 193.25
df data
:
> dfToZoo <- function(df) {
require(zoo)
date <- as.Date(df[, 1], format = '%d.%m.%Y')
#TODO have a look if the column are rightly named
with(df, zoo(TotalReturns, date))
}
csv_data <- read.csv(..., header = TRUE, sep = ";",stringsAsFactors=FALSE)
totalReturns <- (as.double(gsub(",",".",csv_data$TotalReturn)))
df <- data.frame(csv_data$Date, totalReturns)
names(df) <- c("Date" ,"TotalReturns")
zoo_Data <- dfToZoo(df)
attr(*, "dimnames")=List of 2
我的数据?
example data code
从库包:
library(eventstudies)
library(zoo)
###########################
# Load data
(data(SplitDates))
(data(StockPriceReturns))
data <- StockPriceReturns
(head(StockPriceReturns))
es <- phys2eventtime(z=StockPriceReturns, events=SplitDates, width=10)
es.w <- window(es$z.e, start=-10, end=10)
SplitDates[1:3,]
> (str(s_dates))
'data.frame': 36799 obs. of 2 variables:
$ unit: chr "ZAE000006284" "ZAE000006284" "ZAE000006284" "ZAE000006284" ...
$ when: Date, format: "2003-12-18" "2005-04-06" ...
NULL
> (str(zoo_Data))
'zoo' series from 2002-01-01 to 2013-08-20
Data: num [1:3036] 183 183 186 191 191 ...
Index: Date[1:3036], format: "2002-01-01" "2002-01-02" "2002-01-03" "2002-01-04" ...
NULL
> (str(SplitDates))
'data.frame': 22 obs. of 2 variables:
$ unit: chr "BHEL" "Bharti.Airtel" "Cipla" "Coal.India" ...
$ when: Date, format: "2011-10-03" "2009-07-24" ...
NULL
> (str(StockPriceReturns))
'zoo' series from 2000-04-03 to 2013-03-28
Data: num [1:3246, 1:30] NA NA NA NA NA NA NA NA NA NA ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:30] "Bajaj.Auto" "BHEL" "Bharti.Airtel" "Cipla" ...
Index: Date[1:3246], format: "2000-04-03" "2000-04-04" "2000-04-05" "2000-04-06" ...
NULL
library(eventstudies)
library(zoo)
s_dates <-
structure(list(unit = c("ZAE000006284", "ZAE000006284", "ZAE000006284",
"ZAE000006284", "ZAE000006284", "XS0430907989", "XS0430907989"
), when = structure(c(12404, 12879, 12879, 12880, 12930, 14411,
14411), class = "Date")), .Names = c("unit", "when"), row.names = c(NA,
7L), class = "data.frame")
zoo_Data <-
structure(c(182.83, 182.83, 186.4, 190.57, 191.17, 193.25, 190.57
), index = structure(c(11688, 11689, 11690, 11691, 11694, 11695,
11696), class = "Date"), class = "zoo")
es <- phys2eventtime(z=zoo_Data, events=s_dates, width=10)
Error in `colnames<-`(`*tmp*`, value = integer(0)) :
attempt to set 'colnames' on an object with less than two dimensions
> es.w <- window(es$z.e, start=-10, end=10)
Error in window(es$z.e, start = -10, end = 10) : object 'es' not found
zoo_data
时:
> library(eventstudies)
> library(zoo)
>
> s_dates <- dput(head(s_dates,30))
structure(list(unit = c("ZAE000006284", "ZAE000006284", "ZAE000006284",
"ZAE000006284", "ZAE000006284", "XS0430907989", "XS0430907989",
"XS0302626899", "XS0302626899", "XS0302626899", "XS0302626899",
"XS0302626899", "XS0302626899", "XS0266838746", "XS0187043079",
"XS0187043079", "XS0187043079", "XF0000TZ7757", "XF0000AK5197",
"XF0000AK5197", "XF0000AK5197", "XF0000AK5197", "XF0000AK5197",
"USU02681027", "USU026281027", "USU026281027", "USU026281027",
"USU026281027", "USU026281027", "USU026281027"), when = structure(c(12404,
12879, 12879, 12880, 12930, 14411, 14411, 14599, 14600, 15134,
15139, 15328, 15328, 13913, 14330, 14335, 14593, 13049, 12953,
12954, 12954, 12954, 12955, 12934, 13537, 13537, 13537, 13648,
13649, 13649), class = "Date")), .Names = c("unit", "when"), row.names = c(NA,
30L), class = "data.frame")
> zoo_Data <- dput(head(zoo_Data,30))
structure(c(182.83, 182.83, 186.4, 190.57, 191.17, 193.25, 190.57,
184.02, 181.34, 172.11, 169.73, 160.2, 175.09, 172.11, 170.92,
176.58, 171.51, 170.92, 173.9, 168.54, 167.34, 166.75, 166.45,
167.34, 164.37, 159.01, 158.11, 154.84, 156.63, 161.99), index = structure(c(11688,
11689, 11690, 11691, 11694, 11695, 11696, 11697, 11698, 11701,
11702, 11703, 11704, 11705, 11708, 11709, 11710, 11711, 11712,
11715, 11716, 11717, 11718, 11719, 11722, 11723, 11724, 11725,
11726, 11729), class = "Date"), class = "zoo")
>
> n = 20 ## number of observation
> cn <- unique(s_dates$unit) ## get response variable
>
> as.xts(zoo_Data)
>
> names(zoo_Data) <- cn
>
> es <- phys2eventtime(z=zoo_Data), events=s_dates, width=10)
Error in `colnames<-`(`*tmp*`, value = integer(0)) :
attempt to set 'colnames' on an object with less than two dimensions
> es.w <- window(es$z.e, start=-3, end=3)
Error in window(es$z.e, start = -3, end = 3) : object 'es' not found
最佳答案
phys2eventtime
将实际日期转换为事件日期。
因此,给定动物园时间序列和事件日期,它将实际日期转换为事件日期。这意味着,如果它在 zoo 对象的范围内找到一个事件日期,则该日期将变为 0,所有其他日期也相应地发生变化。
所以给这个事件日期对象:
unit when
1 ZAE000006284 2003-12-18
2 ZAE000006284 2005-04-06
3 ZAE000006284 2005-04-06
4 ZAE000006284 2005-04-07
5 ZAE000006284 2005-05-27
6 XS0430907989 2009-06-16
7 XS0430907989 2009-06-16
n = 20 ## number of observation
cn <- unique(s_dates$unit) ## get response variable
rr = range(s_dates$when) ## get date range
## COND2
index = seq(rr[1],rr[2],length.out=n)
mat = matrix(round(runif(n*2,min=150,max=200),2),ncol=2)
ev.dat = xts(mat,index)
## COND1
names(ev.dat) <- cn
head(ev.dat)
ZAE000006284 XS0430907989
2003-12-18 183.27 152.89
2004-04-01 195.23 172.78
2004-07-16 190.18 164.92
2004-10-29 182.24 191.19
2005-02-12 151.78 195.81
2005-05-29 153.78 189.27
(es <- phys2eventtime(z=ev.dat, events=s_dates, width=5))
(es.w <- window(es$z.e, start=-10, end=10))
head(es.w)
2 3 4 5
-4 197.28 197.28 197.28 197.28
-3 158.54 158.54 158.54 158.54
-2 180.56 180.56 180.56 180.56
-1 194.41 194.41 194.41 194.41
0 157.64 157.64 157.64 157.64
1 151.06 151.06 151.06 151.06
check.phys2ev <- function(ev.dat,s_dates){
is.sucess = lapply(s_dates$when,function(when){
inter = findInterval(when, index(ev.dat))
inter < nrow(ev.dat) && inter >1
})
sum(unlist(is.sucess)) >0 &
all(colnames(ev.dat) %in% s_dates$unit)
}
check.phys2ev(ev.dat,s_dates)
[1] TRUE
关于r - 使用 "dimnames"= List of 2 格式化动物园对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20878615/
我是 Java 世界的新手(因为我主要用 C/C++ 编写)。我在我的应用程序中使用 map 。由于 java.util.Map 是抽象的,我需要实例化它的实现。通常我使用 HashMap 像: Ma
我不确定为什么会收到 当我将 MATCH 与动物园对象一起使用时在索引中。假设我有以下内容: a 在哪里行来自: mon mc mc2 matched 2012-01-0
我有一个 .csv 文件,其中包含 4 列数据,以一分钟为间隔针对一列日期/时间。缺少某些时间戳,因此我尝试生成缺少的日期/时间并在 Y 列中为它们分配 NA 值。我以前使用其他格式完全相同的 .cs
我在 R 中有一个动物园对象,它包含每日数据,但缺少周末数据。当我尝试在对象上运行某些函数(例如 ar() )时,我收到错误: mkt.ar <- ar(zoo_object) Error in na
我有一个每日动物园 (xts),其中包含以下格式的几十年数据: head(almorol) 1973-10-02 1973-10-03 1973-10-04 1973-10-05 1973-10-06
我有一个动物园对象,有一个 yearqtr 索引,涵盖大约 50 年。绘制时,x 轴每 10 年显示一次标签,感觉有点贫瘠: b=zoo(1:200,as.yearqtr(1900+seq(1,200
我正在使用类似于以下摘录的数据集: head(nomis.lng.agg) quarter decile avg.val 1 2004 Q4 1
我有两个具有不同时间分辨率的时间序列(传感器数据)。来自“xts/zoo”类( TS1 )的时间序列包括每小时值,而其他时间序列( TS2 )具有更好的时间分辨率(每 10 分钟观察一次)。即对于 T
我是一名优秀的程序员,十分优秀!