cellphone = read.csv("/Users/crystalchau/Desktop/UICT-CELL_IND.csv", nrows = 25, colClasses = c(NA,NA,"NULL"))
cellphone = cellphone[nrow(cellphone):1,]
cellphone.ts = ts(cellphone, frequency = 1)
ts.plot(cellphone.ts, ylab = "Mobile Cellular Telephone Subscriptions")
title(expression(Mobile~Celluar~Telephone~Subscriptions))
par(mfrow=c(1,2))
cellphone = read.csv("/Users/crystalchau/Desktop/UICT-CELL_IND.csv", nrows = 25, colClasses = c("NULL",NA,"NULL"))
cellphone = cellphone[nrow(cellphone):1,]
cellphone.ts = ts(cellphone, frequency = 1)
acf(cellphone.ts, lag.max = 10)
pacf(cellphone.ts, lag.max = 10)
cellphone.ts = ts(cellphone, frequency = 12)
decompose_cellphone = decompose(cellphone.ts, type = "multiplicative")
plot(decompose_cellphone)
library(MASS)
bcTransform = boxcox(cellphone ~ as.numeric(1:length(cellphone)), lambda = seq(-1, 1, length = 10))
plot(bcTransform, type = 'l', axes = FALSE)
它不允许我运行boxcox转换行,并给出错误消息:
boxcox.default(手机.ts ~ as.数字(1:长度(手机.ts))中出错,:响应变量必须为正数
我哪里做错了?
1条答案
按热度按时间sigwle7e1#
该错误表明数据中存在零值或无穷大值(在本例中为
cellphone
)。'* 在线性回归中,box-cox变换广泛用于变换目标变量,以便满足线性和正态性假设。但box-cox变换只能用于严格正的目标值。如果目标(因)变量中有负值,则不能使用box-cox和对数变换。*'(ref)
可以通过向
iris
数据集添加负值来重现该误差。您可以考虑尝试
Yeo-Johnson
转换。这类似于box-cox
,但允许负值。(see here)