I applied linear regression(lm) model for my dataset. I got the expected results(as values) but the output holds the label name in all categories. Dataset seems: (Just a sample data for reference)
DARM Val hba_diff
Category1 23 2.5
Category2 54 3.8
Category3 56 5.2
Category4 89 6.1
Results after applying the below lm model :
lm(formula = hba_diff ~ DARM, data = DARM_data)
Output
Predictors Estimates CI p
(Intercept) 0.00 -0.10 – 0.10 0.957
DARM [Category1] 0.23 -0.30 – 0.75 0.398
DARM [Category2] 0.06 -0.25 – 0.37 0.719
DARM [Category3] 1.00 -2.18 – 4.17 0.538
DARM [Category4] -0.84 -2.67 – 1.00 0.372
I need to remove the 'DARM' in all rows of the output. Kindly suggest a code to remove the 'DARM' term in output set.
Expected output:
Predictors Estimates CI p
(Intercept) 0.00 -0.10 – 0.10 0.957
Category1 0.23 -0.30 – 0.75 0.398
Category2 0.06 -0.25 – 0.37 0.719
Category3 1.00 -2.18 – 4.17 0.538
Category4 -0.84 -2.67 – 1.00 0.372
Please include the full code in the future. Not sure how you get the table, I guess you are using tab_model
function in sjplot
, so the easiest way is to provide the names, for example:
library(sjPlot)
df = data.frame(hba_diff=runif(50),
DARM = sample(c("Category1","Category2","Category3"),50,replace=TRUE))
fit = lm(hba_diff ~ DARM, data = df)
tab_model(fit,pred.labels = c("Intercept","Category2","Category3"))
To plot, do something likewise with ggplot2 (the plot is coord flipped so it is x axis):
library(ggplot2)
plot_model(fit) + scale_x_discrete(labels=c("Category2","Category3"))