作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从 qplot 中提取 500 个变量的截距和斜率。我正在使用的代码:
qplot(gd, nd, data = test, colour = factor(ENT)) +
geom_smooth(method = "lm", se = FALSE)
有人可以帮我提取每条回归线(500 条线/变量)的截距和斜率,如附图所示。
最佳答案
ggplot
将绘制图形,但您可以从 lm()
对象中提取系数(截距和斜率)。实现后者的一种方法是使用 dplyr 的 group_by()
和 do()
函数。参见?做
我在这里使用 mtcars 数据框。
library(ggplot2)
library(dplyr)
ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) +
geom_point() +
geom_smooth(method = "lm", se = FALSE)
mtcars %>%
group_by(cyl) %>%
do({
mod = lm(disp ~ mpg, data = .)
data.frame(Intercept = coef(mod)[1],
Slope = coef(mod)[2])
})
Source: local data frame [3 x 3]
Groups: cyl
cyl Intercept Slope
1 4 233.0674 -4.797961
2 6 125.1225 2.947487
3 8 560.8703 -13.759624
关于r - 如何从大量变量的图中提取截距和斜率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30144785/
我是一名优秀的程序员,十分优秀!