Commit 4924b94c authored by Keene's avatar Keene
Browse files

Initalition of repository

parents
This diff is collapsed.
---
title: "Linear mixed-effects model Becker"
author: "Thom TJ Veeger"
header-includes:
- \usepackage{amsmath}
date: "May 20 2020"
output:
html_document:
toc: true
---
# Preamble
Set options, read the data.
```{r set-options, echo=FALSE, cache=FALSE}
options(width=200)
```
```{r loading data, warning=FALSE, message=FALSE}
library(foreign)
library(lme4) # for the mixed model
library(lmerTest)
library(nlme)
library(ggplot2)
library(bootpredictlme4)
library(visreg)
library(ggrepel)
library(rgl)
library(plotly)
setwd("xxx")
FFdataset=read.spss("xxx.sav",to.data.frame=TRUE)
Muscle_char=read.spss("xxx.sav",to.data.frame=TRUE)
```
# Log odds transformation of the fat fraction
```{r log odd FF, warning=FALSE, message=FALSE}
# Transform outcome and fit lmer.
FFdataset$FF=round(FFdataset$FF,4)
y=log(FFdataset$FF/(1-FFdataset$FF))# log odds of the fat fraction, to be modelled as normal
```
# Building up the model
```{r models, warning=FALSE, message=FALSE}
FFdataset$AgeCentered = (FFdataset$Age - mean(FFdataset$Age))
FFdataset$FLCentered = (FFdataset$Fib_Length - mean(FFdataset$Fib_Length))
FFdataset$PCSAcentered = (FFdataset$PCSA - mean(FFdataset$PCSA))
model_full = lmer(y ~ AgeCentered + FLCentered + PCSAcentered + FLCentered * PCSAcentered + (AgeCentered|Subject) + (AgeCentered|Muscle), data=FFdataset, control=lmerControl(optCtrl=list(maxfun=1e8)),REML=FALSE)
summary(model_full)
CI=confint(model_full, c("(Intercept)", "AgeCentered","FLCentered","PCSAcentered","FLCentered:PCSAcentered"), level = 0.95)
```
```{r bootstrap, warning=FALSE, message=FALSE, results="hide"}
options(bootnsim=1000)
#for figure 3
tmp=visreg(model_full,plot=FALSE)
#for figure 4
tmp6=visreg2d(model_full, "FLCentered","PCSAcentered",type="conditional",plot.type="image",binwidth=0.05,nn=99,zlab="FF",xlab=c("Fiber length (cm)"),ylab=c("PCSA(cm2)"))
for (i in 1:3){
tmp[[i]]$fit$visregUpr=exp(tmp[[i]]$fit$visregUpr)/(1+exp(tmp[[i]]$fit$visregUpr))
tmp[[i]]$fit$visregLwr=exp(tmp[[i]]$fit$visregLwr)/(1+exp(tmp[[i]]$fit$visregLwr))
tmp[[i]]$fit$visregFit=exp(tmp[[i]]$fit$visregFit)/(1+exp(tmp[[i]]$fit$visregFit))
tmp[[i]]$res$visregRes=exp(tmp[[i]]$res$visregRes)/(1+exp(tmp[[i]]$res$visregRes))
tmp[[i]]$res$y=exp(tmp[[i]]$res$y)/(1+exp(tmp[[i]]$res$y))
}
#decentering the data
tmp[[1]]$fit$AgeCentered=tmp[[1]]$fit$AgeCentered+mean(FFdataset$Age)
tmp[[1]]$res$AgeCentered=tmp[[1]]$res$AgeCentered+mean(FFdataset$Age)
tmp[[2]]$fit$FLCentered=tmp[[2]]$fit$FLCentered+mean(FFdataset$Fib_Length)
tmp[[2]]$res$FLCentered=tmp[[2]]$res$FLCentered+mean(FFdataset$Fib_Length)
tmp[[3]]$fit$PCSAcentered=tmp[[3]]$fit$PCSAcentered+mean(FFdataset$PCSA)
tmp[[3]]$res$PCSAcentered=tmp[[3]]$res$PCSAcentered+mean(FFdataset$PCSA)
#scale the logFF data back to FF scale
tmp6$z=exp(tmp6$z)/(1+exp(tmp6$z))
tmp6$x=tmp6$x+mean(FFdataset$Fib_Length)
tmp6$y=tmp6$y+mean(FFdataset$PCSA)
```
```{r plots, warning=FALSE, message=FALSE, echo=FALSE}
# plots for figure 3
plot(tmp[[1]],gg=TRUE,ylab="FF",xlab=c("Age (year)"),fill.par=list(fill="#ADD8E6"))+theme(axis.text=element_text(size=15),axis.title=element_text(size=17,face="bold"))
plot(tmp[[2]],gg=TRUE,ylab="FF",xlab=c("Fiber length (cm)"),fill.par=list(fill="#ADD8E6"))+theme(axis.text=element_text(size=15),axis.title=element_text(size=17,face="bold"))
plot(tmp[[3]],gg=TRUE,ylab="FF",xlab=c("PCSA (cm^2)"),fill.par=list(fill="#ADD8E6"))+theme(axis.text=element_text(size=15),axis.title=element_text(size=17,face="bold"))
colfunc <- colorRampPalette(c("green","yellow","orange","red"))
#plot for figure 4
plot_ly(x = Muscle_char$Fib_Length, y = Muscle_char$PCSA)%>%
layout(yaxis = list(tickfont=list(size=15)), xaxis = list(tickfont=list(size=15)))%>%
add_contour(x = tmp6$x, y = tmp6$y,z=t(tmp6$z),colors=colfunc(100),contours = list(start = 0,
end = 1,
size = 0.05,
showlabels = TRUE))%>%
add_markers(x = Muscle_char$Fib_Length, y = Muscle_char$PCSA, marker=list(size=Muscle_char$Mass/10), color=I("#666666"),opacity=.75)%>%
add_markers(x = Muscle_char$Fib_Length, y = Muscle_char$PCSA, marker=list(size=2), color=I("Black"),opacity=1)%>%
add_annotations(
x=Muscle_char$Fib_Length,
y=Muscle_char$PCSA,
text=Muscle_char$Muscle,
arrowhead = 0,
arrowcolor="#999999",
arrowwidth=0.1,
ax=c(-27,-15,-20,-13,17,-15,3,-25,18,15,15,-27,0,0,-15,-10,0),
ay=c(0,0,0,0,0,0,12,0,0,0,0,0,-10,10,0,0,9))
```
---
title: "Linear mixed-effects model Duchenne"
author: "Thom TJ Veeger"
header-includes:
- \usepackage{amsmath}
date: "May 20 2020"
output:
html_document:
toc: true
---
# Preamble
Set options, read the data.
```{r set-options, echo=FALSE, cache=FALSE}
options( width=200)
```
```{r loading data, warning=FALSE, message=FALSE}
library(foreign)
library(lme4) # for the mixed model
library(lmerTest)
library(nlme)
library(ggplot2)
library(bootpredictlme4)
library(visreg)
library(ggrepel)
library(rgl)
library(plotly)
setwd("xxx")
FFdataset=read.spss("xxx.sav",to.data.frame=TRUE)
Muscle_char=read.spss("Muscle_char.sav",to.data.frame=TRUE)
#FFdataset$FF = FFdataset$FF/100
```
# Log odds transformation of the fat fraction
```{r log odd FF, warning=FALSE, message=FALSE}
# Transform outcome and fit lmer.
FFdataset$FF=round(FFdataset$FF,4)
y=log(FFdataset$FF/(1-FFdataset$FF))# log odds of the fat fraction, to be modelled as normal
```
# Building up the model
```{r models, warning=FALSE, message=FALSE}
FFdataset$AgeCentered = FFdataset$Age - mean(FFdataset$Age)
FFdataset$FLCentered = (FFdataset$Fib_Length - mean(FFdataset$Fib_Length))
FFdataset$PCSAcentered = (FFdataset$PCSA - mean(FFdataset$PCSA))
model_full = lmer(y ~ AgeCentered + FLCentered + PCSAcentered + FLCentered * PCSAcentered + (AgeCentered|Subject) + (AgeCentered|Muscle), data=FFdataset, control=lmerControl(optCtrl=list(maxfun=1e8)),REML=FALSE)
summary(model_full)
CI=confint(model_full, c("(Intercept)", "AgeCentered","FLCentered","PCSAcentered","FLCentered:PCSAcentered"), level = 0.95)
```
```{r bootstrap, warning=FALSE, message=FALSE, results="hide"}
options(bootnsim=1000)
#for figure 3
tmp=visreg(model_full,plot=FALSE)
#for figure 4
tmp6=visreg2d(model_full, "FLCentered","PCSAcentered",type="conditional",plot.type="image",binwidth=0.05,nn=99,zlab="FF",xlab=c("Fiber length (cm)"),ylab=c("PCSA(cm2)"))
#scale the logFF data back to FF scale
for (i in 1:3){
tmp[[i]]$fit$visregUpr=exp(tmp[[i]]$fit$visregUpr)/(1+exp(tmp[[i]]$fit$visregUpr))
tmp[[i]]$fit$visregLwr=exp(tmp[[i]]$fit$visregLwr)/(1+exp(tmp[[i]]$fit$visregLwr))
tmp[[i]]$fit$visregFit=exp(tmp[[i]]$fit$visregFit)/(1+exp(tmp[[i]]$fit$visregFit))
tmp[[i]]$res$visregRes=exp(tmp[[i]]$res$visregRes)/(1+exp(tmp[[i]]$res$visregRes))
tmp[[i]]$res$y=exp(tmp[[i]]$res$y)/(1+exp(tmp[[i]]$res$y))
}
#decentering the data
tmp[[1]]$fit$AgeCentered=tmp[[1]]$fit$AgeCentered+mean(FFdataset$Age)
tmp[[1]]$res$AgeCentered=tmp[[1]]$res$AgeCentered+mean(FFdataset$Age)
tmp[[2]]$fit$FLCentered=tmp[[2]]$fit$FLCentered+mean(FFdataset$Fib_Length)
tmp[[2]]$res$FLCentered=tmp[[2]]$res$FLCentered+mean(FFdataset$Fib_Length)
tmp[[3]]$fit$PCSAcentered=tmp[[3]]$fit$PCSAcentered+mean(FFdataset$PCSA)
tmp[[3]]$res$PCSAcentered=tmp[[3]]$res$PCSAcentered+mean(FFdataset$PCSA)
#scale the logFF data back to FF scale and decenter
tmp6$z=exp(tmp6$z)/(1+exp(tmp6$z))
tmp6$x=tmp6$x+mean(FFdataset$Fib_Length)
tmp6$y=tmp6$y+mean(FFdataset$PCSA)
```
```{r plots, warning=FALSE, message=FALSE, echo=FALSE}
colfunc <- colorRampPalette(c("green","yellow","orange","red"))
color=colfunc(17)
# plots for figure 3
plot(tmp[[1]],gg=TRUE,ylab="FF",xlab=c("Age (year)"),fill.par=list(fill="#ADD8E6"))+theme(axis.text=element_text(size=15),axis.title=element_text(size=17,face="bold"))
plot(tmp[[2]],gg=TRUE,ylab="FF",xlab=c("Fiber length (cm)"),fill.par=list(fill="#ADD8E6"))+theme(axis.text=element_text(size=15),axis.title=element_text(size=17,face="bold"))
plot(tmp[[3]],gg=TRUE,ylab="FF",xlab=c("PCSA (cm^2)"),fill.par=list(fill="#ADD8E6"))+theme(axis.text=element_text(size=15),axis.title=element_text(size=17,face="bold"))
#plot for figure 4
plot_ly(x = Muscle_char$Fib_Length, y = Muscle_char$PCSA)%>%
layout(yaxis = list(tickfont=list(size=15)), xaxis = list(tickfont=list(size=15)))%>%
add_contour(x = tmp6$x, y = tmp6$y,z=t(tmp6$z),colors=colfunc(100),contours = list(
start = 0,
end = 1,
size = 0.05,
showlabels = TRUE))%>%
add_markers(x = Muscle_char$Fib_Length, y = Muscle_char$PCSA, marker=list(size=Muscle_char$Mass/10), color=I("#666666"),opacity=.75)%>%
add_markers(x = Muscle_char$Fib_Length, y = Muscle_char$PCSA, marker=list(size=2), color=I("Black"),opacity=1)%>%
add_annotations(
x=Muscle_char$Fib_Length,
y=Muscle_char$PCSA,
text=Muscle_char$Muscle,
arrowhead = 0,
arrowcolor="#999999",
arrowwidth=0.1,
ax=c(-27,-15,-20,-13,17,-15,3,-25,18,15,15,-27,0,0,-15,-10,0),
ay=c(0,0,0,0,0,0,12,0,0,0,0,0,-10,10,0,0,9))
```
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment