feols我使用model (包)运行了一堆模型fixest,但是我在使用stargazer. 关于我如何做到这一点有什么建议吗?
看起来我确实可以使用etable函数,但我想使用函数stargazer,因为我想在表格中添加几行注释并按照我想要的方式格式化表格(例如table.layout在 中使用函数stargazer)。
我有两组点作为sf对象存储在 R 中。点对象 x 包含 204,467 个点,点 y 包含 5,297 个点。
理论上,我想计算从 x 中的所有点到 y 中的所有点的距离。我知道这会创建一个庞大的矩阵,但在我的 i7 桌面上使用该st_distance(x, y, by_element=FALSE)包sf大约需要 40 分钟。
我想要做的是计算从 x 中的所有点到 y 中的所有点的距离,然后我想将其转换为 a data.frame,其中包含相应 x 和 y 对点的所有变量。这是因为我希望使用 进行聚合方面的灵活性dplyr,例如,我想找到 y 中距离 x 10、50、100 公里以内的点的数量,以及其中x$year < y$year。
我成功创建了距离矩阵,其中包含大约 1,083,061,699 个单元格。我知道这是一种非常低效的方法,但它在聚合方面提供了灵活性。欢迎其他建议。
下面是创建两个 sf 点对象并测量它们之间距离的代码。接下来,我想将其转换为包含 x 和 y 中所有变量的 data.frame,但这是我无法继续的地方。
如果我建议的工作流程不可行,有人可以提供替代解决方案来测量到预定义半径内所有点的距离,并使用 x 和 y 中的所有变量创建结果的 data.frame 吗?
# Create two sf point objects
set.seed(123)
library(sf)
pts1 <- …Run Code Online (Sandbox Code Playgroud) 我想尝试将弹性对象导出到 Excel 电子表格,但我找不到任何解决方案。根据此文档(https://davidgohel.github.io/flextable/reference/index.html),该包允许用户将可格式化对象导出为 pdf、文档和 ppt。
一种解决方法是将其保存为其中一种格式,然后将其保存到 Excel 电子表格中,但我正在寻找一种不太黑客且可扩展到许多表的解决方案。
我已经对数据进行了分组,我想测试几个基本的推理统计数据。
library(tidyverse)
df <- data.frame(x=runif(50, min = 0, max = 25),y=runif(50, min = 10, max = 25), group=rep(0:1,25))
df %>%
group_by(group) %>%
summarize(cor(x,y))
Run Code Online (Sandbox Code Playgroud)
在这里我可以很容易地得到相关性,但我还需要检查它的统计显着性。不幸的是,像cor.test这样的选项在dyplr. 有简单的解决方法吗?
我想绘制 xy 变量的点线图并突出显示两个分组。我知道一些区分因素的选项,例如fill、shape或。对于第一组,我想要有颜色,对于第二组形状(可能有也可能没有相同的颜色)。我需要一个图例来区分这两个分组(我已经有了)。也许我必须将 aes 放入 geom_line 或 geom_point 中,但我不确定。因为后来我想调整形状的大小(以更好地区分这些形状)。colgroup
这是我的代码:
library(ggplot2)
data <- data.frame(id1=c(1,1,1,2,2,2,3,3,3,4,4,4),
id2=seq(1:3), year=seq(from=2007, to=2018, by=1),
variable=rep(c(5:8), each=3))
# two groups by color and shape, but it drops the line (seperate legends, thats nice)
ggplot(data, aes(x=year, y=variable, col=factor(id1), shape=factor(id2))) +
geom_line() + geom_point()
Run Code Online (Sandbox Code Playgroud)
我有一个散点图和基础回归模型。我想在另一个数据点上给出一个很好的例子(假设不包含在估计样本中),即它的实际值与预测值。除了标签之外,我已经准备好了一切(考虑geom_text或geom_label,到目前为止没有任何效果):
data(mtcars)
model <- lm(mpg ~ wt, data=mtcars)
mycar <- data.frame(wt=c(2.5))
predict(model, mycar)
model <- lm(Coupon ~ Total, data=df)
mycar <- data.frame(Total=c(79037022, 83100656, 104299800))
predict(model, new.df)
ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point() +
geom_smooth(method="lm", se=FALSE) +
geom_point(aes(x=2.5,y=23.92395), # red is the prediction for my car
color='red',
size=3, show.legend = TRUE) +
geom_point(aes(x=2.5,y=28), # green is the actual mpg of my car
color='green',
size=3)
Run Code Online (Sandbox Code Playgroud)
我对具体实施很灵活:
我正在寻找易于实施且具有视觉吸引力的东西。谢谢
我想使用dplyrfor 循环来总结每个自变量(列)和目标变量。这是我的主要数据框:
Contract_ID Asurion Variable_1 Variable_2 Variable_3
1 年 acf
2 年平均
3N BCG
4 N adf
5 年 bcf
6 Y adf
分组后我得到
a1 <- a %>%
group_by(Asurion,BhvrBnk_Donates_to_Env_Causes) %>%
summarise(counT=n_distinct(CONTRACT_ID)) %>%
mutate(perc=paste0(round(counT/sum(counT)*100,2),"%"))
Asurion Variable_1 CounT perc
Y a 3 75%
Y b 1 25%
N a 1 50%
N b 1 50%
Run Code Online (Sandbox Code Playgroud)
我希望对数据框中存在的每个变量进行汇总,并且我想使用 for 循环来完成此操作。我怎样才能达到我想要的结果
这是我尝试使用的,但似乎不起作用。这是一个学校项目,我需要为此使用 for 循环。请在这里帮助我
categorical <- colnames(a)###where categroical is the names of all columns in a
###I would like to have a for …Run Code Online (Sandbox Code Playgroud) 我运行一系列回归模型(几乎每天)。我通过用日期(年-月-日格式)标记导出的回归结果来手动跟踪我的结果。这如何在 Stata 中自动化(使用outreg2Word)?这是一个最小的工作示例:
* load data
use http://www.stata-press.com/data/r13/nlswork
* regression
reg ln_wage c.age c.wks_u i.race i.union
* export results in word document in a file appended by "today"/date
outreg2 using "C:\PATH\Results\model_1_2020_08_21.doc", word
Run Code Online (Sandbox Code Playgroud) 我有德国邮政编码的多边形形状数据。对于每个邮政编码,我喜欢计算从质心到其边界的最大距离,并在地图上对其中一些邮政编码进行说明。sf我找到了一篇通过包 andst_cast()计算这个最大值的帖子st_distance()。我的数据为 sf 数据框。
library(sf)
library(tidyverse)
# Get German postcode shape polygons
URL <- "https://downloads.suche-postleitzahl.org/v2/public/plz-5stellig.shp.zip"
# use GDAL virtual file systems to load zipped shapefile from remote url
GER_postcode <- paste0("/vsizip//vsicurl/", URL) %>% read_sf()
# convert numeric
GER_postcode$plz <- as.numeric(GER_postcode$plz)
# filter a specific postcode
test <- GER_postcode %>% filter(plz == 15232)
# compute distances
distances <- test %>%
st_cast("POINT") %>%
st_distance(st_centroid(test))
# maximum dist:
max_dist <- max(distances)
max_dist
ggplot() + …Run Code Online (Sandbox Code Playgroud)