[英]R Shiny - Display Linear, Polynomial and Cubic Regression Summaries in Seperate Tables
[英]How to do a linear Regression with summaries of a certain dataset in R?
我想在 R中创建一个线性回归,其中我使用数据集globalterrorismdb_0718dist
在 y 轴上显示每年(2000 年到 2017 年之间)的攻击次数,在 x 轴上显示年份。 我已经为每年创建了它自己的变量( a <- count(globalterrorism, iyear == 2000)
, ..., r <- count(globalterrorism, iyear == 2017)
)。 gf_point(country~iyear, data = globalterrorismdb_0718dist)
<- 那是我第一次尝试.. 我用library(mosaic)
做到了
试试这个:
library(dplyr)
globalterrorismdb_0718dist %>%
count(iyear) %>%
ggplot(.,aes(x = iyear, y = n))+geom_point()+
geom_smooth(method = "loess")+
labs(x = "Year", y = "Number of attacks")
更新:
globalterrorismdb_0718dist %>%
count(iyear) %>%
lm(data = . , iyear~n) %>% summary()
Call:
lm(formula = iyear ~ n, data = .)
Residuals:
Min 1Q Median 3Q Max
-15.637 -9.578 -4.462 11.605 17.101
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.984e+03 2.227e+00 890.832 < 2e-16 ***
n 2.449e-03 4.111e-04 5.958 3.61e-07 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 10.7 on 45 degrees of freedom
Multiple R-squared: 0.4409, Adjusted R-squared: 0.4285
F-statistic: 35.49 on 1 and 45 DF, p-value: 3.61e-07
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.