科学网

 找回密码
  注册

tag 标签: repeated

相关帖子

版块 作者 回复/查看 最后发表

没有相关内容

相关日志

[转载]R and Analysis of Variance ( within subjects)
ljxue 2013-3-22 21:38
http://personality-project.org/r/r.anova.html (Repeated measures ANOVA) One way ANOVA - within subjects Example 3. One-Way Within-Subjects ANOVA Five subjects are asked to memorize a list of words. The words on this list are of three types: positive words, negative words and neutral words. Their recall data by word type is displayed in Appendix III. Note that there is a single factor (Valence ) with three levels (negative, neutral and positive). In addition, there is also a random factor Subject . Create a data file ex3 that contains this data. Again it is important that each observation appears on an individual line! Note that this is not the standard way of thinking about data. Example 6 will show how to transform data from the standard data table into this form. #Run the analysis: datafilename=http://personality-project.org/r/datasets/R.appendix3.data data.ex3=read.table(datafilename,header=T) #read the data into a table data.ex3 #show the data aov.ex3 = aov(Recall~Valence+Error(Subject/Valence),data.ex3) summary(aov.ex3) print(model.tables(aov.ex3,means),digits=3) #report the means and the number of subjects/cell boxplot(Recall~Valence,data=data.ex3) #graphical output Because Valence is crossed with the random factor Subject (i.e., every subject sees all three types of words), you must specify the error term for Valence , which in this case is Subject by Valence . Do this by adding the termError(Subject/Valence) to the factor Valence , as shown above. The output will look like: datafilename=http://personality-project.org/r/datasets/R.appendix3.data data.ex3=read.table(datafilename,header=T) #read the data into a table data.ex3 #show the data Observation Subject Valence Recall 1 1 Jim Neg 32 2 2 Jim Neu 15 3 3 Jim Pos 45 4 4 Victor Neg 30 5 5 Victor Neu 13 6 6 Victor Pos 40 7 7 Faye Neg 26 8 8 Faye Neu 12 9 9 Faye Pos 42 10 10 Ron Neg 22 11 11 Ron Neu 10 12 12 Ron Pos 38 13 13 Jason Neg 29 14 14 Jason Neu 8 15 15 Jason Pos 35 aov.ex3 = aov(Recall~Valence+Error(Subject/Valence),data.ex3) summary(aov.ex3) Error: Subject Df Sum Sq Mean Sq F value Pr(F) Residuals 4 105.067 26.267 Error: Subject:Valence Df Sum Sq Mean Sq F value Pr(F) Valence 2 2029.73 1014.87 189.11 1.841e-07 *** Residuals 8 42.93 5.37 --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 print(model.tables(aov.ex3,means),digits=3) #report the means and the number of subjects/cell Tables of means Grand mean 26.46667 Valence Valence Neg Neu Pos 27.8 11.6 40.0 The analysis of between-subjects factors will appear first (there are none in this case), followed by the within-subjects factors. Note that the p value for Valence is displayed in exponential notation; this occurs when the p value is extremely low, as it is in this case (approximately .00000018). Two-way Within Subjects ANOVA Example 4. Two-Way Within-Subjects ANOVA Appendix IV contains the data from an experiment where five subjects were tested on their recall of words of differing valences. There were two different memory tasks: free or cued recall. Thus, there were 2 independent factors: Valence (3 levels) and Task (2 levels). Again, Subject serves as a random factor. Enter the data into a file entitled ex4 and run the following analysis: In this example, Subject is crossed with both Task and Valence , so you must specify three different error terms: one forTask , one for Valence and one for the interaction between the two. Fortunately, R is smart enough to divide up the within-subjects error term properly as long as you specify it in your command. The commands are: datafilename=http://personality-project.org/r/datasets/R.appendix4.data data.ex4=read.table(datafilename,header=T) #read the data into a table data.ex4 #show the data aov.ex4=aov(Recall~(Task*Valence)+Error(Subject/(Task*Valence)),data.ex4 ) summary(aov.ex4) print(model.tables(aov.ex4,means),digits=3) #report the means and the number of subjects/cell boxplot(Recall~Task*Valence,data=data.ex4) #graphical summary of means of the 6 cells results in the following output datafilename=http://personality-project.org/r/datasets/R.appendix4.data data.example4=read.table(datafilename,header=T) #read the data into a table data.example4 #show the data Observation Subject Task Valence Recall 1 1 Jim Free Neg 8 2 2 Jim Free Neu 9 3 3 Jim Free Pos 5 4 4 Jim Cued Neg 7 5 5 Jim Cued Neu 9 6 6 Jim Cued Pos 10 7 7 Victor Free Neg 12 8 8 Victor Free Neu 13 9 9 Victor Free Pos 14 10 10 Victor Cued Neg 16 11 11 Victor Cued Neu 13 12 12 Victor Cued Pos 14 13 13 Faye Free Neg 13 14 14 Faye Free Neu 13 15 15 Faye Free Pos 12 16 16 Faye Cued Neg 15 17 17 Faye Cued Neu 16 18 18 Faye Cued Pos 14 19 19 Ron Free Neg 12 20 20 Ron Free Neu 14 21 21 Ron Free Pos 15 22 22 Ron Cued Neg 17 23 23 Ron Cued Neu 18 24 24 Ron Cued Pos 20 25 25 Jason Free Neg 6 26 26 Jason Free Neu 7 27 27 Jason Free Pos 9 28 28 Jason Cued Neg 4 29 29 Jason Cued Neu 9 30 30 Jason Cued Pos 10 aov.ex4=aov(Recall~(Task*Valence)+Error(Subject/(Task*Valence)),data.example4 ) summary(aov.ex4) Error: Subject Df Sum Sq Mean Sq F value Pr(F) Residuals 4 349.13 87.28 Error: Subject:Task Df Sum Sq Mean Sq F value Pr(F) Task 1 30.0000 30.0000 7.3469 0.05351 . Residuals 4 16.3333 4.0833 --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 Error: Subject:Valence Df Sum Sq Mean Sq F value Pr(F) Valence 2 9.8000 4.9000 1.4591 0.2883 Residuals 8 26.8667 3.3583 Error: Subject:Task:Valence Df Sum Sq Mean Sq F value Pr(F) Task:Valence 2 1.4000 0.7000 0.2907 0.7553 Residuals 8 19.2667 2.4083 print(model.tables(aov.ex4,means),digits=3) #report the means and the number of subjects/cell Tables of means Grand mean 11.8 Task Cued Free 12.8 10.8 rep 15.0 15.0 Valence Neg Neu Pos 11 12.1 12.3 rep 10 10.0 10.0 Task:Valence Valence Task Neg Neu Pos Cued 11.8 13.0 13.6 rep 5.0 5.0 5.0 Free 10.2 11.2 11.0 rep 5.0 5.0 5.0 ------------------------------------------------------------- # Note 这里用的模型是: aov.ex4=aov(Recall~(Task*Valence)+Error(Subject/(Task*Valence)),data.example4 ) 而上篇博文中用的是: aov.out = aov(SSS ~ diet * test + Error(subject/test), data=hill) http://blog.sciencenet.cn/home.php?mod=spaceuid=285393do=blogid=672361 区别在与第一个模型中,两个变量都基于重复测量。即每个个体都经历过各种组合的处理。 而第二个模型中,一部分个体经过diet中的 chicken ,而另一部分个体经过diet中的 chicken 的 pasta , 所以diet不是within变量。
2484 次阅读|0 个评论
[转载]Repeated measures ANOVA with R
ljxue 2013-3-13 10:05
http://www.r-statistics.com/2010/04/repeated-measures-anova-with-r-tutorials/ Repeated measures ANOVA is a common task for the data analyst. There are (at least) two ways of performing “repeated measures ANOVA” using R but none is really trivial, and each way has it’s own complication/pitfalls (explanation/solution to which I was usually able to find through searching in the R-help mailing list). So for future reference, I am starting this page to document links I find to tutorials, explanations (and troubleshooting) of “repeated measure ANOVA” done with R Functions and packages (I suggest using the tutorials supplied bellow for how to use these functions) aov {stats} – offers SS type I repeated measures anova, by a call to lm for each stratum. A short example is given in the ?aov help file Anova { car } – Calculates type-II or type-III analysis-of-variance tables for model objects produced by lm, and for various other object. The ?Anova help file offers an example for how to use this for repeated measures ezANOVA { ez } – This function provides easy analysis of data from factorial experiments, including purely within-Ss designs (a.k.a. “repeated measures”), purely between-Ss designs, and mixed within-and-between-Ss designs, yielding ANOVA results and assumption checks. It is a wrapper of the Anova {car} function, and is easier to use. The ez package also offers the functions ezPlot and ezStats to give plot and statistics of the ANOVA analysis. The ?ezANOVA help file gives a good demonstration for the functions use (My thanks goes to Matthew Finkbe for letting me know about this cool package) friedman.test {stats} – Performs a Friedman rank sum test with unreplicated blocked data. That is, a non-parametric one-way repeated measures anova. I also wrote a wrapper function to perform and plot a post-hoc analysis on the friedman test results Non parametric multi way repeated measures anova – I believe such a function could be developed based on the Proportional Odds Model, maybe using the {repolr} or the {ordinal} packages. But I still didn’t come across any function that implements these models (if you do – please let me know in the comments). Repeated measures, non-parametric, multivariate analysis of variance – as far as I know, such a method is not currently available in R. There is, however, the Analysis of similarities (ANOSIM) analysis which provides a way to test statistically whether there is a significantdifference between two or more groups of sampling units. Is is available in the { vegan } package through the “anosim” function. There is also a tutorial and a relevant published paper . Good Tutorials A basic tutorial about ANOVA with R (only the last bit holds some example of repeated measures) on personality-project A thorough tutorial on motor control lab A thorough tutorial on UCLA seminar page Another good tutorial by Jonathan Baron and Yuelin Li on “Notes on the use of R for psychology experiments and questionnaires” Troubelshooting Unbalanced design Unbalanced design doesn’t work when doing repeated measures ANOVA with aov, it just doesn’t. This situation occurs if there are missing values in the data or that the data is not from a fully balanced design. The way this will show up in your output is that you will see the between subject section showing withing subject variables. A solution for this might be to use the Anova function from library car with parameter type=”III”. But before doing that, first make sure you understand the difference between SS type I, II and III. Here is a good tutorial for helping you out with that. By the way, these links are also useful in case you want to do a simple two way ANOVA for unbalanced design I will “later” add R-help mailing list discussions that I found helpful on the subject. If you come across good resources, please let me know about them in the comments.
个人分类: Bioinformatics|4868 次阅读|0 个评论
重复测量方差分析SPSS处理
热度 3 bnuzgy 2012-8-21 22:12
重复测量资料(repeated measurement data)是指同一受试对象的同一观察指标在不同时间点上进行多次测量所得的资料,常用来分析该观察指标在不同时间点上的变化特点。 举例(注:此例子为不等距重复测量): 为了解某药物对某种疾病模型大鼠的体重影响,将20只Wistar大鼠随机分成3组,阴性对照组(7只)、正常对照组(6只)和待测药物组(7只)。阴性对照组,造模14天后肌注生理盐水;正常对照组,14天后肌注生理盐水;待测药物组,造模14天后肌注待测药物,连续给药8天。分别记录造模后第10、15、20、24天的大鼠体重。 SPSS分析步骤:  Analyze→General Linear Model(一般线性模型)→Repeated Measures…→出现Repeated Measures Define Factors对话框,在Within?Subject Factor Name中键入t (重复测量的变量名);在Number of levels中键入4 (重复测量的次数),单击Add→ Define,进入Repeated Measures 主对话框:将t10~t24(代表四次测量结果)调入Within?Subjects Variables(t)框中; group调入Between?Subjects Factor(s) 框中→ Model,进入Repeated Measures :Model对话框,选中Custom(自定义模型),将time调入Within?Subjects Model框(分析4次测量间有无随时间变化的趋势);group调入Between?Subjects Model框,→Build Term(s)菜单中选中 Main effects(只分析主效应) ,单击Continue返回→ Paste,进入SPSS Syntax Editor程序编辑窗口,将/WSFACTOR=t 4 Polynomial 语句修改为/WSFACTOR=t 4 Polynomial (10 15 20 24)→单击Run→ All 。 输出结果: 表2 球形检验结果(略)   表3 组内因素的一元方差分析检验结果(略)   表4 组内因素的多元方差分析检验结果(略)   表5 组间因素的一元方差分析检验结果(略)   表2为SPSS给出的球形检验结果。表3是针对组内因素t及t与组间因素group的交互作用即t * group进行的一元方差分析检验,表中后3行是校正后的结果(校正系数Epsilon)。表4是针对t和t* group进行的多元方差分析检验,SPSS对此具体采用了4种多元检验方法,一般以Pillai's Trace结果为准。表5是组间因素group的检验结果。   此例中球形检验结果χ2=23.574, P0.05,数据不符合Huynh?Feldt条件,不满足球形假设,说明重复测量的数据间高度相关,应以多元检验结果为准[2] ,即表4第1行的数据。同时可参考校正后的一元方差分析结果,多推荐Greenhouse?Geisser的校正结果,即表3第2行的数据。   若数据满足球形假设,则说明重复测量的数据间实际上不存在相关性,可直接进行一元方差分析,无需校正,应采用表3第1行的数据。 各组资料在不同时间点上的差别   在不同处理组与不同时间上的差别均有统计学意义时,可进一步进行两两比较,本例就属此种情况。SPSS中的操作步骤如下:Analyze→Multivariate(多元方差分析模型)→向Dependent variablesk框中调入t10~t24;Fixed factors中调入group,单击Continue→ Model,选中Custom,将group调入Model框,Build Term(s)菜单中选中 Main effects,单击Continue →单击Post Hoc,在Post Hoc Tests for 框中调入group,选中LSD(两两比较方法的选择原则与单因素方差分析一致),单击Continue →单击Options,在Display means for框中调入 group,选中Disply Descriptive statistics(输出对数据的统计描述)单击Continue→OK。 在对重复测量资料进行分析时要注意下面几点:①球形检验之后,若p0.05, 说明重复测量数据之间不存在相关性,满足Huynh-Feldt条件,可以使用重复测量资料的单变量方差分析。若p0.05,说明不满足Huynh-Feldt条件,需要对组内效应进行校正,校正系数为Epsilon而组间效应无需校正;②不等距重复测量资料在SPSS中不能直接利用菜单完成,可利用Paste按钮和Syntax Editor程序编辑窗口;③重复测量资料的结果较复杂,在给出解释时要慎重。 参考文献 丛珊,李凡. 医学研究中不等距重复测量资料的分析及在SPSS16.0中的实现.
49023 次阅读|6 个评论

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-23 13:36

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部