我的老师给了我一个回归的结果,练习是对导致回归的数据集进行逆向工程.然后我们需要对它做一个回归,找到完全相同的结果.
我设法使系数为-19.93,但我没有得到相同的SE.我不知道怎么做.我不知道我是否应该使用一些公式链接的SE估计和标准误差的回归(我有一些,但我真的不知道如何实现他们在R).提前感谢您的帮助!
我的R输出:
## Given values
n <- 1592
se_β1 <- 1.47
β1hat <- -19.93
## Create a dummy variable for control vs treatment condition
set.seed(123)
Low_anchor <- rbinom(n,1,0.5)
## Formula of standard error of beta 1 (assuming homoskedasticity)
calculate_standard_error <- function(u, Low_anchor) {
sqrt((1/(n - 2))*sum(u^2)/(n*sd(Low_anchor)^2))
}
## Define initial values of u
u <- rnorm(n)
## Tolerance for convergence
tolerance <- 0.1
## Iteratively adjust u until the standard error matches the target
while (abs(calculate_standard_error(u, Low_anchor) - se_β1) > tolerance) {
## Generate new set of values for u from a normal distribution
u <- rnorm(n)
}
print(u)
## regression
Yc <- -19.93*Low_anchor + u
model1 <- lm(Yc ~ Low_anchor - 1)
## Print the summary of the model
summary(model1)