Kto by ste mi chceli pomoct a nemuseli vymyslat a improvizovat, tak prikladam zdrojaky co som skusal ja:
acf() bez class atributu
# How to compute acf ?
# see the book:
# Paul S.P. Cowpertwait · Andrew V. Metcalfe:
# Introductory Time Series with R
# pp 33
my_acvf <- function(x, k) {
# acvf() - autocovariance estimation
s = 0
for (t in 1:(length(x) - k)) {
s <- s + (x[t] - mean(x))*(x[t+k] - mean((x)))
}
return(s / (length(x) - 1))
}
my_acfk <- function(x, k) {
# acf() - autocorrelation estimation for given k
return (my_acvf(x, k) / my_acvf(x, 0))
}
my_acf <- function(x) {
# acf() - autocorrelation estimation returns the 3D-array
series <- deparse1(substitute(x))
x <- as.matrix(x)
my_acf_vector <- vector()
my_lag_vector <- seq(from = 0, along = x)
for (k in my_lag_vector) {
my_acf_vector <- c(my_acf_vector, my_acfk(x, k))
}
my_lag_array <- array(my_lag_vector, dim = c(length(my_lag_vector), 1, 1))
my_acf_array <- array(my_acf_vector, dim = c(length(my_acf_vector), 1, 1))
type <- "correlation"
sampleT <- as.integer(nrow(x))
my_acf_out <-
structure(
list(acf = my_acf_array, type = type, n.used = sampleT,
lag = my_lag_array, series = series, snames = colnames(x)))
return (my_acf_out)
}
acf() s class atributom
# How to compute acf ?
# see the book:
# Paul S.P. Cowpertwait · Andrew V. Metcalfe:
# Introductory Time Series with R
# pp 33
my_acvf <- function(x, k) {
# acvf() - autocovariance estimation
s = 0
for (t in 1:(length(x) - k)) {
s <- s + (x[t] - mean(x))*(x[t+k] - mean((x)))
}
return(s / (length(x) - 1))
}
my_acfk <- function(x, k) {
# acf() - autocorrelation estimation for given k
return (my_acvf(x, k) / my_acvf(x, 0))
}
my_acf <- function(x) {
# acf() - autocorrelation estimation returns the 3D-array
series <- deparse1(substitute(x))
x <- as.matrix(x)
my_acf_vector <- vector()
my_lag_vector <- seq(from = 0, along = x)
for (k in my_lag_vector) {
my_acf_vector <- c(my_acf_vector, my_acfk(x, k))
}
my_lag_array <- array(my_lag_vector, dim = c(length(my_lag_vector), 1, 1))
my_acf_array <- array(my_acf_vector, dim = c(length(my_acf_vector), 1, 1))
type <- "correlation"
sampleT <- as.integer(nrow(x))
my_acf_out <-
structure(
list(acf = my_acf_array, type = type, n.used = sampleT,
lag = my_lag_array, series = series, snames = colnames(x)),
class = "acf")
return (my_acf_out)
}