如何在R中进行时间序列分析,将时间“仓”转换为连续时间?

沃克

带有以下数据:

#demo data:
set.seed(1234)

library(tidyverse)
library(fs)
n = 100
time= c(15, 30, 60, 90, 120, 180, 240, 300)
treat = factor(c("trt1", "trt2", "tr1+2", "trt1+2+3"))
intensity = c(sample(1:400, n, replace=TRUE))
              df <- expand.grid(time= time, treat = treat, intensity=intensity)
df <- data.frame(
                time= rep(df$time, each = 100),
                intensity = rep(df$intensity),
                treat = rep(df$treat, each = 100)
)

我最终希望拟合一个模型,该模型试图将波动与物理上传统的阻尼振荡器函数进行比较。这是我的问题的图形视图:在此处输入图片说明

可能是我对如何使时间连续感到很愚蠢,但重要的是要保留这些值,而不仅仅是一个单变量的时间序列数据帧。否则,这就是我要做的。但是还有一个因素变量也应保留。

It should look more like this (excel quick graph) but I need to extract the mathematical guts of the function for such lines that would trace the peaks of the curve in the R output: 在此处输入图片说明

A solution would involve both: 1) being able to reproduce the curve in R, and 2) generating the density data over time needed to start fitting polynomial models.

DaveArmstrong

Here's the Density plot for the fake data:

df %>% 
  ggplot(aes(x=intensity, fill=treat)) + 
  geom_density(color="transparent", alpha=.25) + 
  facet_wrap(~as.factor(time), nrow=1) + 
  theme_bw() + 
  theme(panel.grid=element_blank())

在此处输入图片说明

Now, if you wanted to make that into a line plot, you could calculate the highest density value for each treatment-time pair and then plot it:

df %>% group_by(treat, time) %>% 
  summarise(d = max(density(intensity)$y)) %>% 
  ggplot(aes(x=time, y=d, colour=treat)) + 
  geom_point() + 
  geom_line() + 
  theme_classic() + 
  labs(x="Time", y="Intensity")

在此处输入图片说明

The last part of your ask was to generate the density data over time. If I understand what you want to do, you could do it as follows:

out <- df %>% group_by(treat, time) %>% 
  summarise(as.data.frame(density(df$intensity)[c("x", "y")]))

head(out)
# # A tibble: 6 x 4
# # Groups:   treat, time [1]
#   treat  time     x          y
#   <fct> <dbl> <dbl>      <dbl>
# 1 tr1+2    15 -20.5 0.00000608
# 2 tr1+2    15 -19.6 0.00000838
# 3 tr1+2    15 -18.7 0.0000114 
# 4 tr1+2    15 -17.8 0.0000153 
# 5 tr1+2    15 -17.0 0.0000203 
# 6 tr1+2    15 -16.1 0.0000267 

The x variable is the evaluation point for intensity and the y variable is the height of the density curve for that value of x.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

将数据框转换为 xts 进行时间序列分析时我做错了什么?

来自分类Dev

将数据集从“宽”格式转换为“长”格式,并将时间列转换为时间格式以进行时间序列分析

来自分类Dev

使用科学Python进行时间序列数据分析:对多个文件进行连续分析

来自分类Dev

使用R统计软件进行时间序列分析

来自分类Dev

如何在Kibana中进行时间范围搜索

来自分类Dev

如何在Powershell中进行时间“ HH:mm”比较?

来自分类Dev

如何在jQuery中进行时间检查?

来自分类Dev

使用R将连续时间序列数据转换为每日小时表示

来自分类Dev

使用R将连续的时间序列数据转换为每天的小时表示形式

来自分类Dev

如何在J / Jd中进行asof时间序列联接

来自分类Dev

将日期从字符转换为可以在R中的时间序列分析中使用的日期格式

来自分类Dev

将整数转换为时间并在R中进行计算

来自分类Dev

将时间的字符向量转换为正确的格式并在R中进行bin

来自分类Dev

如何进行时间分析

来自分类Dev

如何在R和组数据中创建时间仓

来自分类Dev

如何将时间分析转换为O(n)?

来自分类Dev

将数据转换为R中的时间序列

来自分类Dev

将数据帧转换为 R 中的时间序列

来自分类Dev

如何将数据帧转换为时间序列?

来自分类Dev

如何将时间序列数据转换为图像?

来自分类Dev

sql如何将时间序列数据转换为hoc

来自分类Dev

如何在R中将as_tibble()格式的时间序列数据转换为as_tsibble()格式?

来自分类Dev

如何在R中将时间序列栅格堆栈转换为矩阵或大列表?

来自分类Dev

将时间戳转换为 R 中的频率分箱时间序列?

来自分类Dev

如何将日期时间序列转换为以小时为单位的实际持续时间?

来自分类Dev

如何在本地时间进行时间同步?

来自分类Dev

用R分析时间序列

来自分类Dev

如何在go中进行功能持续时间细分(分析)

来自分类Dev

如何将UTC日期/时间转换为MDT和军事时间以进行反应应用?

Related 相关文章

  1. 1

    将数据框转换为 xts 进行时间序列分析时我做错了什么?

  2. 2

    将数据集从“宽”格式转换为“长”格式,并将时间列转换为时间格式以进行时间序列分析

  3. 3

    使用科学Python进行时间序列数据分析:对多个文件进行连续分析

  4. 4

    使用R统计软件进行时间序列分析

  5. 5

    如何在Kibana中进行时间范围搜索

  6. 6

    如何在Powershell中进行时间“ HH:mm”比较?

  7. 7

    如何在jQuery中进行时间检查?

  8. 8

    使用R将连续时间序列数据转换为每日小时表示

  9. 9

    使用R将连续的时间序列数据转换为每天的小时表示形式

  10. 10

    如何在J / Jd中进行asof时间序列联接

  11. 11

    将日期从字符转换为可以在R中的时间序列分析中使用的日期格式

  12. 12

    将整数转换为时间并在R中进行计算

  13. 13

    将时间的字符向量转换为正确的格式并在R中进行bin

  14. 14

    如何进行时间分析

  15. 15

    如何在R和组数据中创建时间仓

  16. 16

    如何将时间分析转换为O(n)?

  17. 17

    将数据转换为R中的时间序列

  18. 18

    将数据帧转换为 R 中的时间序列

  19. 19

    如何将数据帧转换为时间序列?

  20. 20

    如何将时间序列数据转换为图像?

  21. 21

    sql如何将时间序列数据转换为hoc

  22. 22

    如何在R中将as_tibble()格式的时间序列数据转换为as_tsibble()格式?

  23. 23

    如何在R中将时间序列栅格堆栈转换为矩阵或大列表?

  24. 24

    将时间戳转换为 R 中的频率分箱时间序列?

  25. 25

    如何将日期时间序列转换为以小时为单位的实际持续时间?

  26. 26

    如何在本地时间进行时间同步?

  27. 27

    用R分析时间序列

  28. 28

    如何在go中进行功能持续时间细分(分析)

  29. 29

    如何将UTC日期/时间转换为MDT和军事时间以进行反应应用?

热门标签

归档