This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bigf<-function(df) { | |
| df<-df[!is.na(df$rt),] | |
| df<-df[df$rt<60*5,] | |
| x<-irw::long2resp(df) | |
| id<-x$id | |
| x$id<-NULL | |
| m<-mirt::mirt(x,1,'Rasch') | |
| th<-mirt::fscores(m) | |
| th<-data.frame(id=id,th=th[,1]) | |
| df<-merge(df,th) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(TestGardener) | |
| convert<-function(resp) { | |
| n<-ncol(resp) | |
| N<-nrow(resp) | |
| for (i in 1:ncol(resp)) { | |
| vals<-sample(2:4,N,replace=TRUE) | |
| resp[,i]<-ifelse(resp[,i]==1,resp[,i],vals) | |
| } | |
| optList <- list() | |
| grbg <- matrix(0,n,1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##a helper function we'll use along the way. | |
| ##kr20 is a function that computes the kr20 version of cronbach's alpha | |
| kr20<-function(resp) { | |
| k<-ncol(resp) | |
| p<-colMeans(resp,na.rm=TRUE) | |
| q<-1-p | |
| o<-rowSums(resp) | |
| (k/(k-1))*(1-sum(p*q)/var(o)) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(schoolgrowth) | |
| ## > growthscores | |
| ## stuid school grade year subject Y | |
| ## 1 s0102 sch01 4 1 ela 50 | |
| ## 2 s0196 sch01 4 1 ela 46 | |
| ## 3 s0227 sch01 4 1 ela 5 | |
| ## 4 s0284 sch01 4 1 ela 18 | |
| ## 5 s0353 sch01 4 1 ela 15 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| simfun<-function(N,a1,beta.inter=.1) { | |
| ff<-function(i,N,a1,a2,beta.inter) { | |
| add.error<-function(t,alpha) { | |
| ve<-var(t)/alpha-var(t) | |
| e<-rnorm(N,mean=0,sd=sqrt(ve)) | |
| t+e | |
| } | |
| g<-rnorm(N) | |
| e<-rnorm(N) | |
| y<-.2*g+.5*e+beta.inter*g*e+rnorm(N) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #this contains the funtion that does the ML estimation | |
| ratio.test<-function(df, | |
| hess=FALSE, #if FALSE, compute empirical hessian | |
| ctl.list=list(maxit=1000,reltol=sqrt(.Machine$double.eps)/1000) | |
| ) { | |
| ## | |
| anal_vcov <- function(pars, df){ | |
| neg_hess <- function(pars,df) { #computes the negative hessian | |
| for (nm in names(pars)) assign(nm,pars[[nm]]) | |
| mu <- m*df$E + pi0*df$g + pi1*df$g*df$E |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| out<-list() | |
| for (s1 in seq(0,.2,by=.01)) { | |
| print(s1) | |
| test<-numeric() | |
| for (i in 1:250) { | |
| N=1000 | |
| h=sqrt(.6) | |
| e=sqrt(1-h^2) | |
| m=.35 | |
| s0=sqrt(1-m^2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interplay<-function(x,std.time.in.item=FALSE,nspl=4,plot.den=TRUE,top.plot=TRUE,...) { | |
| ##x needs to have columns: | |
| ## item [item id] | |
| ## id [person id] | |
| ## diff [item difficulty] | |
| ## th [person theta] | |
| ## pv [irt-based p-value] | |
| ## rt [response time in metric you want to analyze] | |
| ##resp [item response] | |
| ##################################################################### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #get genetic risk score | |
| read.table("/hrsshare/alz_context/pgs/alz_nc.profile",header=TRUE)->score | |
| score[,c(2,6)]->score | |
| names(score)<-c("subjectID","polygenic_score") | |
| #rand fat files | |
| load("/hrsshare/v2_hrs_linked.Rdata") | |
| x[,c("subjectID","hhidpn","family","raracem","rahispan")]->ids | |
| ids[ids$raracem=="1.white/caucasian" & ids$rahispan=="0. not hispanic",]->ids | |
| merge(ids,score)->x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| make_grs<-function(nm,df,fam.id="family",id="subjectID", | |
| threshold.seq, | |
| plink="/hrsshare/analytic_sample/hrs_geno_final", | |
| resid.fm=NULL) { | |
| dir.nm<-paste0("/tmp/",nm) | |
| system(paste("mkdir",dir.nm)) | |
| getwd()->dir.save | |
| setwd(dir.nm) | |
| if (!is.null(resid.fm)) { | |
| paste(nm,"~",resid.fm)->resid.fm |
NewerOlder