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)



https://uc-r.github.io/pipe#:~:text=The%20compound%20assignment%20%25%25,and%20then%20assigning%20the%20result.&text=The%20exposition%20(%20%25%24%25%20)%20operator%20is,to%20some%20of%20the%20columns.




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
```

Introduction to the Analysis of Survival Data in the Presence of Competing Risks

 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4741409/