错误:如果 'na.rm' 为 FALSE,则不允许缺少值和 NaN [英] Error: missing values and NaN's not allowed if 'na.rm' is FALSE
问题描述
尝试#r4ds 的多个模型章节,最后遇到错误消息:
Trying out multiple models chapter of #r4ds and ran into an error message at the end:
错误:如果 'na.rm' 为 FALSE,则不允许缺少值和 NaN另外: 警告信息:在 ns(as.numeric(Month), 4) 中:强制引入的 NAs
Error: missing values and NaN's not allowed if 'na.rm' is FALSE In addition: Warning message: In ns(as.numeric(Month), 4) : NAs introduced by coercion
与
ADA_model<- function(ADA_mutiple_model){
lm(ADA ~ ns(as.numeric(Month), 4), data=ADA_mutiple_model)
}
ADA_mutiple_model <- ADA_mutiple_model %>%
mutate(model=map(data,ADA_model))
作为我使用的产生错误的代码.
as the code I used that creates the error.
看下面的mod3看看功能是什么样子
See mod3 below to see what the function looks like
推荐答案
你的问题与使用 lm
无关,但是在 splines::ns
里面的时候为自然三次样条生成 B 样条基础.很可能你的Month
是一个字符变量,你不能使用as.numeric
进行强制.
Your problem has nothing to do with the use of lm
, but inside splines::ns
when generating B-spline basis for natural cubic splines. Very likely your Month
is a character variable, and you can not use as.numeric
for coercing.
我刚刚检查了您的附图.图中的 x 轴验证了我的猜测.Month
需要使用 1:12,而不是JAN"、FEB"等
I just checked your attached figure. The x-axis in the plots verifies what I guessed. You need to use 1:12 for Month
, not "JAN", "FEB", etc.
这篇关于错误:如果 'na.rm' 为 FALSE,则不允许缺少值和 NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!