lm.fit(x,y,offset = offset,singular.ok,...)0中的非NA错误,带有boxcox公式 [英] Error in lm.fit(x,y,offset = offset, singular.ok,...) 0 non-NA cases with boxcox formula

查看:1148
本文介绍了lm.fit(x,y,offset = offset,singular.ok,...)0中的非NA错误,带有boxcox公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to run a boxcox transformation with the following code:

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

但我一直收到此错误:

lm.fit(x,y,offset =偏移量,singular.ok = singular.ok,...)中的错误:0(非NA)情况调用:... eval-> eval-> boxcar- > boxcar.formula-> lm-> lm.fit执行停止

Error in lm.fit(x,y,offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases Calls: ... eval -> eval -> boxcar -> boxcar.formula -> lm -> lm.fit Execution halted

提前谢谢!

推荐答案

错误消息

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

lm.fit(x,y,offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases

当变量xy(或两者)仅具有NA时,

是由lm(y ~ x)命令生成的. 这是一个示例:

is generated by the lm(y ~ x) command when variables x or y (or both) have only NAs.
Here is an example:

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

在您的代码中,我建议使用以下命令测试(恰好在lm命令之前)您的变量之一是否具有所有NA:

In your code I suggest to test (just before your lm commands) if one of your variables has all NAs using:

all(is.na(x))
all(is.na(y))
all(is.na(y^trans))

在我的示例中:

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

这篇关于lm.fit(x,y,offset = offset,singular.ok,...)0中的非NA错误,带有boxcox公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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