Function to calculate CI of linear regression coefficients
Amateur code
```
jad<-function(x, y) {
model<-lm(y~x)
std.err<-coef(summary(model))[, 2]
coef.model1<-coef(summary(model))[, 1]
upper.ci<-coef.model1+1.96*std.err
lower.ci<-coef.model1-1.96*std.err
print(upper.ci)
print(lower.ci)
}
```
Pro code
jad <- function(x, y) {
`colnames<-`(
coef(summary(lm(y ~ x)))[,1:2] %*% matrix(c(1, 1.96, 1, -1.96), nrow = 2), c("upper.ci", "lower.ci")
)
}
Some data management Libraries for R
Library (magrittr)
Library (dplyr)
wrs%>%
extract(1:20,c("age", "edu")) %>%
head
or
wrs%>%
extract(1:20,1:2) %>%
head
Practical way to label factors
```
library(memisc)
labels(anemia$anem)<-c("not anemic"=0, "anemic"=1) #library memisc```
Subscribe to:
Posts (Atom)
Introduction to the Analysis of Survival Data in the Presence of Competing Risks
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4741409/
-
Sometimes when you are running a regression model with variables that have different lengths, r will prompt with the following error message...
-
``` library(memisc) labels(anemia$anem)<-c("not anemic"=0, "anemic"=1) #library memisc ```