forked from vasishth/MScStatisticsNotes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumericalMethods.Rnw
55 lines (38 loc) · 975 Bytes
/
NumericalMethods.Rnw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
\documentclass{article}
\title{Notes on numerical methods in R}
\author{Shravan Vasishth}
\begin{document}
\SweaveOpts{concordance=TRUE}
\maketitle
\section{Rounding and display of digits}
<<>>=
x<-.7/.1 -7
zapsmall(.7/.1) -7
formatC(x,format="f",big.mark=",")
x<-10000
formatC(x,format="f",big.mark=",")
formatC(x,format="E",big.mark=",")
.Machine
@
<<>>=
library(simgen)
library(lme4)
pmx <- createParamMx(10,h0=FALSE)
x.df <- mkDf(nsubj=24, nitem=24, mcr.params=pmx[1,], wsbi=FALSE)
xtabs(~ItemID+Cond,x.df)
m0<-lmer(Resp~Cond+(1+Cond|SubjID)+(1+Cond|ItemID),x.df)
summary(m0)
p.env<-getParamRanges()
as.list(p.env)
p.env$r01.subj.range<-c(0.6,0.6)
p.env$r01.item.range<-c(0.6,0.6)
nsim<-100
tvals<-rep(NA,nsim)
for(i in 1:nsim){
pmx <- createParamMx(10,h0=FALSE,simparam.env=p.env)
x.df <- mkDf(nsubj=24, nitem=48, mcr.params=pmx[1,], wsbi=FALSE)
m0<-lmer(Resp~Cond+(1+Cond|SubjID)+(1+Cond|ItemID),x.df)
tvals[i]<-summary(m0)$coef[2,3]
}
@
\end{document}