File: Collaboration boosts career progression_part

Comment: Get residuals of tie strength adjusted tie strength model_tiestrength glm(strength.mean~no.of.papers:Gender, family"gaussian", data new) model with strength not transformed looked a bit dodgy, so we logtransformed strength
Category: Statistical Modeling
Code:
model_tiestrength = glm(log(strength.mean)~no.of.papers:Gender+no.of.papers, family="gaussian", data = new) model_tiestrength = glm(log(strength.mean)~no.of.papers:Gender, family="gaussian", data = new) hist(resid(model_tiestrength), main = "residuals of model with log(tie strength)") qqnorm(resid(model_tiestrength)) summary(model_tiestrength) summ(model_tiestrength) new$residuals.strength <- resid(model_tiestrength) hist(new$residuals.strength)

Comment: get number of papers (and other stats) per gender
Category: Data Variable
Code:
ddply(new, "Gender",summarise, mean = mean(no.of.papers, na.rm = TRUE), median = median(no.of.papers, na.rm = TRUE), sd = sd(no.of.papers, na.rm = TRUE), N = sum(!is.na(no.of.papers)), se = sd / sqrt(N), min = min(no.of.papers, na.rm = TRUE), max = max(no.of.papers, na.rm = TRUE))

Comment: Create censoring VARIABLE PI status: 1 if PI, 0 if author did not make it to PI
Category: Data Variable
Code:
new.PI$status.PI = ifelse(!is.na(new.PI$Time.to.PI),1,0)

Comment: Gender effect of Gender on time to PI
Category: Data Variable
Code:
flexgender<-flexsurvreg(Surv(new.PI$time.PI,new.PI$status.PI)~Gender, dist="lnorm", data=new.PI) flexgender

Comment: fit_lognormal Lowest AIC, best fit Package flexsurv provides access to additional distributions Also allows plotting options want red lines to match as close as possible to KM curve
Category: Visualization
Code:
fit_exp<-flexsurvreg(Surv(new$n.years,new$status)~1, dist="exp") fit_weibull<-flexsurvreg(Surv(new$n.years,new$status)~1, dist="weibull") fit_gamma<-flexsurvreg(Surv(new$n.years,new$status)~1, dist="gamma") fit_gengamma<-flexsurvreg(Surv(new$n.years,new$status)~1, dist="gengamma") fit_genf<-flexsurvreg(Surv(new$n.years,new$status)~1, dist="genf") fit_lognormal<-flexsurvreg(Surv(new$n.years,new$status)~1, dist="lnorm") fit_gompertz<-flexsurvreg(Surv(new$n.years,new$status)~1, dist="gompertz") fit_exp fit_weibull fit_gamma fit_gengamma fit_genf fit_lognormal fit_gompertz plot(fit_exp) plot(fit_weibull) plot(fit_gamma) plot(fit_gengamma) plot(fit_genf) plot(fit_lognormal) plot(fit_gompertz)

Comment: Generalized gamma distribution is not sig. better fit than lognormal distribution. Justifies using lognormal. AFT model AFT model uses survreg function from Survival package using lognormal distribution according to earlier exploration of the best distribution for the data use survreg for stepwise then flexsurvreg to generate graphs GENDER Examine gender differences first, ignoring any of the social metrics Effect of gender on career length (n.years)
Category: Statistical Modeling
Code:
flexAFTgender<-flexsurvreg(Surv(n.years,status)~Gender,dist="lnorm",data=new) flexAFTgender plot(flexAFTgender,col=c("blue","red"),ci=T,xlab="Years",ylab="Survival probability")

Comment: Reverses the factor level ordering for labels after coord_flip()
Category: Data Variable
Code:
df$labeltext<-factor(df$labeltext, levels=rev(df$labeltext)) df$colour <- c("dark grey","dark grey","black","black","dark grey","dark grey") df_TPICL$labeltext_TPICL <- factor(df_TPICL$labeltext_TPICL, levels=rev(df_TPICL$labeltext_TPICL)) df_TPICL$colour <- c("dark grey","dark grey","dark grey","dark grey","dark grey","dark grey","black","black","dark grey","dark grey","dark grey","dark grey") plotTPICL1<- ggplot(data=df_TPICL, aes(x=labeltext_TPICL, y=estimate_TPICL, ymin=lower_TPICL, ymax=upper_TPICL, col=Gender_TPICL, shape=Gender_TPICL))+ annotate("rect", xmin = 0, xmax = 6.5, ymin = 1, ymax = 5, alpha = .2, fill = "grey") + annotate("rect", xmin = 6.5, xmax = 12.7, ymin = 0, ymax = 1, alpha = .2, fill = "grey") + geom_point(aes(size=2,col = colour, fill = colour),show.legend=FALSE)+ geom_pointrange(size=0.7, col = df_TPICL$colour, fill = df_TPICL$colour,show.legend=FALSE) + geom_hline(yintercept=1, lty=2) + # Add a dotted line at x=1 after flip geom_vline(xintercept=6.5, lty=1) + # Adds a solid line at y=6.5 after flip to differentiate between top panel = career longevity and bottom panel = time to PI geom_errorbar(aes(ymin=lower_TPICL, ymax=upper_TPICL,width=0.6,cex=1,col=colour, fill = colour),show.legend=FALSE) + scale_x_discrete(breaks=c(1,3,5,7,9,11), labels=c("Adj. Network Size","Adj. Tie Strength","Adj. Clustering Coef.", "Adj. Network Size","Adj. Tie Strength","Adj. Clustering Coef.")) + coord_flip() + # Flip coordinates (puts labels on y axis) xlab("Label") + ylab("Deceleration factor") + scale_fill_manual(values=c("dark grey","dark grey","black","black","dark grey","dark grey","black","black","dark grey","dark grey","dark grey","dark grey"))+ scale_colour_manual(values=c("black","dark grey","dark grey","dark grey","black","black")) + scale_shape_manual(values=c(17,16))+ annotate("text",x=7.2, y=5, label="Time to become a PI",size=5,fontface="bold",hjust=1) + annotate("text",x=1, y=5, label="Career length", size=5,fontface="bold",hjust=1) + theme(axis.title.y = element_blank(), # Remove y axis title axis.text.y = element_text(size=12, colour="black"), # Change size of y axis labels axis.text.x = element_text(size=12,colour="black"), # Change size of x axis numbers axis.title.x = element_text(size=14,vjust=0.5,colour="black",face="bold"), # Change size and font of x axis title and move it down a bit panel.grid.major = element_blank(), # Formatting to create blank plot with box around it axis.line = element_line(colour="black"), panel.background = element_rect(colour = "black", size=1, fill=NA), legend.title =element_blank())+ guides(colour=FALSE)

Comment: Add label to plot C
Category: Visualization
Code:
plotTPICL2<-plotTPICL1+ labs(tag="C")+ theme(plot.tag.position = c(0.19,0.5),plot.tag = element_text(size=14,face="bold"))

Comment: Now layout plots and plot them labels for plots A and B added here
Category: Visualization
Code:
ggarrange(plotPIstatus,plotTPICL2,heights=c(1,1.7),ncol=1,nrow=2,labels=c("A","B"),label.x=0.18,label.y=0.95)