使用动物园对象进行线性回归时出现错误... $(。 - zoo)中的错误(`* tmp *`) [英] Error when doing linear regression using zoo objects ... Error in `$<-.zoo`(`*tmp*`

查看:102
本文介绍了使用动物园对象进行线性回归时出现错误... $(。 - zoo)中的错误(`* tmp *`)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对R很新,慢慢熟悉。我的问题是指以下代码段。



我正在创建一个带有以下标题的动物园对象,然后按日期过滤。在过滤的日期我减去两列(来自埃琳娜的汤姆)。一切正常,直到这里。



代码如下:


b< read.zoo(b1,header = TRUE,index.column = 1,format =%d /%m /%Y)



startDate =2013/11 / 02
endDate =2013/12/20



日期< - seq(as.Date(startDate),as.Date(endDate) ,by = 1)



TE = b [日期] $ Tom - b [日期] $ Elena


然而,我正在对Elena的减法(见TE)上的结果进行回归。但是,我每次尝试和回归时都会收到一条错误消息。


TE $ model< - lm(TE〜b [ $ Elena)


$< - 。zoo * tmp * ,model,value = list(系数= c(-0.0597128230859905,
不适用于单变量动物园系列



我已经尝试创建一个数据框,然后进行回归,但没有任何帮助,谢谢。

解决方案

您不能将回归结果(类 lm 的列表)添加到类 zoo



我建议将模型保存在单独的对象中,例如

  fit<  -  lm(TE〜b [dates] $ Elena)


I am new to R and slowly getting acquainted. My question refers to the following piece of code.

I am creating a zoo object with the following headers and then filtering by date. On the filtered dates I am subtracting two columns (Tom from Elena). Everything works fine until here.

Code below:

b <- read.zoo(b1, header = TRUE, index.column = 1, format = "%d/%m/%Y")

startDate = "2013/11/02" endDate = "2013/12/20"

dates <- seq(as.Date(startDate), as.Date(endDate), by=1)

TE = b[dates]$Tom - b[dates]$Elena

However I am then regressing the results from my subtraction (see above TE) on Elena. However i get an error message every time i try and to this regression

TE$model <- lm(TE ~ b[dates]$Elena)

Error in $<-.zoo(*tmp*, "model", value = list(coefficients = c(-0.0597128230859905, : not possible for univariate zoo series

I have tried creating a data frame and then doing the regression but with no avail. Any help would be appreciated. Thanks.

解决方案

You can not add the outcome of a regression (a list of class lm) to a time series of class zoo.

I recommend saving the model in a separate object, e.g.,

fit <- lm(TE ~ b[dates]$Elena)

这篇关于使用动物园对象进行线性回归时出现错误... $(。 - zoo)中的错误(`* tmp *`)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆