-3

如果有两组数据“x”和“y”随“时间”变化,比较“x”和“y”随时间的增加率是否相同。

我的问题是它如何开始这个问题,我需要执行哪些步骤?这个问题在过去一周一直困扰着我,我不知道如何解决它。感谢您的帮助。我将在 R 中为这个项目工作

我所做的是plot(x~time)plot(y~time)X 和 Y 都是线性的,它们从图表的左下角到右上角。由此我如何告诉 R 找到从 X 到 y 的增长率?

4

1 回答 1

3

Here's some ideas to get started, though I would recommend taking a look at the link Ricardo provided in the comments if you want to get started with time series analysis in R. If this is the first thing you are doing with R, you may also benefit from some general reading at a site like: http://www.statmethods.net

I read your data in and saved it to a data.frame named test using

test <- read.table(file="insert.your.file.here",header=TRUE)

You can then plot the trends over time against one another, using plot and lines or the matplot function which can plot multiple columns at once.

matplot(test["time"],test[c("x","y")],type="l")

You should end up with something like this:

enter image description here

Just by eye-balling it, you can see that y has increased more than x over the period.

If you want to plot the linear trend, you can try using the lm function to get the relationship between time and the values for each of x and y. Like so:

lm(y ~ time, data=test), col="red")
lm(x ~ time, data=test), col="black") 

This will give you the gradient and intercept for the trend. The gradient is the average increase over time. You can add these lines to your plot like so:

abline(lm(y ~ time, data=test), col="red"))
abline(lm(x ~ time, data=test), col="black"))

enter image description here

This is a pretty naive analysis though, and you should consider the possibility of seasonal trends in your data or other influences. I suggest you read this: http://a-little-book-of-r-for-time-series.readthedocs.org/en/latest/src/timeseries.html

于 2013-04-21T01:49:05.877 回答