[英]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.