我正在尝试编译正在运行但未编译的代码。
Error Message: Quitting from lines 40-42 (midterm.Rmd)
Error in data$Y_i1 : object of type 'closure' is not subsettable
Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> mean
Execution halted
代码
**c) Using the dataset “potential_outcomes.Rda" from Problem Set 1 (also loaded with this exam on bCourses), calculate the ATE and SE($hat{ATE}$) using R. For the latter, assume that half of the units will be assigned to the treatment group in the experiment. Is the ATE a parameter or an estimator? How about SE($hat{ATE}$)?**
```{r}
ATE <- mean(data$Y_i1) - mean(data$Y_i0)
ATE ## Average Treatment Effect
```
```{r}
N1 <- length(data$Y_i1)
N0 <- length(data$Y_i0)
N <- 23 # Half of observations
var1 <- var(data$Y_i1)
var0 <- var(data$Y_i0)
var1N <- var1/N
var0N <- var0/N
SEATE <- sqrt(var1N + var0N)
SEATE ## The Standard Error of the ATE
```
The ATE is a parameter because it describes the box. There is no estimation required. The SE of the ATE on the other hand, approximates the true standard error for the difference in means.
object of type 'closure' is not subsettable
表示您正在尝试为函数子集。如果不设置data
,它将引用utils
包中的data
函数。
is.function(data)
#> [1] TRUE
因此,如果我们尝试使用$
运算符,就会出现错误。
data$Species
#> Error in data$Species : object of type 'closure' is not subsettable
但是,如果data
被设置为数据帧,它就可以工作。
data <- iris
data$Species
#> [1] setosa setosa
#> [3] setosa setosa
#> ...