R Language-Variance analysis

Source: Internet
Author: User

Variance analysis refers to the interaction of different variables, resulting in a change in results

1. Single-Factor Variance analysis:

Case: 50 patients were treated with cholesterol-lowering medications, of which three were treated with the same drug (20mg a day, 10mg two times a day, 5mg four times), and the remaining two were (Druge and DRUGD), representing the candidate drug

Which drug treatment lowers cholesterol the most?

1 Library (Multcomp)2 Attach (cholesterol)3 #1. Sample sizes for each group4 table (TRT)5 #2. Average value of each group6Aggregate (Response,by=list (TRT), fun=mean)7 #3. Standard deviation for each group8Aggregate (Response,by=list (TRT), fun=SD)9 #4. Differences Between inspection groupsTenFit <-AoV (response ~TRT) One Summary (FIT) A Library (gplots) - #5. Draw each group mean and confidence interval -Plotmeans (response ~ Trt,xlab ='Treatment', Ylab ='Response', main='meanplot\nwith 95% CI') theDetach (cholesterol)

Conclusion:

1. Mean value display druge lower cholesterol, 1time lower cholesterol.

2. Explain the difference between different therapies is very large

Multiple comparisons of drugs and medication times

1 Library (Multcomp) 2 par (mar=c (5,4,6,2))3 tuk <-glht (FIT,LINFCT=MCP (trt='Tukey') ) )4 plot (CLD (tuk,level=.05), col='lightgrey')

Conclusion: It is best to treat cholesterol 4 times a day and when using Druge.

Assumptions for evaluating tests

1 Library (CAR) 2 Qqplot (LM (response ~ trt,data=cholesterol), simulate=t,main='q-q Plot', labels =F)3 bartlett.test (response ~ trt,data=cholesterol)4#  detection Outliers  5 outliertest (FIT)

Conclusion: The data falls within the range of 95% confidence intervals, indicating that the data points satisfy the normality hypothesis

2. Single-Factor covariance analysis

Case: The pregnant mice were divided into 4 groups, each receiving different doses of the drug dose (0.5,50,500) produced by the mouse weight dependent variable, pregnancy time as a co-variable

1Data (Litter,package ='Multcomp')2 Attach (Litter)3 table (Dose)4Aggregate (weight,by=list (dose), fun=mean)5Fit2 <-AoV (weight ~ gesttime +dose)6 Summary (FIT2)7 Library (effects)8 #Take out the covariance to calculate the mean value of the adjustment9Effect'Dose', Fit2)TenContrast <-Rbind ('no drug vs drug'= C (3,-1,-1,-1)) OneSummary (GLHT (FIT2,LINFCT=MCP (dose=contrast ))) A Library (HH) -Ancovaplot (weight ~ gesttime + dose,data=litter)

Conclusion: 0 doses of litter 20, 500 doses of litter 17

0 doses of weight at around 32, 500 doses at around 30

Pregnancy time and weight related

Drug dosage and weight related

 

Conclusion: The weight of mice was proportional to the time of pregnancy and the dosage was inversely

3. Two-Factor variance analysis

Case: Randomly assigned 60 guinea pigs, using two feeding methods (orange juice or vitamin C), various feeding methods contain ascorbic acid 3 (0.5,1,2)

Each treatment combination is allocated 10 guinea pigs, the length of the tooth is the dependent variable

1 Attach (toothgrowth) 2 table (supp,dose) 3 Aggregate (Len,by=list (supp,dose), fun=mean)4 Aggregate (Len,by=list (supp,dose), fun= SD) 5 # convert the dose to a factor variable, so it is not a co-variable 6 Dose <- factor (dose)7 fit3 <-AoV (len ~ supp*dose)8 Summary (FIT3) 9 Detach (toothgrowth)

Conclusion: The main effect on the teeth of guinea pigs is very large

Conclusion: In the interval of 0.5~1mg, the tooth length of the guinea pig in the middle of the region is more than that of orange juice, and in the same interval, when more than 2mg, the effect of both on the teeth of guinea pigs is same.

4. Repeated measurement of variance

Case: Comparison of photosynthesis rates between frigid and non-frigid plants in a certain concentration of CO2 environment

1Co2$conc <-factor (Co2$conc)2W1B1 <-subset (co2,treatment = ='Chilled')3FIT4 <-AoV (uptake ~ conc*type + Error (plant/(Conc)), W1B1)4 Summary (FIT4)5Par (las=2)6Par (Mar=c (10,4,4,2))7With (W1b1,interaction.plot (conc,type,uptake,type='b', Col=c ('Red','Blue'), Pch=c (16,18),8main='Interaction plot for plant type and concentration'))9BoxPlot (Uptake~type*conc,data=w1b1,col=c ('Gold','Green'),TenMain ='Chilled Quebec and Mississippi Plants', Oneylab="Carbon dioxide Uptake rate (umol/m^2 sec)")

Conclusion: The absorption rate of the plants in Quebec is higher than that of Mississippi State carbon dioxide, and with the concentration of CO2, the effect is more obvious.

5. Multivariate Variance Analysis

Case study: Studying the calories, fats, and sugars in American food will vary depending on the shelf.

1 Library (MASS) 2 Attach (Uscereal) 3 Shelf <- factor (shelf)4  y <- cbind (calories,fat,sugars)5  Aggregate (y,by=list (shelf), fun=mean)6  CoV (y)7  fit5 <- Manova (y ~ shelf)8  Summary (FIT5)9  Summary.aov (FIT5)

Find out the outliers.

1Center <-Colmeans (y)2N <-nrow (y)3P <-ncol (y)4CoV <-CoV (y)5D <-Mahalanobis (Y,center,cov)6Coord <-Qqplot (QCHISQ (ppoints (n), df=p), D,7main="QQ Plot Assessing multivariate normality",8ylab="Mahalanobis D2")9Abline (a=0,b=1)TenIdentify (Coord$x,coord$y,labels = Row.names (uscereal))

Conclusion: There are two products that do not conform to the multivariate normal distribution on different shelves of different cereal nutrient components.

1 Library (Rrcov) 2 # Robust multivariate variance analysis 3 wilks.test (y,shelf,method='mcd')

 

Conclusion: Robust detection is insensitive to outliers and violation of Manova, which proves that different grain nutrient compositions in different shelves are concluded

R Language-Variance analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.