全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 HLM专版
3684 14
2013-12-02
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-12-10 00:11:58
Examples
## Not run:
library(R2MLwiN)
## Modify the following paths as appropriate.
## MLwiN folder
mlwin ="C:/Program Files (x86)/MLwiN v2.27/"
## MLwiN sample worksheet folder
wspath=paste(mlwin,"/samples/",sep="")
## MLwiN sample worksheet: tutorial dataset
wsfile=paste(wspath,"tutorial.ws",sep="");inputfile=paste(tempdir(),"/tutorial.dta",sep="")
ws2foreign(wsfile, foreignfile=inputfile, MLwiNPath=mlwin)
library(foreign);indata =read.dta(inputfile)
## Define the model
formula="normexam~(0|cons+standlrt)+(2|cons+standlrt)+(1|cons)"
levID=c('school','student')
## Choose option(s) for inference
estoptions= list(EstM=1)## Fit the model
(mymodel=runMLwiN(formula, levID, D="Normal", indata, estoptions, MLwiNPath=mlwin))

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-12-10 00:17:09
Examples
## Not run:
# NB: change path as appropriate
MLwiN <- "C:/Program Files (x86)/MLwiN v2.27/"
data(bang1)
bang1$use <- as.numeric(bang1$use) - 1
bang1$urban <- as.numeric(bang1$urban) - 1
# Fit 2-level random coefficient logistic model, using MCMC
# cons (constant of ones) as denominator specifies
# Bernoulli distribution (0/1 response)
F1 = "logit(use, cons) ~ (0|cons + age + lc[nokids] + urban) + (2|cons + urban)"
ID = c("district", "woman")
binomialMCMC <- runMLwiN(Formula = F1, levID = ID, D = "Binomial",
indata = bang1, estoptions = list(EstM = 1), MLwiNPath = MLwiN)
## End(Not run)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-12-10 00:18:50
Examples
## Not run:
library(R2MLwiN)
## Modify the following paths as appropriate.
## MLwiN folder
mlwin = "C:/Program Files (x86)/MLwiN v2.27/"
## MLwiN sample worksheet folder
wspath=paste(mlwin,"/samples/",sep="")
## Example: tutorial
formula="normexam~(0|cons+standlrt)+(2|cons)+(1|cons)"
levID=c('school','student')
wsfile=paste(wspath,"tutorial.ws",sep="")
inputfile=paste(tempdir(),"/tutorial.dta",sep="")
ws2foreign(wsfile, foreignfile=inputfile, MLwiNPath=mlwin)
library(foreign);indata =read.dta(inputfile)
estoptions= list(EstM=1,resi.store=TRUE,resi.store.levs=2,mcmcMeth=list(iterations=5001))
(mymodel=runMLwiN(formula, levID, D="Normal", indata, estoptions,MLwiNPath=mlwin))
lencateg = length(unique(indata[["school"]]))
resi.chain2 = mymodel["resi.chains"][,1]
resi.chain2 = matrix(resi.chain2, nrow =lencateg)
## For each iteration, rank the schools
u0rank = apply(resi.chain2,2,rank)
## For each school, calculate the mean rank...
u0rankmn = apply(u0rank, 1,mean)
u0ranklo = apply(u0rank, 1, function(x) quantile(x,.025))
u0rankmd = apply(u0rank, 1,median)
u0rankhi = apply(u0rank, 1, function(x) quantile(x,.975))
rankno = order(u0rankmn)
caterpillar(y=u0rankmn[rankno], x=1:65, qtlow=u0ranklo[rankno], qtup=u0rankhi[rankno],
xlab="School", ylab="Rank")
## End(Not run)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-12-10 00:19:37
Examples
## Not run:
library(R2MLwiN)
## Modify the following paths as appropriate.
## MLwiN folder
mlwin = "C:/Program Files (x86)/MLwiN v2.27/"
## MLwiN sample worksheet folder
wspath=paste(mlwin,"/samples/",sep="")
## Example: Normal
formula="normexam~(0|cons)+(2|cons)+(1|cons)"
levID=c('school','student')
estoptions= list(resi.store=TRUE)
wsfile=paste(wspath,"tutorial.ws",sep="")
inputfile=paste(tempdir(),"/tutorial.dta",sep="")
ws2foreign(wsfile, foreignfile=inputfile, MLwiNPath=mlwin)
library(foreign);indata =read.dta(inputfile)
mymodel=runMLwiN(formula, levID, D="Normal", indata, estoptions,MLwiNPath=mlwin)
## Caterpillar plot
caterpillarR(mymodel["residual"], lev=2)
## End(Not run)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-12-10 00:20:54
Examples
## Not run:
# NB: change path as appropriate
MLwiN <- "C:/Program Files (x86)/MLwiN v2.27/"
data(jspmix1)
# behaviour coded 0/1
jspmix1$behaviour <- as.numeric(jspmix1$behaviour) - 1
# fit multilevel mixed response model, modelling effect of sex
# and ravens on both responses, and fluent on english response only
F1 = "c(english, probit(behaviour, cons)) ~ (0s|cons + sex + ravens)
+ (0c|fluent{1, 0}) + (2s|cons) + (1s|cons.english)"
ID = c("school", "id")
(MixedRespMCMC <- runMLwiN(Formula = F1, levID = ID,
D = c("Mixed", "Normal", "Binomial"), indata = jspmix1,
estoptions = list(EstM = 1, mcmcMeth = list(fixM = 1, residM = 1, Lev1VarM = 1)),
MLwiNPath = MLwiN))
## End(Not run)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群