我是R.的新手 已经采用了泵的每日数据。这些数据为两年,共有742个数字。
library(tidyverse)
sig_breaks <- c(zero = 0, "***" = 0.001, "**" = 0.01, "*" = 0.05, NS = Inf)
iris %>%
as_tibble() %>%
select_if(is.numeric) %>%
gather(key = measure, value = value, -Petal.Width) %>%
group_by(measure) %>%
do(mtx = cor.test(.$value, .$Petal.Width, method = "spearman")) %>%
broom::tidy(mtx) %>%
mutate(stars = cut(p.value, breaks = sig_breaks, include.lowest = T, labels = names(sig_breaks)[2:5]))
#> # A tibble: 3 x 7
#> # Groups: measure [3]
#> measure estimate statistic p.value method alternative stars
#> <chr> <dbl> <dbl> <dbl> <fct> <fct> <fct>
#> 1 Petal.Length 0.938 35061. 8.16e-70 Spearman's r… two.sided ***
#> 2 Sepal.Length 0.834 93208. 4.19e-40 Spearman's r… two.sided ***
#> 3 Sepal.Width -0.289 725048. 3.34e- 4 Spearman's r… two.sided ***
iris %>%
select_if(is.numeric) %>%
as.matrix() %>%
Hmisc::rcorr(type = "spearman") %>%
broom::tidy() %>%
filter(column1 == "Petal.Width" | column2 == "Petal.Width") %>%
mutate(stars = cut(p.value, breaks = sig_breaks, include.lowest = T, labels = names(sig_breaks)[2:5]))
#> column1 column2 estimate n p.value stars
#> 1 Sepal.Length Petal.Width 0.8342888 150 0.0000000000 ***
#> 2 Sepal.Width Petal.Width -0.2890317 150 0.0003342981 ***
#> 3 Petal.Length Petal.Width 0.9376668 150 0.0000000000 ***
cw<-read.csv("RCW1.csv")
str(cw)
data.frame': 742 obs. of 14 variables:
$ date : Date, format: "2016-04-01" "2016-04-02" "2016-04-03" ...
$ amp : num 226 227 0 225 226 ...
$ brg_de_tmp : num 38.1 38.1 39.6 41.6 41.5 ...
$ brg_nde_tmp: num 78.6 79.1 72 79.9 80.4 ...
$ kg : num 2.07 2.07 0.06 2.29 2.28 2.3 2.11 2.1 2.11 2.11 ...
$ level1 : num 8.45 8.46 8.69 8.67 8.43 8.6 8.39 8.5 8.46 8.65 ...
$ level2 : num 8.44 8.46 8.67 8.65 8.42 8.59 8.38 8.48 8.46 8.63 ...
$ mde_xvib : num 1.15 1.35 0.28 1.05 1.15 1.06 1.25 1.25 1.25 1.25 ...
$ mde_zvib : num 1.37 1.57 0.4 1.18 1.13 1.38 1.28 1.57 1.3 1.5 ...
$ rpm : num 296.46 296.91 -4.76 297.09 297.91 ...
$ mde_yvib : num 2.09 2.38 0.34 2 1.82 2.24 2.17 2.56 1.9 2.27 ...
$ m_nde_yvib : num 1.15 1.13 0.35 0.96 0.96 0.96 1.15 1.06 1.15 1.15 ...
$ m_nde_zvib : num 1.53 1.63 0.27 1.33 1.43 1.4 1.76 1.63 1.79 1.71 ...
$ permit : chr "#N/A" "#N/A" "CW Pump house: Motor stand" "#N/A" ...
我有两个问题。
编号1:如何在绘制以下代码时在X轴上获得“日期”。
cw_x <- xts(cw, order.by=as.Date(cw[,1], "%Y/%m/%d"))
cw_ts<-as.ts(cw_x)
> head(cw_ts)
Time Series:
Start = 1
End = 6
Frequency = 1
date amp brg_de_tmp brg_nde_tmp kg level1 level2 mde_xvib mde_zvib rpm mde_yvib
1 2016-04-01 226.05 38.06 78.61 2.07 8.45 8.44 1.15 1.37 296.46 2.09
2 2016-04-02 226.59 38.08 79.13 2.07 8.46 8.46 1.35 1.57 296.91 2.38
3 2016-04-03 0.00 39.57 71.96 0.06 8.69 8.67 0.28 0.40 -4.76 0.34
4 2016-04-04 225.01 41.57 79.91 2.29 8.67 8.65 1.05 1.18 297.09 2.00
5 2016-04-05 226.41 41.54 80.43 2.28 8.43 8.42 1.15 1.13 297.91 1.82
6 2016-04-06 225.65 41.08 79.89 2.30 8.60 8.59 1.06 1.38 297.55 2.24
m_nde_yvib m_nde_zvib permit
1 1.15 1.53 #N/A
2 1.13 1.63 #N/A
3 0.35 0.27 CW Pump house: Motor stand
4 0.96 1.33 #N/A
5 0.96 1.43 #N/A
6 0.96 1.40 #N/A
请参阅我在X轴上获取行号,我想更改为日期。
问题2:我正试图通过以下两个代码获得季节性情节,如Robjhyndman的书“预测:原则与实践”所述
autoplot(cw_ts[,2:5],facets = TRUE) + ylab("parameters")
和
ggseasonplot(cw_ts, year.labels=TRUE, year.labels.left=TRUE) +
ylab("") +
ggtitle("Seasonal plot: Pump parameter")
那么如何将我的时间序列归入上面的代码中呢?我收到了以下错误。
ggseasonplot(cw_ts, polar=TRUE) +
ylab("") +
ggtitle("Polar seasonal plot: Pump parameter")
和
ggseasonplot(cw_ts, year.labels=TRUE, year.labels.left=TRUE) +
+ ylab("") +
+ ggtitle("Seasonal plot: Pump parameter")
Error in ggseasonplot(cw_ts, year.labels = TRUE, year.labels.left = TRUE) :
Data are not seasonal
任何建议都会对我有所帮助。谢谢。