9/10/2023 0 Comments R studio regression output![]() ![]() Summary(model1) # term estimate std.error statistic p.value model1 <- with(dat2, lm(scale(math) ~ migrant + female, weights = studwgt)) For some other functions, an imputationlist has to be created but with a mids object (multiply imputed dataset), these can be analyzed directly. # hisei 1 1 1 1 1 0 1 1 1 class(dat2) # "mids"Īfter imputing the data, in order to analyze the data, instead of specifying the data frame in the data option, the data are analyzed using the with function. # idschool studwgt math migrant books hisei paredu female urban # idschool studwgt math migrant books hisei paredu female # 5 5 math migrant books hisei paredu summary(dat2) # Class: mids First step is to impute the data using mice. You can specify other types of imputation (instead of predictive mean matching or pmm and instead use logreg for variables such as female– or convert it to factor before imputing– however female had nothing missing anyway). You can perform all the necessary diagnostics after imputation. Generally, we would impute ~25 datasets (m = 25) but for demonstration purposes, we will just impute 5 datasets. In our dataset, 3006 observations out of 4073 (74%) have complete data. # "books" "hisei" "paredu" "female" "urban" #data.ma01$female <- factor(data.ma01$female, labels = c('m', 'f'))ĭat <- data.ma01 #remove student id and mathĭim(dat) #number of observations and variables # 4073 9 length(table(dat$idschool)) #79 schools # 79 md.pattern(dat, plot = F) #view missing data pattern # idschool studwgt female urban math migrant books paredu hisei ![]() # 6 1 names(data.ma01) # "idstud" "idschool" "studwgt" "math" "read" "migrant" Head(data.ma01) # idstud idschool studwgt math read migrant books hisei paredu female ![]() This still is a lot of steps.įor an example, I will use the data.ma01 dataset in the miceadds package. A function then saves the results into a data frame, which after some processing, is read in texreg to display/save the output. The cluster robust standard errors were computed using the sandwich package. I settled on using the mitools package (to combine the imputation results just using the lm function). This note does not show how to perform multilevel imputation– just single-level imputation and getting the output ‘publication ready’. Display multiple models side by side (i.e., show standard errors below regression coefficients).Include weights (as is the case with nationally representative datasets).Account for clustering (working with nested data).My preference for imputation in R is to use the mice package together with the miceadds package. However, I have not been able to figure out how to get the output of multiply imputed results to display properly (if someone knows of a way, please email me or leave a comment). I have used packages such as stargazer and huxtable for getting nice (or as it has been called, pretty) regression tables. More challenging even (at least for me), is getting the results to display a certain way that can be used in publications (i.e., showing regressions in a hierarchical fashion or multiple models side by side) that can be exported to MS Word. However, analyzing imputed models with certain options (i.e., with clustering, with weights) is a bit more challenging. There are several guides on using multiple imputation in R. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |