regression - R Shiny: Rendering summary.ivreg output -
i'm trying render instrumental variable regression summary in r shiny
here code:
iv=ivreg(lwage~educ+exper|nearc4+exper) summary(iv)
when use rendertable following error: no applicable method 'xtable' applied object of class "summary.ivreg"
any suggestions how go around issue?
this website, if want see i'm doing exactly: https://ieconometrics.shinyapps.io/test/
rendertable
expect object xtable methods exist, can see methods avaible : methods(xtable)
, , doen't work summary.ivreg
, can build method or obtain result these code below :
library(shiny) library(aer) library(reporters) # define server server <- function(input, output) { output$raw_summary <- renderprint({ fm <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff + i(tax/cpi), data = cigarettessw, subset = year == "1995") print(summary(fm)) }) output$summary_table <- renderui({ fm <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff + i(tax/cpi), data = cigarettessw, subset = year == "1995") data = summary(fm)$coefficients data = as.data.frame(data) # signif codes signif.codes = cut( data[,4] , breaks = c( -inf, 0.001, 0.01, 0.05, inf) , labels= c("***", "**", "*", "" ) ) # format data values data[, 1] = formatc( data[, 1], digits=3, format = "f") data[, 2] = formatc( data[, 2], digits=3, format = "f") data[, 3] = formatc( data[, 3], digits=3, format = "f") data[, 4] = ifelse( data[, 4] < 0.001, "< 0.001", formatc( data[, 4], digits=5, format = "f")) # add signif codes data data$signif = signif.codes # create empty flextable coef_ft = flextable( data = data, add.rownames=true , body.par.props = parright(), header.text.props = textbold() , header.columns = t ) # center first column , set text bold italic coef_ft[,1] = parcenter() coef_ft[,1] = textbolditalic() # define borders coef_ft = setflextableborders( coef_ft , inner.vertical = bordernone(), inner.horizontal = borderdotted() , outer.vertical = bordernone(), outer.horizontal = bordersolid() ) return(html(as.html(coef_ft))) }) } # define ui ui <- shinyui(fluidpage( p("raw summary"), verbatimtextoutput(outputid = "raw_summary"), p("pretty model summary table :"), uioutput(outputid = "summary_table") )) # call app shinyapp(ui = ui, server = server)
Comments
Post a Comment