我有以下向量和acf函数( quantmod包、XML包、动物园包)
L<- 1
theurl <- "http://www.iasg.com/groups/group/transtrend/program/transtrend-diversified-
trend-program-enhanced-risk-usd"
tables <- readHTMLTable(theurl)
n.rows <- unlist(lapply(tables, function(t) dim(t)[1]))
MONTHLYPERFORMANCE<-tables[[which.max(n.rows)]]
z<- as.data.frame(MONTHLYPERFORMANCE);
z$Year<-NULL
z$YTD <- NULL
z$DD <- NULL
z <- z[nrow(z):1,];
s<-as.vector(t(z))
w<-as.numeric(s)
p<-na.omit(w)
x<-(p*0.01*L)
d<-length(na.omit(x))
x<- x[1:d]
#DETREND+DENOISE
s<-detrend(x, tt = 'linear', bp = c())
#AUTOCORRELATION
a<-acf(x)
b<-a[[1]]
c<-(b[2:length(b)])
posssignificance_level<-qnorm((1+0.95)/2)/sqrt(sum(!is.na(x)))
posssignificance_level
negsignificance_level<- -posssignificance_level
negsignificance_level
poscorr<-which(posssignificance_level<c)
negcorr<-which(negsignificance_level>c)
posautorrelation <- if(length(poscorr) == 0) Lag(s,0) else na.omit(posautorrelation <-
Lag(s, poscorr))
negautorrelation <- if(length(negcorr) == 0) Lag(s,0) else na.omit(negautorrelation <-
Lag(s, negcorr))然后,我想使所有由偏序关系和否定自动关系产生的级数由下面的表达式获得最小行数,无论是从偏序关系还是从否定自动关系。
shortest <- min(length(posautorrelation), length(negautorrelation))
posautorrelation <- tail(posautorrelation, shortest)
negautorrelation <- tail(negautorrelation, shortest)
tpos <-na.omit(posautorrelation); rownames(tpos)<-NULL
tneg <-na.omit(negautorrelation); rownames(tneg)<-NULL这很好,当我只有一个系列的积极和另一个消极。但是,如果“偏序关系”或“否定自动关系”产生多个列,则最短函数之和不同列的行数,从而妨碍“最短”表达式。是否有一种“最短”的方法来考虑后自动关系的一个列和否定关系的一个列。
发布于 2014-01-22 01:18:21
shortest <- min(length(posautorrelation[,1]), length(negautorrelation[,1]))https://stackoverflow.com/questions/21272185
复制相似问题