R language-Select the number of samples

Source: Internet
Author: User

Efficacy analysis: Can help in the case of a given degree of confidence in the detection of a given effect value of the required sample amount, but also at a given level of confidence in the case of a certain sample amount can be detected in the probability of a given effect value

1.t Inspection

Case study: Experiment using cell phone and driver response time

1 Library (PWR)2 #n indicates sample size3 #d indicates the difference between standardized mean values4 #Sig.level represents a significant level of5 #power for efficacy level6 #Type refers to the test types7 #alternative refers to a two-sided test or a single-sided test.8Pwr.t.test (D=.8,sig.level =. 05,power =. 9,type ='Two.sample', alternative ='two.sided')

Conclusion: A total of 34 samples (68) per group is required to ensure that the 0.8 effect value is detected by 90% and a maximum of 5% is error.

2. Variance analysis

Case: Analysis of 5 groups of data, to achieve 0.8 of the efficacy, the effect is 0.25, select a significant level of 0.5. Calculate the size of the population sample

# k indicates the number of groups # F represents the effect value pwr.anova.test (k=5,f=.25,sig.level =. 05,power =. 8)

Conclusion: It is necessary to 39*5,195 subjects to participate in the experiment in order to obtain the above results

3. Relevance

Case: The relationship between depression and loneliness, 0 hypothesis and study hypothesis for

h0:p<=0.25 and h1:p>0.25

Set a significant level of 0.05, slap rejection 0 hypothesis, want to have 90% of the information rejected H0, how many testers

1 # R indicates the effect value 2 ' Greater ')

Conclusion: 134 subjects were required to participate in the experiment

4. Linear model

Case: The boss's leadership style affects employee satisfaction, salaries and gratuities explain 30% employee satisfaction Variance, leadership style can explain 35% variance,

To reach 90% confidence, the significant level is 0.05, and how many subjects are required to reach the variance contribution rate

F2 = (0.35-0.3)/(1-0.35) =0.0769

1 # u represents molecular degrees of freedom 2 # v represents the denominator degrees of freedom 3 # F2 represents the effect value 4 pwr.f2.test (u=3,f2=0.0769,sig.level =. 05,power =. 90)

Conclusion: v= Overall sample-predictor variable-1, so n=v+7+1=187+7+1=193

5. Proportional inspection

Case: A drug with a 60% cure rate, the new drug has a 65% cure rate, now how many subjects can appreciate the difference between the two drugs

1 ' Greater ')

Conclusion: Using unilateral test in this case, it was concluded that 1605 subjects were required to obtain the difference between the two drugs.

6. Chi-Square inspection

The chi-square test is used to evaluate the relationship between the two variables, 0 is assumed to be independent of the variables, and the reject 0 assumes that the variable is not independent

Case study: The relationship between promotion and race: 70% of the sample was white, 10% Black, 20% Hispanic, and 50% of whites were more likely to get promoted than 20% blacks and 60% Hispanics.

1 prob <-matrix (C (. 42,.28,.03,.07,.10,.10), Byrow = T,nrow = 3)2#  Calculates the effect value of the alternative hypothesis in a two-factor list 3es.w2 (prob)4#  W is the effect value,5#  DF is the degree of Freedom 6 pwr.chisq.test (w=0.1853198,df=2,sig.level =. 05,power =. 90)

Conclusion: This experiment requires 369 testers to prove the association between promotion and race.

7. Select the appropriate effect value in the new case

7.1 Single Factor

1Es <-seq (. 1,.5,.01)2NES <-Length (es)3Samsize <-NULL4  for(Iinch1: NES) {5Result <-pwr.anova.test (k=5,f=es[i],sig.level =. 05,power =. 90)6Samsize[i] <-Ceiling (result$n)7 }8Plot (samsize,es,type='L', lwd='2', col='Red',9Ylab ='Effect Size',TenXlab ='Sample Szie', OneMain ='One- Anova with power=.90 and alpha=.05')

Conclusion: When the number of Ben Ben is higher than 200, the effect is not obvious when the sample is increased

7.2 Drawing Efficiency Analysis diagram

1 #1. Generate a series of correlation coefficients and efficacy values2R <-seq (. 1,.5,.01)3NR <-Length (R)4 5P <-seq (. 4,.9,.1)6NP <-Length (p)7 8 #2. Get Sample size9Samsize <-Array (numeric (NR*NP), Dim =C (NR,NP))Ten  One  for(Iinch1: NP) { A    for(jinch1: NR) { -Result <-pwr.r.test (n=null,r=r[j],sig.level =. 05,power = P[i],alternative ='two.sided') -Samsize[j,i] <-Ceiling (result$n) the   } - } -  - #3. Create a graphic +Xrange <-Range (r) -Yrange <-Round (range (samsize)) +Colors <-Rainbow (Length (p)) APlot (xrange,yrange,type='N', atXlab ='corrlation coefficient', -Ylab ='Sample Size') - #4. Add Efficiency curve -  for(Iinch1: NP) { -Lines (r,samsize[,i],type='L', lwd=2,col=Colors[i]) - } in #5. Grid lines -Abline (V=0,h=seq (0,yrange[2],50), lty=2,col='grey89') toAbline (H=0,v=seq (xrange[1],xrange[2],.02), lty=2,col='grey89') + #6. Title and Notes -Title'Sample Size estimation for corrlation\nsig=0.05') theLegend'TopRight', title ='Power', As.character (P), fill=colors)

Conclusion: At 40% confidence level, it is necessary to detect that 0.2 of the correlation requires about 75 samples, and at 90% confidence level, it takes about 260 samples to detect the same correlation.

R language-Select the number of samples

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.