Hi everyone, I have a question about calculating r-squared in R. I have tried searching the archives and couldn't find what I was looking for - but apologies if there is somewhere I can find this... I carried out a droughting experiment to test plant competition under limited water. I had: - 7 different levels of watering treatment (1 -7 - from most watered to least watered/) - 15 replicates at each level. Soil moisture readings were taken 4 times throughout the experiment (so I have 105 readings for each of the 4 times) and I now want to check that there was a significant decrease in soil moisture as I decreased the watering frequency, i.e. watering level 7 showed lower soil moisture units than level 1. I have carried out a repeated measures anova as follows (where block is which time the reading was taken: 1,2,3 or 4): model1<-aov(soilmoisture~wateringlevel+Error(block/wateringlevel)) I then plotted (soilmoisture~wateringlevel) and fitted a regression line: lm1<-lm(soilmoisture~wateringlevel) abline(lm1,lty=1) Here are my questions: 1) Is the repeated measures anova I have entered correct to tell me if there is a significant difference in my watering levels? 2) How do I calculate r2 value to show much variation my watering level explains? - and then put this figure on my plot? Thank you - and again apologies if this is a too-basic question - (I am a real stats and R beginner). Please let me know if I need to provide any more detail! Sarah [[alternative HTML version deleted]]
Hi Sarah, On Jul 25, 2009, at 8:25 AM, Buckmaster, Sarah wrote:> Hi everyone, > > I have a question about calculating r-squared in R. I have tried > searching the archives and couldn't find what I was looking for - > but apologies if there is somewhere I can find this... > > I carried out a droughting experiment to test plant competition > under limited water. I had: > - 7 different levels of watering treatment (1 -7 - from most watered > to least watered/) > - 15 replicates at each level. > > Soil moisture readings were taken 4 times throughout the experiment > (so I have 105 readings for each of the 4 times) and I now want to > check that there was a significant decrease in soil moisture as I > decreased the watering frequency, i.e. watering level 7 showed lower > soil moisture units than level 1. > > I have carried out a repeated measures anova as follows (where block > is which time the reading was taken: 1,2,3 or 4): > model1<-aov(soilmoisture~wateringlevel+Error(block/wateringlevel)) > > I then plotted (soilmoisture~wateringlevel) and fitted a regression > line: > lm1<-lm(soilmoisture~wateringlevel) > abline(lm1,lty=1) > > > Here are my questions: > > 1) Is the repeated measures anova I have entered correct to tell me if > there is a significant difference in my watering levels?It seems like using anova here is reasonable -- I haven't used it in R, though, so I can't comment on your *actual* use of it (looks right -- can't u also just call aov on your lm1 object, too?)> 2) How do I calculate r2 value to show much variation my watering > level explains? - and then put this figure on my plot?I think this should be pretty straight forward -- you can find the formula here: http://en.wikipedia.org/wiki/Fraction_of_variance_unexplained and R^2 = SSR / SST (on that page) Using the formulas on that page, translating to R is pretty straight forward. Let's take the example code at the bottom of ?lm help page for reference and calculate the R^2: ssr <- sum((predict(lm.D9, group) - weight)^2) sst <- sum((weight - mean(weight))^2) r2 <- ssr / sst HTH, -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact
Hi Sarah,>From your description it sounds as though you would be best offconsulting with a statistician. Without having a clear understanding of the research hypotheses, experimental units, how randomization was performed, the spatial and temporal structure of the experiment, etc, it's not possible to judge the appropriateness of your multilevel/hierarchical/mixed model. Also, R-squared is not defined from models with random effects (but R-squared-like values can be calculated for specified levels of variation). As for how to add annotation to plots try example(text) #or example(plotmath) hth, Kingsford Jones On Sat, Jul 25, 2009 at 6:25 AM, Buckmaster, Sarah<s.buckmaster.08 at aberdeen.ac.uk> wrote:> Hi everyone, > > I have a question about calculating r-squared in R. I have tried searching the archives and couldn't find what I was looking for - but apologies if there is somewhere I can find this... > > I carried out a droughting experiment to test plant competition under limited water. I had: > ?- 7 different levels of watering treatment (1 -7 - from most watered to least watered/) > - 15 replicates at each level. > > Soil moisture readings were taken 4 times throughout the experiment (so I have 105 readings for each of the 4 times) and I now want to check that there was a significant decrease in soil moisture as I decreased the watering frequency, i.e. watering level 7 showed lower soil moisture units than level 1. > > I have carried out a repeated measures anova as follows (where block is which time the reading was taken: 1,2,3 or 4): > model1<-aov(soilmoisture~wateringlevel+Error(block/wateringlevel)) > > I then plotted (soilmoisture~wateringlevel) and fitted a regression line: > lm1<-lm(soilmoisture~wateringlevel) > abline(lm1,lty=1) > > > Here are my questions: > > 1) Is the repeated measures anova I have entered correct to tell me if > ?there is a significant difference in my watering levels? > > 2) How do I calculate r2 value to show much variation my watering > ?level explains? - and then put this figure on my plot? > > Thank you - and again apologies if this is a too-basic question - (I am a real stats and R beginner). >No need for apologies -- not too basic at all. Mixed/Multilevel/Hierarchical models are tricky. Generally it's not possible to pass judgment about the appropriateness of a model without consulting personally with the experimenter -- is it possible for you to consult with a statistician? If so, some questions that might arise include - For the water effect are you interested in - a regression curve describing the effect? - effects of each watering level? - contrasts between specific levels? - interactions between water effect and e.g., location or time? - What are the experimental units? - How was randomization performed? - Is there hierarchical spatial structure (e.g., plants within plots within blocks)? - Are there spatial trends in the amount of water applied to units?> Please let me know if I need to provide any more detail! > > > > Sarah > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >