+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 15 of 41

Thread: [R] Between subjects repeated measures ANOVA help. Level: Novice.

  1. #1
    Points: 134, Level: 2
    Level completed: 68%, Points required for next Level: 16

    Posts
    19
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Post [R] Between subjects repeated measures ANOVA help. Level: Novice.




    Dear community,

    I am fairly new to the field of statistics and R and I apologise if my problem seems to be too basic.

    In my research I have performed a series of measurements on 5 different brands of blocks. Each block has been inspected for deformation under incremental forces (20, 30, 40, 50, 60, 70, 80, 90, 100, 110 and 120 N). The deformation for each force was measured 3 times and the mean values were assigned to each brand for a specific amount of force. I was successful in creating linear regression graphs for these 5 different brands.

    Now my wish is to see whether a brand makes a significant difference in deformation values and to perform a post-hoc to compare brands among themselves. In other words to compare the linear regression lines. Sorry if what I am saying makes no sense.

    So far, I have tried the following commands:

    anova(lm(Deformation~Force*Brand, data=Data), lm(Deformation~Force, data=Data))


    and

    aov.data = aov(Deformation~Force*Brand, Data)

    and gotten suspiciously low P values (***) which clearly indicates that I might be doing something wrong. I would be grateful if you could help me with this issue.



    Force Brand Deformation
    20 Brand1 0.65
    30 Brand1 1.23
    40 Brand1 1.25
    50 Brand1 2.39
    60 Brand1 2.45
    70 Brand1 2.93
    80 Brand1 3.13
    90 Brand1 3.57
    100 Brand1 4.68
    110 Brand1 4.84
    120 Brand1 5.33
    20 Brand2 1.24
    30 Brand2 1.11
    40 Brand2 1.6
    50 Brand2 2.13
    60 Brand2 2.69
    70 Brand2 3.60
    80 Brand2 3.90
    90 Brand2 3.99
    100 Brand2 4.51
    110 Brand2 4.74
    120 Brand2 5.98
    20 Brand3 1.21
    30 Brand3 1.37
    40 Brand3 2.56
    50 Brand3 2.49
    60 Brand3 3.17
    70 Brand3 3.33
    80 Brand3 3.38
    90 Brand3 4.2
    100 Brand3 4.22
    110 Brand3 5.22
    120 Brand3 6.28
    20 Brand4 0.92
    30 Brand4 0.89
    40 Brand4 1.2
    50 Brand4 1.67
    60 Brand4 1.98
    70 Brand4 2.25
    80 Brand4 3.8
    90 Brand4 4.17
    100 Brand4 4.94
    110 Brand4 5.4
    120 Brand4 5.76
    20 Brand5 0.69
    30 Brand5 1.26
    40 Brand5 1.61
    50 Brand5 2.17
    60 Brand5 2.07
    70 Brand5 3.35
    80 Brand5 3.27
    90 Brand5 4.13
    100 Brand5 4.25
    110 Brand5 4.59
    120 Brand5 5

    Thank you.

  2. #2
    ggplot2orBust
    Points: 71,220, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,417
    Thanks
    1,811
    Thanked 928 Times in 809 Posts

    Re: [R] Between subjects repeated measures ANOVA help. Level: Novice.

    I'd check out the ez.anova function from the ez package for R. What you have done appears to be hierarchical linear regression (block wise testing) and haven't taken care of the nonindependent error terms. Also andy field has en excellent R book that covers this type of testing in a very approachable way within the R program.
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  3. The Following User Says Thank You to trinker For This Useful Post:

    pickle (02-18-2013)

  4. #3
    Points: 134, Level: 2
    Level completed: 68%, Points required for next Level: 16

    Posts
    19
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Talking Re: [R] Between subjects repeated measures ANOVA help. Level: Novice.

    Thank you, I will check it out. Any chance you could help me out with the code?

  5. #4
    Human
    Points: 12,676, Level: 73
    Level completed: 57%, Points required for next Level: 174
    Awards:
    Master Tagger
    GretaGarbo's Avatar
    Posts
    1,362
    Thanks
    455
    Thanked 462 Times in 402 Posts

    Re: [R] Between subjects repeated measures ANOVA help. Level: Novice.

    I don't think this problem seems “too basic”, on the contrary for me.

    When you have a p-value that is really low, it simply means that something is significant.

    There is a statistical significant difference between brands p=0.011<0.05, so it is significant at the 5% level. And force is significant with p-value=2*10^-16 which is clearly less than 0.05.

    And “blah blah” there is just one replicate per cell so interactions can not be estimated and tested.

    Maybe there are some hierarchical structures here. But for the moment I just assume that it was a completely randomized experiment. I am not sure if I am familiar with the model structure trinker suggest. Suggestions about models and evaluation, anybody?


    Code: 
    dat <-  read.table(header=TRUE, text="
    Force  Brand	Deformation
    20	Brand1	0.65
    30	Brand1	1.23
    40	Brand1	1.25
    50	Brand1	2.39
    60	Brand1	2.45
    70	Brand1	2.93
    80	Brand1	3.13
    90	Brand1	3.57
    100	Brand1	4.68
    110	Brand1	4.84
    120	Brand1	5.33
    20	Brand2	1.24
    30	Brand2	1.11
    40	Brand2	1.6
    50	Brand2	2.13
    60	Brand2	2.69
    70	Brand2	3.60
    80	Brand2	3.90
    90	Brand2	3.99
    100	Brand2	4.51
    110	Brand2	4.74
    120	Brand2	5.98
    20	Brand3	1.21
    30	Brand3	1.37
    40	Brand3	2.56
    50	Brand3	2.49
    60	Brand3	3.17
    70	Brand3	3.33
    80	Brand3	3.38
    90	Brand3	4.2
    100	Brand3	4.22
    110	Brand3	5.22
    120	Brand3	6.28
    20	Brand4	0.92
    30	Brand4	0.89
    40	Brand4	1.2
    50	Brand4	1.67
    60	Brand4	1.98
    70	Brand4	2.25
    80	Brand4	3.8
    90	Brand4	4.17
    100	Brand4	4.94
    110	Brand4	5.4
    120	Brand4	5.76
    20	Brand5	0.69
    30	Brand5	1.26
    40	Brand5	1.61
    50	Brand5	2.17
    60	Brand5	2.07
    70	Brand5	3.35
    80	Brand5	3.27
    90	Brand5	4.13
    100	Brand5	4.25
    110	Brand5	4.59
    120	Brand5	5")
    
    
    
    
    dat$brand.f <- as.factor(dat$Brand)
    dat$force.f <- as.factor(dat$Force)
    
    head(dat)
    
    table(dat$brand.f,dat$force.f)
    
    summary(lm( Deformation ~ brand.f + force.f +brand.f:force.f ,dat))
    # the interaction brand.f:force.f can not be estimated because only one replicate blah blah
    
    summary(lm( Deformation ~ brand.f + force.f  ,dat))
      anova(lm( Deformation ~ brand.f + force.f  ,dat))
    
    
    boxplot(Deformation~ force.f,data=dat)
    boxplot(Deformation~ brand.f,data=dat)
    
    #with force as a co-variate below
    summary(lm( Deformation ~ brand.f + Force  ,dat))
    
    plot(Deformation ~ Force , pch=as.numeric(dat$brand.f)   , data=dat)
    
    
    #I will leave the rest to the rest of you for regression diagnostics and so on.
    #####################################################################


    I will leave the rest, to the rest of you for regression diagnostics and so on.

  6. The Following User Says Thank You to GretaGarbo For This Useful Post:

    pickle (02-18-2013)

  7. #5
    ggplot2orBust
    Points: 71,220, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,417
    Thanks
    1,811
    Thanked 928 Times in 809 Posts

    Re: [R] Between subjects repeated measures ANOVA help. Level: Novice.

    @Greta does your syntax address the repeated measures?
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  8. #6
    Human
    Points: 12,676, Level: 73
    Level completed: 57%, Points required for next Level: 174
    Awards:
    Master Tagger
    GretaGarbo's Avatar
    Posts
    1,362
    Thanks
    455
    Thanked 462 Times in 402 Posts

    Re: [R] Between subjects repeated measures ANOVA help. Level: Novice.

    @trinker! What repeated measure? Where do you see that?

    The OP has averaged over three measurements and shown us that average. Then the repeated measures has disappeared.

    In my reading!

  9. #7
    Cookie Scientist
    Points: 13,431, Level: 75
    Level completed: 46%, Points required for next Level: 219
    Jake's Avatar
    Location
    Austin, TX
    Posts
    1,293
    Thanks
    66
    Thanked 584 Times in 438 Posts

    Re: [R] Between subjects repeated measures ANOVA help. Level: Novice.

    I agree with Greta, this is not a repeated measures problem unless Brand is considered to be a random factor (in which case we would have repeated measurements on each random unit, which is what is classically considered a "repeated measures" situation). Since I assume we are not considering Brands to be random here, this analysis seems as straightforward as Greta indicated.
    “In God we trust. All others must bring data.”
    ~W. Edwards Deming

  10. The Following User Says Thank You to Jake For This Useful Post:

    pickle (02-18-2013)

  11. #8
    ggplot2orBust
    Points: 71,220, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,417
    Thanks
    1,811
    Thanked 928 Times in 809 Posts

    Re: [R] Between subjects repeated measures ANOVA help. Level: Novice.

    gotcha you are correct.
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  12. #9
    Points: 134, Level: 2
    Level completed: 68%, Points required for next Level: 16

    Posts
    19
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: [R] Between subjects repeated measures ANOVA help. Level: Novice.

    Dear repliers,

    I may have addressed my problem in a wrong way. By repeated measures I meant different forces (20 N, 30 N, 40 N,...) I wanted to compare deformations over the whole series 20 N - 120 N for different brands so that I can say: "brand has a significant influence on deformation in the whole 20 N to 120 N measurement series"; and "Brand2 showed the least deformation, Brand5 showed the most deformation" throughout measurements.

    I want to see if brand influences regression lines significantly.

    Once more, I am sorry if I said something utterly stupid.

  13. #10
    Human
    Points: 12,676, Level: 73
    Level completed: 57%, Points required for next Level: 174
    Awards:
    Master Tagger
    GretaGarbo's Avatar
    Posts
    1,362
    Thanks
    455
    Thanked 462 Times in 402 Posts

    Re: [R] Between subjects repeated measures ANOVA help. Level: Novice.

    @Pickle! Didn't you read and run the code I supplied above?

    For others: Is there anybody who wish to go on with the regression diagnostics, if assumptions are met and so on?

    (And it is an utterly natural question.)

  14. The Following User Says Thank You to GretaGarbo For This Useful Post:

    pickle (02-18-2013)

  15. #11
    Points: 134, Level: 2
    Level completed: 68%, Points required for next Level: 16

    Posts
    19
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: [R] Between subjects repeated measures ANOVA help. Level: Novice.

    Thank you Greta for the code, I will run it in about 2 hours when I get home from work. This is my doctoral thesis that I am working on, your help is greatly appreciated. I wish I could buy you a dinner or something for doing this

    I hope I can ask you for further assistance when I run the code. Unfortunately, my biomedical background makes me an idiot for statistics.

  16. #12
    Points: 134, Level: 2
    Level completed: 68%, Points required for next Level: 16

    Posts
    19
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: [R] Between subjects repeated measures ANOVA help. Level: Novice.

    I have run the code and am very pleased with the outcome. However, I still have things that remained unclear.
    Let me see if I got this well. This is the ANOVA table:

    Code: 
    Analysis of Variance Table
    
    Response: Deformation
              Df  Sum Sq Mean Sq  F value  Pr(>F)    
    brand.f    4   1.810  0.4525   3.7116 0.01162 *  
    force.f   10 124.076 12.4076 101.7711 < 2e-16 ***
    Residuals 40   4.877  0.1219                     
    ---
    Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    So basically brand.f Pr(>F) 0.01162 means that P is 0.01162, which is <.05 and statistically significant. The force significance is something I am not interested in, because it obviously influences deformation. What do residuals mean?

    My second question regards summary( lm (Deformation ~ brand.f + force.f , dat)), which gives me this table:

    Code: 
    Residuals:
         Min       1Q   Median       3Q      Max 
    -0.73582 -0.18482 -0.03636  0.23009  0.61764 
    
    Coefficients:
                   Estimate Std. Error t value Pr(>|t|)    
    (Intercept)    0.787636   0.182346   4.319  0.00010 ***
    brand.fBrand2  0.276364   0.148885   1.856  0.07080 .  
    brand.fBrand3  0.452727   0.148885   3.041  0.00415 ** 
    brand.fBrand4  0.048182   0.148885   0.324  0.74791    
    brand.fBrand5 -0.005455   0.148885  -0.037  0.97096    
    force.f30      0.230000   0.220832   1.042  0.30389    
    force.f40      0.702000   0.220832   3.179  0.00285 ** 
    force.f50      1.228000   0.220832   5.561 1.96e-06 ***
    force.f60      1.530000   0.220832   6.928 2.36e-08 ***
    force.f70      2.150000   0.220832   9.736 4.15e-12 ***
    force.f80      2.554000   0.220832  11.565 2.48e-14 ***
    force.f90      3.070000   0.220832  13.902  < 2e-16 ***
    force.f100     3.578000   0.220832  16.202  < 2e-16 ***
    force.f110     4.016000   0.220832  18.186  < 2e-16 ***
    force.f120     4.728000   0.220832  21.410  < 2e-16 ***
    ---
    Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
    
    Residual standard error: 0.3492 on 40 degrees of freedom
    Multiple R-squared: 0.9627,     Adjusted R-squared: 0.9497 
    F-statistic: 73.75 on 14 and 40 DF,  p-value: < 2.2e-16
    This table is rather puzzling. What does it mean? Why is Brand1 not listed at all?
    Last edited by pickle; 02-19-2013 at 01:26 PM. Reason: Added a question

  17. #13
    Human
    Points: 12,676, Level: 73
    Level completed: 57%, Points required for next Level: 174
    Awards:
    Master Tagger
    GretaGarbo's Avatar
    Posts
    1,362
    Thanks
    455
    Thanked 462 Times in 402 Posts

    Re: [R] Between subjects repeated measures ANOVA help. Level: Novice.

    I am glad that you are not working for the KGB or the CIA, in that you dare to show us your data. Most posters here seems to deal with government secrets in that they don't dare to even show a small example of their data. Then it is difficult to suggest or advice.

    What kind of material is it that is deformed?

    If you Edit your above post with the computer printout and highlight it and click on the #-symbol (the code symbol) I believe that it will be easier to read (in courier new) in straight columns.

    If you are not familiar with “residuals” you need to study linear regression more. Look at any elementary text book and search the web. Essentially it is the observed value – predicted value.


    The Brand 1 and the lowest level of force is not included as separate estimates because they are included in the “intercept”. So they act as reference values. (Look around. That has been discussed here at the forum the last days.)

    Did you randomize the experiment and in particular the order of the 5*11=55 experiments?
    (And did you use formally random numbers?)


    Is there anybody who want to do the check on residuals and so on on this model (where the variables are created in the code above)?

    Code: 
    summary(lm( Deformation ~ brand.f + force.f  ,dat))

  18. The Following 2 Users Say Thank You to GretaGarbo For This Useful Post:

    Lazar (02-18-2013), pickle (02-19-2013)

  19. #14
    Phineas Packard
    Points: 16,013, Level: 81
    Level completed: 33%, Points required for next Level: 337
    Lazar's Avatar
    Location
    Sydney
    Posts
    1,159
    Thanks
    198
    Thanked 336 Times in 299 Posts

    Re: [R] Between subjects repeated measures ANOVA help. Level: Novice.

    This:
    I am glad that you are not working for the KGB or the CIA, in that you dare to show us your data. Most posters here seems to deal with government secrets in that they don't dare to even show a small example of their data. Then it is difficult to suggest or advice.
    Thanks Greta!!

  20. #15
    ggplot2orBust
    Points: 71,220, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,417
    Thanks
    1,811
    Thanked 928 Times in 809 Posts

    Re: [R] Between subjects repeated measures ANOVA help. Level: Novice.


    When you're posting code, dataframes or computer output it's helpful to wrap this information in code tags by:
    1. either clicking the pound (#) sign icon or
    2. wrap with [CODE]some code[/CODE]

    which produces:
    Code: 
    some code
    For more see this (LINK)
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  21. The Following User Says Thank You to trinker For This Useful Post:

    pickle (02-19-2013)

+ Reply to Thread
Page 1 of 3 1 2 3 LastLast

           




Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts






Advertise on Talk Stats