Use latex math in coef names huxtable - r

I am using quarto to generate an HTML report.
I have a regression table that I created using huxtable library.
I wanted to know how can I use math notation for the name of the coefficients.
here is the code for the table:
huxtable::huxreg(
cox1,cox2,cox3,cox4,cox5,
omit_coefs=factors,
tidy_args = list(exponentiate = TRUE),
coefs = c(
"$Ln(capacity)$" = "log(plan_cap)",
"Government Owned" = "Owner_typeGovernment",
"Noord-Holland" = "provinceN",
"Zuid-Holland" = "provinceZ")
)
However the results is:
What should I do in order to make the Ln(capacity) appear as math equation?
I need to know this since the rest of the tables I am going to produce include equations.
Thank you.

Related

Exporting Probit regression results to LATEX with additional statistics (z values, LR chi^2, and Pseduo-R^2)?

I'm new to all of this so will very much appreciate any help at all!
I have a "glm" model results that I want to export to Latex, in the form of a table.
I've tried to use the "texreg" package, but couldn't find a way to add to the table some statistics like:
z-value, LR chi^2, and Pseduo-R^2.
Does anyone know an easy way of doing it?
this is the code that I currently run:
texreg(
l = list(extract_probit_model_Emp, extract_probit_model_lfp),
file = "results/probit_test",
stars = c(0.01, 0.05, 0.1),
custom.header = list("probit" = 1:2),
custom.model.names = c("Employment", "LFP"),
omit.coef = "control",
center = TRUE,
caption = "Probit Test on Employment and LFP")
I wonder if there is any way of doind it with the texreg package, or is there another one that is easy to handle?
Thanks in advance!
PS:
I have the same problem with exporting OLS reg results. Guess this is roughly the same?

Predict Multiple Output using Apriori Algorithm in R

Currently I am working on item-item based recommendation system using r. The package which I have used is arules. I have done my basic models but I want to modify my model with following criteria:
In the apriori algo. We will receive only one output, not multiple output. I want multiple output value in the rhs side. For example:
lhs rhs
{GH DAILY MOONG DAL PREMIUM 1kg,
MDH POW SPICE DEGHI CHILLI 100g,PREM 1kg} => {DAILY OTH PULSE CHANA DAL...
Rice}
My recommendation system totally based on item-item. Is there any other algorithm or package exist in r which will give me better business output?
How to calculate confidence and support value? For my case I am using default values.
My code is given below:
#Create Sparse Matrix
dataset = read.transactions('/Users/Nikita/Downloads/Reco_System/market_basket_before_model.csv', sep = ',', rm.duplicates = TRUE)
summary(dataset)
itemFrequencyPlot(dataset, topN = 20, type = 'absolute')
#1st cut
# Training Apriori on the dataset
rules = apriori(data = dataset, parameter = list(support = 0.001, confidence = 0.8))
# Visualising the results
inspect(sort(rules, by = 'lift')[1:30])
Thanks in advance.
Most implementations of association rule mining algorithms restrict the RHS of the rules to a single item to avoid further combinatorial explosion.

stargazer: create table with regression output without model objects

I have computed several models, using both glm() and rxGlm() (the second one is from Microsoft R). Unfortunately, rxGlm() does not store all information required by stargazer. So when trying to create the summary table (even after adjusting the RxGlm data via as.glm() ), I get the following error message:
Error in qr.lm(object) : lm object does not have a proper 'qr' component.
Rank zero or should not have used lm(.., qr=FALSE).
I am already reading out separetly the t-statistics and p-values and feed them back to stargazer separately. However, stargazer still requires the model output objects to be stored in the workspace and otherwise sends an error message.
This is how I extract the statistics from the model output:
obj1.t <- summary(obj1)$coef[ , "z value"]
obj1.p <- summary(obj1)$coef[ , "Pr(>|z|)"]
This is a simplified form of my stargazer command, where se = and p = are used to feed back the previously extracted statistics.
stargazer(list(obj1, obj2),
type = "html", table.layout = "cd=!t-s-!a=!n", star.cutoffs=c(0.05,0.01,0.001), no.space = TRUE,
omit = c(1989:2015), font.size = "normalsize",
out = "Test.html",
df= FALSE,
column.labels = c("(1)", "(2)"),
add.lines = list(c("fixed effects", "No", "Yes")),
dep.var.labels = c("Dummy"),
title = "GLM PROBIT MODEL",
se= list(obj1.t, obj2.t),
p = list(obj1.p, obj2.p),
notes = "t statistics shown in parentheses")
Now my question: is there a way to create regression output tables with stargazer without having to provide the model output objects? So basically store all the required data in separate vectors and then feed them back to stargazer? RxGlm summaries provide all the information that is necessary to fill the regression results table manually. However, I am looking for a way to do it automatically.

Export Linear Mixed Effects Model Outputs in csv using Julia Language

I am new to Julia programming language, however, I am fitting a Linear Mixed Effects Model and I find it difficult to save the fixed and random effects estimates in .csv files.
An example code can be found:
using MixedModels
#time modelOutput = fit(lmm(Y~ A + B + (0 + A | group), data))
There is available reference about how to obtain the fixed (fixef(modelOutput)) and random (ranef(modelOutput)) effects however using a DataFrame I am facing errors.
Any advice is appreciated.
Okay, I actually took the time to do this for you. A CoefTable is a type defined in statmodels here. Given this information, we can extract the relevant information from the CoefTable instance as follows:
df = DataFrame(variable = ct.rownms,
Estimate = ct.mat[:,1],
StdError = ct.mat[:,2],
z_val = ct.mat[:,3])
This will give an nvar-by-4 DataFrame which you can then write to csv as described earlier using writetable("output.csv",df)
I had a number of problems getting the accepted answer to work; Julia has evolved a lot since then. I rewrote it based primarily on code from the jglmm R package, with some adaptation/cobbling-together from other sources ...
"""
outfun(m, outfn="output.csv")
output the coefficient table of a fitted model to a file
"""
outfun = function(m, outfn="output.csv")
ct = coeftable(m)
coef_df = DataFrame(ct.cols);
rename!(coef_df, ct.colnms, makeunique = true)
coef_df[!, :term] = ct.rownms;
CSV.write(outfn, coef_df);
end

Creating a latex table from coeftest object in R

I have coeftest class object that I coded for some purposes that lm class cannot achieve, but I need to export the object in the way as xtable(lm) does. Any idea would be appreciated!
I think this could help you out:
library(AER) # I think coeftest() belongs to this package.
library(Hmisc)
latex(coeftest(model), digits=5)
Where model is the linear model estimated by lm(). latex() is a function from Hmisc package which is more general than xtable.
If this is not what you are looking for, then provide some data and the expected result so that we can figure it out.
library(stargazer)
stargazer(model, se=coeftest(model), report=vcs)
model is the linear model. stargazer is, at least in my experience, more general than latex() from Hmisc.
Alternatively, if you want to use xtable, could write down a small function:
library(lmtest)
library(xtable)
xtable.coeftest <- function (x, caption = NULL, label = NULL, align = NULL, digits = NULL,
display = NULL, ...)
{
class(x) <- "matrix"
li<-list(coef=x)
return(xtable:::xtable.summary.lm(li, caption = caption, label = label,
align = align, digits = digits, display = display))
}
example(coeftest)
xtable(coeftest(fm))
It is admittedly not the most elegant (there are two issues, one that it is difficult to convert a coeftest object, second that xtable.summary.lm uses x$coef instead of coef(x)) but it works!

Resources