I have a dataframe like so:
set.seed(560)
df<-data.frame(lag= rep(1:40, each=228), psit= rep(rnorm(228, 20,
10)),var=rnorm(9120, 50, 10))
For each subset of lag I would like to run a linear regression where psit is predicted by var (e.g. lm(psit~var, df)). I would like to output the coefficient information for each value. Specifically, the beta Estimate and the Std. error into a datatframe. Then calculate the standardized effect size. The output should be:
output<-data.frame(lag= rep(1:40, each=1), estimate= rep(rnorm(40,
.5, 0.01)),std.error=rnorm(40,0.01, 0.01))
output$strd.effect <- output$estimate /output$std.error
I have tried:
models <-
df %>%
group_by(lag) %>%
do(model = lm(psit ~ var,data = .))
coeff<-
models %>%
ungroup()%>%
group_by(variable) %>%
do(glance(estimate=summary(model[i]$coeff[,1],
std.error=summary(model[i]$coeff[,2])
coeff<-
coeff %>%
group_by(variable) %>%
mutate(std.effect=estimate[[i]]/coeff[[i]]