Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
lm.fit(x,y,offset=offset,singular.ok,…)中的错误0使用boxcox公式的非NA情况_R_Eval_Lm - Fatal编程技术网

lm.fit(x,y,offset=offset,singular.ok,…)中的错误0使用boxcox公式的非NA情况

lm.fit(x,y,offset=offset,singular.ok,…)中的错误0使用boxcox公式的非NA情况,r,eval,lm,R,Eval,Lm,我正在尝试使用以下代码运行boxcox转换: urban1 <- subset(ski,urban <= 4,na.rm=TRUE) ski$gender <- as.numeric((as.character(ski$gender)),na.rm=TRUE) urban1 <- as.numeric((as.character(urban1))) x <- (ski$gender*urban1) y <- ski$EPSI. bc <- boxcox(

我正在尝试使用以下代码运行boxcox转换:

urban1 <- subset(ski,urban <= 4,na.rm=TRUE)
ski$gender <- as.numeric((as.character(ski$gender)),na.rm=TRUE)
urban1 <- as.numeric((as.character(urban1)))
x <- (ski$gender*urban1)
y <- ski$EPSI.
bc <- boxcox(y ~ x) 
(trans <- bc$x[which.max(bc$y)]) 
model3 <- lm(y ~ x) 
model3new <- lm(y^trans ~ x)
ski$EPSI. <- ski$EPSI. + 1
urban1错误消息

lm.fit(x,y,offset=offset,singular.ok=singular.ok,…):0 (非NA)案件

当变量
x
y
(或两者)只有NAs时,由
lm(y~x)
命令生成。
以下是一个例子:

n <- 10
x <- rnorm(n,1)
y <- rep(NA,n)
lm(y ~ x)

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
  0 (non-NA) cases
在我的例子中:

all(is.na(y))
[1] TRUE

错误可能由数据中的NA触发或不良转换触发

#From the mtcars dataset
mpg.reg3 <- lm(mpg ~ cylinders + displacement + horsepower + weight + acceleration + year + origin, data=Auto, na.action=na.exclude)
来自mtcars数据集的
#

mpg.reg3你确定第二排吗?如果代码中缺少值,则用不正确的值替换数据。我可以建议你在宇宙中转换你的代码吗?我在删除所有完全不可用的列后得到这个错误。出现此错误可能还有其他原因吗?@TomKisters拜托,汤姆,你能分享更多关于你的问题的信息吗?
#From the mtcars dataset
mpg.reg3 <- lm(mpg ~ cylinders + displacement + horsepower + weight + acceleration + year + origin, data=Auto, na.action=na.exclude)