https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4741409/
R codes and Programming
#original data was 500 observations, 2 varying variables HOMAR and INSULIN. 3 time periods
reshaped_data<-reshape(test.reshape,
direction = "long",
varying = c("HOMA_M0", "HOMA_M3","HOMA_M6", "INSULIN_M0", "INSULIN_M3", "INSULIN_M6"),
v.names = c("HOMAR", "INSULIN"),
idvar = c("id"),
timevar = "visit",
new.row.names = 1:1500,
times = 1:3)
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)
}
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
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 ```