简体   繁体   English

使用log时的线性模型“ lm”函数错误

[英]linear model “lm” function error when log is used

I get the error below when trying to draw the lmline. 尝试绘制lmline时出现以下错误。 This same error occurs weather the plot is base plot, lattice or ggplot. 如果图是基本图,点阵图或ggplot,则会发生相同的错误。 There isn't an NA or NAN in the column - it was scrubbed of that. 列中没有NA或NAN-已将其清除。 But the log for Emission may have caused "inf" in some of the data. 但是,排放日志可能会导致某些数据出现“ inf”。 I suspect the issue to be with the lm function having problem with "inf" for obvious reasons. 由于明显的原因,我怀疑问题出在lm函数存在“ inf”问题。 Is there a way to get around this? 有办法解决这个问题吗?

model <- lm(log(Emissions) ~ year, outpoint) Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/Inf in 'y' 模型< -lm (log(排放)〜年,出站) lm.fit(x,y,offset = offset,singular.ok = singular.ok,...)中的错误:NA / NaN / Inf in'y'

Note: if log isn't used - the lmline draws. 注意:如果不使用log,则会绘制lmline。 I am doing this because the data is mushed and can be better presented with a log. 我这样做是因为数据被屏蔽了,可以用日志更好地呈现。

xyplot(log(y) ~ x | f, type = c("p","r"), panel = function(x, y,...) {
        panel.xyplot(x, y, ...)  
        panel.lmline(x, y, ...)
}, xlab = "x label", ylab = "y label")

Get the following error in the plot. 在图中获得以下错误。

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
  NA/NaN/Inf in 'y'

Yes probably your y variable has a zero in it, or a negative number. 是的,可能您的y变量中包含零或负数。 If it's only a zero, you could add a small amount to every y, such as half the minimum non-zero number. 如果仅为零,则可以为每个y添加少量,例如最小非零数字的一半。 If it's negative values, a log transform might not be appropriate, but if you really must, you could add a large enough number to every y that none are negative. 如果它是负值,则对数转换可能不合适,但是如果确实需要,则可以为每个y添加足够大的数字,而没有一个都是负数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 线性 model function lm() 错误:NA/NaN/Inf in foreign function call (arg 1) - Linear model function lm() error: NA/NaN/Inf in foreign function call (arg 1) lm()线性模型-属性 - lm() linear model - attributes 一个线性数组的R线性模型(lm)预测函数 - R linear model (lm) predict function with one single array 是否有 function 用于替换(或完全删除)解释线性 model(lm)中的变量? - Is there a function for substituting (or removing at all) explaining variables in a linear model (lm)? 使用加权 function (minpack.lm::wfct()) 进行非线性回归时,仅 try() 或 trycatch() 会出错 - Error only with try() or trycatch() when using Weighting function (minpack.lm::wfct()) for non linear regression 匹配线性 model 的 lm 和 optim 系数估计与乘法误差 - Matching lm and optim coefficient estimates for linear model with multiplicative error 当因变量是因子/分类变量时的线性模型 (lm)? - Linear model (lm) when dependent variable is a factor/categorical variable? 用R绘制线性模型(lm)时产生的NaN - NaNs produced when plotting a linear model (lm) with R 从线性回归函数lm中获取误差值 - get the error value from linear regression function lm R:将线性模型与`lm`拟合时的对比误差 - R: Error in contrasts when fitting linear models with `lm`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM