




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、R-practice session 3cs&ss 560Marijtje van Duijn Winter 2006The commands used in this session are available as R syntax file (Session3.R) at the website.Data input and preparationWe continue with the data used in Snijders & Bosker. For a description see Example 4.1 (p. 46).The data are the same as in
2、 the previous session, except for the treatment of the variable IQc. This variable is the grandmean centered IQ. Then the same procedure is followed as before, resulting in two variables, a centered and an uncentered one, measuring IQ in deviation to its school meanGo the file practice session3.r an
3、d execute the commands under data preparation. One other new variable will be produced, called z2, that is the deviation of the (school variable) groupsize with respect to the overall mean groupsize (equal to 23.1, approximately). Note that the groupsize can be larger than the number of students per
4、 school in the dataset due to missing pupils.Comparing (nested) models and estimating a random slope modelMake sure the library nlme is attached.First we will give a command to format the output a little nicer, restricting the number of decimal places.options(digits=5)This seems to be the best choic
5、e, although R does not always obey” this command. If you like, play around a bit with other choices for the number of digits. In the same options command you can decide to turn of the use of stars to signal significance - in the eyes of many statisticians a despicable practiceoptions(show.signif.sta
6、rs=FALSE)We will first estimate the models from Tables 4.2, 4.4, and 4.5 again.Check that we are now reproducing the output in the tables, and look at the funny p-values.model.4.2summary(model.4.2)VarCorr(model.4.2) model.4.4summary(model.4.4)VarCorr(model.4.4)We can do a deviance test or likelihood
7、 ratio test by giving the commandanova(model.4.4,model.4.2)Here, however, it is not necessary to do a deviance test, because the models only differ in their fixed effects: model 4.4 is model.4.2 + meanIQc. It is then preferable (from a statistical point of view) to use a t-test as reported in the su
8、mmary output, or an F-test (remember its relation to the t-test?) that can be obtained with the commandanova(model.4.4)Because of the small p-values we dont see any difference in the test, but the results can be different - especially when testing multiple fixed effects, or categorical variables.Bec
9、ause going from model.4.2. to model.4.4 means the addition of the variable meanIQc, R allows (for lme() but also for lm() the commandmodel.4.4model.4.4model.5.1summary(model.5.1)VarCorr(model.5.1)We could also get model.5.1 by updating model.4.4 (and changing the estimation method), with the command
10、smodel.5.1model.5.1mode/.4.4anova(model.5.1,model.4.4)Here we cannot use a t-test or F-test for testing the significance of the addition of a random effect, and is the likelihood ratio test the easiest.Note that the likelihood ratio test is done with 2 degrees of freedom. Two extra parameters were e
11、stimated in model.5.1 compared to model.4.4: the variance of the slope and the covariance between slope and intercept (%2and tq1).It is the case that the p-values with the chi-square approximation are conservative for nested multilevel models - the reason for this being that the test considers a nul
12、l hypothesis (a variance equal to zero) on the boundary of the parameter space (a variance cannot be smaller than zero). A solution is to use a bootstrap procedure to obtain a better estimate of the p-value. This procedure can be done in the nlme package (see Pinheiro & Bates, 2000, section 2.4) but
13、 for most purposes the conservative chi-square test seems sufficient.To investigate whether the random slope can be explained using the variable z2, the centered group size, the model of table 5.2 is estimatedmodel.5.2summary(model.5.2)An interaction can be specified with the * sign, but also with t
14、he : sign (as used in the output). Lets see whether we can do without the random slopes now.Unfortunately, the update function does not work for the random part, so we will specify model.5.2asummary(model.5.2a)anova(model.5.2,model.5.2a)So the conclusion is.?I leave the model in table 5.3 as an exer
15、cise.The influence of centeringLast week we saw that it matters for the intercept whether or not we center an explanatory variable. Lets investigate what the effect is on the variance structure. From the theoretical derivations of the between- and within-group variances, we know that this should mak
16、e a difference.First we estimate the model in table 5.1 not using the centered IQ. Here we see the expected effect on the (level 2) intercept variance.model.5.1.asummary(model.5.1.a)VarCorr(model.5.1.a)anova(model.5.1.a,model.5.1)Next we estimate the model in table5.1 using IQ in deviation to its gr
17、oup (school) mean. And now we observe not a difference in the variance structure, but in the estimates of the fixed effects.model.5.1.bsummary(model.5.1.b)VarCorr(model.5.1.b)anova(model.5.1.b,model.5.1)Compare this to model.4.9.model.4.9summary(model.4.9)VarCorr(model.4.9)I admit that the differenc
18、es are not so big, but that is because of the large dataset, with many schools and many students!Visualizing random slopesWe can get a visual impression of the size of the variation by making a graph like figure 5.1. We will draw a sample of 15 school interecepts and slopes from the population with the bivariate normal distributism parameters as estimated in model.5.1. We can draw from a multivariate normal distribution, using the function mvrnorm(), available in the MASS library. We do this after having specified its parameters, taken from the output. (We co
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 流行性結(jié)膜炎的健康宣教
- 二年級(jí)數(shù)學(xué)兩位數(shù)加兩位數(shù)計(jì)算題質(zhì)量自測(cè)試題大全附答案
- 小學(xué)教師心理培訓(xùn)講座
- 糖尿病視網(wǎng)膜病變的健康宣教
- 結(jié)膜炎的健康宣教
- 相對(duì)性紅細(xì)胞增多癥的健康宣教
- 春節(jié)前安全教育主題班會(huì)
- 汽車行業(yè)總結(jié)匯報(bào)
- 護(hù)理排班優(yōu)化管理制度
- EHS題庫(kù)復(fù)習(xí)測(cè)試卷
- 航空航天概論智慧樹知到期末考試答案章節(jié)答案2024年西安航空學(xué)院
- 人教版七年級(jí)下冊(cè)生物重點(diǎn)知識(shí)提綱(填空版)
- 2024年河南水利與環(huán)境職業(yè)學(xué)院?jiǎn)握新殬I(yè)適應(yīng)性測(cè)試題庫(kù)審定版
- 國(guó)家八年級(jí)數(shù)學(xué)質(zhì)量測(cè)試題(六套)
- MOOC 宋詞經(jīng)典-浙江大學(xué) 中國(guó)大學(xué)慕課答案
- MOOC 工程材料學(xué)-華中科技大學(xué) 中國(guó)大學(xué)慕課答案
- 基于自由現(xiàn)金流折現(xiàn)模型的江中藥業(yè)估值分析
- 礦山設(shè)備授權(quán)書
- 人教版五年級(jí)數(shù)學(xué)下冊(cè)第七單元《折線統(tǒng)計(jì)圖》(教學(xué)設(shè)計(jì))
- 金鏟鏟之戰(zhàn)教程
- 青春期生殖保健知識(shí)講座
評(píng)論
0/150
提交評(píng)論