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
| data { | |
| int<lower=1> N; | |
| real rt[N]; //outcome | |
| real c1[N]; //predictor | |
| real c2[N]; //predictor | |
| real c3[N]; //predictor | |
| int<lower=1> I; //number of subjects | |
| int<lower=1, upper=I> id[N]; //subject id | |
| vector[4] mu_prior; //vector of zeros passed in from R | |
| } |
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
| Details: | |
| key: | |
| beta[1] = Intercept | |
| beta[2] = c1 | |
| beta[3] = c2 | |
| beta[4] = c3 | |
| 1. Fixed effects, Stan vs lmer: | |
| Stan: |
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
| model | |
| { | |
| # The model for each observational unit | |
| # (each row is a subject's data point) | |
| for( j in 1:N ) | |
| { | |
| mu[j] <- beta[1] + beta[2] * ( so[j] ) + u[subj[j]] + w[item[j]] | |
| rt[j] ~ dnorm( mu[j], tau.e ) | |
| ##change the above line to: | |
| #rt[j] ~ dt(mu[j],tau.e, 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
| newcomb <- | |
| c(28,26,33,24,34,-44,27,16,40,-2, | |
| 29,22,24,21,25,30,23,29,31,19, | |
| 24,20,36,32,36,28,25,21,28,29, | |
| 37,25,28,26,30,32,36,26,30,22, | |
| 36,23,27,27,28,27,31,27,26,33, | |
| 26,32,32,24,39,28,24,25,32,25, | |
| 29,27,28,29,16,23) | |
| # Data as a list |
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
| > # Calculate the predicted random effects by hand for the ergoStool data | |
| > (fm1<-lmer(effort~Type-1 + (1|Subject),ergoStool)) | |
| Linear mixed model fit by REML | |
| Formula: effort ~ Type - 1 + (1 | Subject) | |
| Data: ergoStool | |
| AIC BIC logLik deviance REMLdev | |
| 133 143 -60.6 122 121 | |
| Random effects: | |
| Groups Name Variance Std.Dev. | |
| Subject (Intercept) 1.78 1.33 |
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
| > summary(lm<-lm(wear~material-1,BHHshoes)) | |
| > X<-model.matrix(lm) | |
| > 2.49^2*solve(t(X)%*%X) | |
| materialA materialB | |
| materialA 0.62001 0.00000 | |
| materialB 0.00000 0.62001 |
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
| > b1.vals<-subset(BHHshoes,material=="A")$wear | |
| > b2.vals<-subset(BHHshoes,material=="B")$wear | |
| > | |
| > vcovmatrix<-var(cbind(b1.vals,b2.vals)) | |
| > | |
| > covar<-vcovmatrix[1,2] | |
| > sds<-sqrt(diag(vcovmatrix)) | |
| > covar/(sds[1]*sds[2]) | |
| b1.vals | |
| 0.98823 |
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
| > (lm.full<-lmer(wear~material-1+(1|Subject), data = BHHshoes)) | |
| Linear mixed model fit by REML | |
| Formula: wear ~ material - 1 + (1 | Subject) | |
| Data: BHHshoes | |
| AIC BIC logLik deviance REMLdev | |
| 62.9 66.9 -27.5 53.8 54.9 | |
| Random effects: | |
| Groups Name Variance Std.Dev. | |
| Subject (Intercept) 6.1009 2.470 | |
| Residual 0.0749 0.274 |
NewerOlder