당신이 찾고있는 것은 패널 데이터 구조입니다. 횡단면 시계열 데이터라고도하는 패널 데이터는 시간에 따라뿐만 아니라 요소에 따라 달라지는 데이터입니다. 귀하의 경우 waves
의 value
은 각 엔티티에서 시간에 따라 다르지만 group
은 엔티티에 따라 다릅니다. 일반적인 패널 데이터 형식을 얻으려면 간단한 gather
및 join
을 사용할 수 있습니다. 여기
library(tidyr)
library(dplyr)
panel_df = df %>%
gather(index, value) %>%
inner_join(lookup, by = "index") %>%
group_by(index) %>%
mutate(time = 1:n())
# index value group time
# <chr> <dbl> <chr> <int>
# 1 waves1 0.0000000 healthy 1
# 2 waves1 0.2474040 healthy 2
# 3 waves1 0.4794255 healthy 3
# 4 waves1 0.6816388 healthy 4
# 5 waves1 0.8414710 healthy 5
# 6 waves1 0.9489846 healthy 6
# 7 waves1 0.9974950 healthy 7
# 8 waves1 0.9839859 healthy 8
# 9 waves1 0.9092974 healthy 9
# 10 waves1 0.7780732 healthy 10
# # ... with 476 more rows
,
index
은 개체 차원을 나타내며, 나는 수동으로 패널 데이터의 시간 차원을 나타 내기 위해
time
변수를 만들었습니다.
library(ggplot2)
# Visualize all waves, grouped by health status
ggplot(panel_df, aes(x = time, y = value, group = index)) +
geom_line(aes(color = group))

# Only Healthy people
panel_df %>%
filter(group == "healthy") %>%
ggplot(aes(x = time, y = value, color = index)) +
geom_line()
# Compare healthy and unhealthy people's waves
panel_df %>%
ggplot(aes(x = time, y = value, color = index)) +
geom_line() +
facet_grid(. ~ group)

시간 차원 작업 :
# plot acf for each entity `value` time series
par(mfrow = c(3, 2))
by(panel_df$value, panel_df$index, function(x) acf(x))
012,351,641
당신이
ggplot2
와 함께 다음과 같은 일을 할 수있는 패널 데이터를 시각화하는 방법 마지막

library(forecast)
panel_df %>%
filter(index == "waves1") %>%
{autoplot(acf(.$value))}

상기
plm
패키지는 패널 데이터와 협력 우수하다. 계량 경제학의 다양한 패널 회귀 모델이 구현되었지만이 답변을 더 이상 만들지 않기 위해 나는 자체 연구를위한 몇 가지 링크를 남겨 둘 것입니다.
pdim
는 패널 데이터의 당신에게 개체 및 시간 차원을 이야기하며 균형 여부 :
library(plm)
# Check dimension of Panel
pdim(panel_df, index = c("index", "time"))
# Balanced Panel: n=6, T=81, N=486
- What is Panel Data?
- Getting Started in Fixed/Random Effects Models using R
- Regressions with Panel Data
나는 더 나은 데이터를 수정 한 데모.
는
은 데이터 :는
library(zoo)
w1 <- sin(seq(0,20,0.25))
w2 <- cos(seq(0,20,0.25))
w3 = w1*2
w4 = w2*0.5
w5 = w1*w2
w6 = w2^2
df <- data.frame(w1,w2,w3,w4,w5,w6, stringsAsFactors = FALSE)
names(df) <- paste("waves", 1:6, sep="")
waves <- zoo(df)
lookup <- data.frame(index = paste("waves", 1:6, sep=""),
group = c("healthy", "unhealthy"),
stringsAsFactors = FALSE)
당신은 여기에'data.table'를 사용할 수 있습니다. – agstudy