简体   繁体   English

lm() 和 geom_smooth() 的参数是否相同?

[英]Same parameters from lm() and geom_smooth()?

I am wondering if the function lm() from the stats package is the same as the one used in geom_smoot(method = lm) in ggplot2.我想知道 package 中的 function lm()是否与 Z64B86077DA413996627142D8Z 中的geom_smoot(method = lm)中使用的相同。 If so, are the parameters calculated by them the same everytime for the same data.如果是这样,他们每次为相同的数据计算的参数是否相同。

So would...那么会...

lm(response ~ variable, data = dat)

calculate the same parameters as...计算与...相同的参数

ggplot(dat, aes(variable, response)) + 
  geom_smooth(method = lm)

Yes, geom_smooth uses stats::lm .是的, geom_smooth使用stats::lm The ?geom_smooth documentation mentions stats::lm specifically, and in the See Also section has a link to the lm documentation. ?geom_smooth文档特别提到了stats::lm ,并且在See Also部分有一个指向lm文档的链接。

The linear model (coded in lm ) is fully deterministic.线性 model(编码为lm )是完全确定的。 It returns the same results as long as you call it on the same input.只要您在相同的输入上调用它,它就会返回相同的结果。 geom_smooth uses stats::lm behind the scene, so the results should be the same. geom_smooth在后台使用stats::lm ,所以结果应该是一样的。 Note that it is not possible to extract model parameters from a ggplot plot ( link ).请注意,无法从ggplot plot( 链接)中提取 model 参数。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM