我试图让Newey-West标准错误与包中的pmg()(Mean Groups/Fama-MacBeth估算器)输出一起使用plm.
按照这里的例子:
require(foreign)
require(plm)
require(lmtest)
test <- read.dta("http://www.kellogg.northwestern.edu/faculty/petersen/htm/papers/se/test_data.dta")
fpmg <- pmg(y~x, test, index=c("firmid", "year")) # Time index in second position, unlike the example
Run Code Online (Sandbox Code Playgroud)
我可以coeftest直接使用,以获得Fama-MacBeth标准错误:
# Regular “Fama-MacBeth” standard errors
coeftest(fpmg)
# t test of coefficients:
#
# Estimate Std. Error t value Pr(>|t|)
# (Intercept) 0.032470 0.071671 0.453 0.6505
# x 0.969212 0.034782 27.866 <2e-16 ***
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ …Run Code Online (Sandbox Code Playgroud) 我有两个情节.一条线条平滑:
library(splines)
library(ggplot2)
ggplot(mtcars, aes(hp, qsec)) + stat_smooth(aes(group = cyl,
colour = factor(cyl)),
method = "glm",
formula = y ~ ns(x, 1),
level = 1e-9,
size = I(1)) +
theme(panel.background=element_rect(fill="transparent",colour=NA),
plot.background=element_rect(fill="transparent",colour=NA),
legend.key = element_rect(fill = "transparent", colour = "transparent"))
Run Code Online (Sandbox Code Playgroud)
一个没有:
ggplot(mtcars, aes(hp, qsec)) +
geom_point(aes(group = cyl, colour = factor(cyl))) +
theme(panel.background=element_rect(fill="transparent",colour=NA),
plot.background=element_rect(fill="transparent",colour=NA),
legend.key = element_rect(fill = "transparent", colour = "transparent"))
Run Code Online (Sandbox Code Playgroud)
如何在第一个图中获得白色或透明的图例背景?为什么相同的主题命令在第二个绘图中完成工作?
有没有理由我无法直接从zip文件中读取RDS文件,而不必先将其解压缩到磁盘上的临时文件?
假设这是zip文件:
saveRDS(cars, "cars.rds")
saveRDS(iris, "iris.rds")
write.csv(iris, "iris.csv")
zip("datasets.zip", c("cars.rds", "iris.rds", "iris.csv"))
file.remove("cars.rds", "iris.rds", "iris.csv")
Run Code Online (Sandbox Code Playgroud)
对于csv文件,我可以直接读取它:
iris2 <- read.csv(unz("datasets.zip", "iris.csv"))
Run Code Online (Sandbox Code Playgroud)
但是,我不明白为什么我不能unz()直接使用readRDS():
iris3 <- readRDS(unz("datasets.zip", "iris.rds"))
Run Code Online (Sandbox Code Playgroud)
这给了我错误:
Error: unknown input format
Run Code Online (Sandbox Code Playgroud)
我也想知道为什么会这样.我知道我可以做以下事情,就像这个问题一样:
path <- unzip("datasets.zip", "iris.rds")
iris4 <- readRDS(path)
file.remove(path)
Run Code Online (Sandbox Code Playgroud)
但这似乎并不高效,而且我需要经常为大量文件执行此操作,因此I/O效率低下很重要.是否有任何解决方法来读取rds文件而不将其提取到磁盘?