Any of those help The basic trick for drawing confidence bars in R, if you don't want to use any packages (plotrix::plotCI, or gplot::barplot2), is to use arrows(...,angle=90) (or use segments() if you don't want "serifs" on your error bars) code :
M < lm(mpg ~ . , data = mtcars)
c0 < coef(M)
cc < confint(M, level = 0.9)
b < drop(barplot(c0,ylim=range(c(cc)))) ## b stores vector of x positions
arrows(b,c0,b,cc[,1],angle=90,length=0.05) ## lower bars
arrows(b,c0,b,cc[,2],angle=90,length=0.05) ## upper bars
Share :

Get p values or confidence intervals for nonnegative least square (nnls) fit coefficients
By : user2806114
Date : March 29 2020, 07:55 AM
I wish did fix the issue. What you are proposing to do is a massively bad idea, so much so that I'm reluctant to show you how to do it. The reason is that for OLS, assuming the residuals are normally distributed with constant variance, then the parameter estimates follow a multivariate tdistribution and we can calculate confidence limits and pvalues in the usual way. However, if we perform NNLS on the same data, the residuals will not be normally ditributed, and the standard techniques for calculating pvalues, etc. will produce garbage. There are methods for estimating confidence limits on the parameters of an NNLS fit (see this reference for instance), but they are approximate and usually rely on fairly restrictive assumptions about the dataset. code :
set.seed(1) # for reproducible example
data < as.data.frame(matrix(runif(1e4, min = 1, max = 1),nc=4))
colnames(data) <c("y", "x1", "x2", "x3")
data$y < with(data,10*x1+x2 + rnorm(2500))
A < as.matrix(data[,c("x1", "x2", "x3")])
b < data$y
test < nnls(A,b)
test
# Nonnegative least squares model
# x estimates: 0 1.142601 0
# residual sumofsquares: 88391
# reason terminated: The solution has been computed sucessfully.
fit < nls(y~b.1*x1+b.2*x2+b.3*x3,data,algorithm="port",lower=c(0,0,0))
fit
# Nonlinear regression model
# model: y ~ b.1 * x1 + b.2 * x2 + b.3 * x3
# data: data
# b.1 b.2 b.3
# 0.000 1.143 0.000
# residual sumofsquares: 88391
par(mfrow=c(1,2),mar=c(3,4,1,1))
qqnorm(residuals(lm(y~.,data)),main="OLS"); qqline(residuals(lm(y~.,data)))
qqnorm(residuals(fit),main="NNLS"); qqline(residuals(fit))

Plotting individual confidence intervals for the coefficients in the lmList fit
By : Costiaan Mesu
Date : March 29 2020, 07:55 AM
will be helpful for those in need There are only two observations with Dog == 9. This results in an NA for the estimate of the quadratic parameter and intervals can't handle that. If you exclude this subset it works: code :
fm2Pixel.lis < lmList(pixel ~ poly(day, 2, raw = TRUE)  Dog,
Pixel[Pixel$Dog != 9,])
plot(intervals(fm2Pixel.lis))

How do I add coefficients, SE, confidence intervals, and odds ratios in stargazer table?
By : KvnLf
Date : March 29 2020, 07:55 AM
hop of those help? Stargazer accepts multiple models and appends each to a new row. So, you can make a second model and replace the standard coefficients with odds ratios and pass this to the stargazer call. code :
tattoo < read.table("https://ndownloader.figshare.com/files/6920972",
header=TRUE, na.strings=c("unk", "NA"))
library(mlogit)
Tat<mlogit.data(tattoo, varying=NULL, shape="wide", choice="size", id.var="date")
ml.Tat<mlogit(size~1age+sex+yy, Tat, reflevel="small", id.var="date")
ml.TatOR<mlogit(size~1age+sex+yy, Tat, reflevel="small", id.var="date")
ml.TatOR$coefficients < exp(ml.TatOR$coefficients) #replace coefficents with odds ratios
library(stargazer)
stargazer(ml.Tat, ml.TatOR, ci=c(F,T),column.labels=c("coefficients","odds ratio"),
type="text",single.row=TRUE, star.cutoffs=c(0.05,0.01,0.001),
out="table1.txt", digits=4)
====================================================================
Dependent variable:

size
coefficients odds ratio
(1) (2)

large:(intercept) 444.6032*** (22.1015) 0.0000 (43.3181, 43.3181)
medium:(intercept) 187.9871*** (11.9584) 0.0000 (23.4381, 23.4381)
large:age 0.0251*** (0.0041) 1.0254*** (1.0174, 1.0334)
medium:age 0.0080** (0.0026) 1.0081*** (1.0030, 1.0131)
large:sexM 1.3818*** (0.0607) 3.9821*** (3.8632, 4.1011)
medium:sexM 0.7365*** (0.0330) 2.0886*** (2.0239, 2.1534)
large:yy 0.2195*** (0.0110) 1.2455*** (1.2239, 1.2670)
medium:yy 0.0931*** (0.0059) 1.0976*** (1.0859, 1.1093)

Observations 18,162 18,162
R2 0.0410 0.0410
Log Likelihood 15,882.7000 15,882.7000
LR Test (df = 8) 1,357.1140*** 1,357.1140***
====================================================================
Note: *p<0.05; **p<0.01; ***p<0.001

Plot coefficients with confidence intervals in R
By : easystuff
Date : March 29 2020, 07:55 AM
it helps some times We may use ggcoef from GGally. One issue is that you want to visualize only a subset of coefficients. In that case we can do code :
ggcoef(tail(broom::tidy(sample_lm, conf.int = TRUE), 51), sort = "ascending")
tbl < tail(broom::tidy(sample_lm, conf.int = TRUE), 51)
tbl$term < factor(tbl$term, levels = tbl$term)
ggcoef(tbl) + coord_flip() + theme(axis.text.x = element_text(angle = 30))

How to get coefficients and their confidence intervals in mixed effects models?
By : Jailson Junior
Date : March 29 2020, 07:55 AM
this will help There are two new packages, lmerTest and lsmeans, that can calculate 95% confidence limits for lmer and glmer output. Maybe you can look into those? And coefplot2, I think can do it too (though as Ben points out below, in a not so sophisticated way, from the standard errors on the Wald statistics, as opposed to KenwardRoger and/or Satterthwaite df approximations used in lmerTest and lsmeans)... Just a shame that there are still no inbuilt plotting facilities in package lsmeans (as there are in package effects(), which btw also returns 95% confidence limits on lmer and glmer objects but does so by refitting a model without any of the random factors, which is evidently not correct).

