R in Action reading notes (13) Tenth chapter efficacy analysis

Source: Internet
Author: User

Efficacy analysis

Efficacy analysis helps to determine the amount of sample required to detect a given effect value in a given confidence level. In turn, it can also help you calculate the probability that a given effect value can be detected in a sample volume at a given level of confidence. If the probability is unacceptably low, modifying or abandoning the experiment would be a wise choice.

10.1 Quick Facts on hypothesis testing

In the research process, researchers usually focus on four volumes: sample size, significance level, efficacy, and effect values. The sample size refers to the number of observations in each condition/group in the experimental design. The level of significance (also known as Alpha) is defined by the probability of the I-type error. It can also be seen as the probability that the effect does not occur. The effect is defined by the probability of 1 minus type II errors. We can think of it as the probability of the real effect happening. The effect value refers to the amount of the effect in the alternative or research hypothesis. The expression of an effect value depends on the statistical method used in the hypothesis test.

10.2 Using PWR Package for efficacy analysis

Letter Number of power calculation objects

Pwr.2p.test () two ratio (n equal)

Pwr.2p2n.test () two scale (n unequal)

Pwr.anova.test () Balanced single factor anova

Pwr.chisq.test () Chi-square test

Pwr.f2.test () Generalized linear model

Pwr.p.test () scale (single sample)

Pwr.r.test () correlation coefficients

Pwr.t.test () t Test (single sample, two samples, paired)

Pwr.t2n.test () t Test (n unequal two copies)

10.2.1 T Test

For the T-Test, the Pwr.t.test () function provides a number of useful analysis options in the form of:

function (n = null, d = null, Sig.level = 0.05, power = null,

Type = C ("Two.sample", "One.sample", "paired"), Alternative =c ("two.sided", "less", "greater"))

n is the sample size.

D is the effect value, which is the difference between the normalized mean value. d = (m1-m2)/s

Sig.level represents a significant level (default is 0.05).

Power is the potency level.

Type refers to the test types: A two-sample T-Test (Two.sample), a single-sample T-Test (One.sample), or a dependent sample T-Test (paired). The default is a two-sample T-Test.

Alternative means that the statistical test is either a bilateral test (two.sided) or a single-sided test (less or greater). The default is a two-sided test.

>Library(PWR)

>pwr.t.test(d=. 8,sig.level=. 05,power=. 9,type=" Two.sample ", Alternative=" two.sided ")

Double-samplet test power calculation

n =33.82554

D =0.8

Sig.level =0.05

Power=0.9

Alternative = two.sided

Note: n is number in*each* Group

10.2.2 Variance Analysis

The Pwr.anova.test () function can analyze the effect of a balanced univariate ANOVA. The format is:

function (k = NULL, n = null, F = null, Sig.level =0.05, power = null) where k is the number of groups, n is the sample size in each group

For single-factor variance analysis, the effect value can be measured by f:

wherein, PI = ni/n,

NI = number of observations in Group I

N = Total number of observations

Μi

= Group I mean

μ= overall mean value

σ2 = intra-group error variance

> Pwr.anova.test (k=5,f=.25,sig.level=.05,power=.8)

Balancedone-way Analysis of variance power calculation

k= 5 #结果表明 with a total sample size of 5x39, or 195

n= 39.1534

f= 0.25

Sig.level= 0.05

power= 0.8

Note:n is number in each group

10.2.3 Correlation

The Pwr.r.test () function can analyze the correlation analysis

n is the number of observations, R is the value of the effect (measured by the linear correlation coefficient), the sig.level is the significant level, and power is the function

Alternative to specify whether the significance test is a bilateral test (tow.sided) or a unilateral test (less or greater).

>pwr.r.test (r=.25,sig.level=.05,power=.90,alternative= "greater")

Approximate correlation power calculation (Arctangh transformation)

n= 133.2803

R= 0.25

Sig.level= 0.05

Power= 0.9

alternative= Greater

10.2.4 Linear Model

For linear models (such as multivariate regression), the pwr.f2.test () function can perform the corresponding efficacy analysis in the following format:

function (U = null, v = NULL, F2 = null, Sig.level = 0.05, power = null), and U and V respectively are molecular degrees of freedom and denominator degrees of freedom, F2 is the effect value.

When evaluating the effect of a set of predictors on the results, it is appropriate to use the first formula to calculate the F2; It is advisable to use the second formula when evaluating the effect of a set of predictors over the result of a second set of variables (covariance).

> Pwr.f2.test (u=3,f2=.0769,sig.level=.05,power=.90)
     
              U = 3
              v = 184.2426
             F2 = 0.0769
      Sig.level = 0.05
          Power = 0.9

In multivariate regression, the degree of freedom of the denominator equals n-k-1,n is the total number of observations, and K is the number of predictor variables. In this example, N-7

-1 = 185, which requires sample size n = 185 + 7 + 1 = 193.

10.2.5 ratio test

When comparing two scales, the pwr.2p.test () function can be used for efficacy analysis. The format is:

    

Where h is the effect value, n is the same sample size for each group. The effect value h is defined as follows:

The ES.h (P1, p2) function can be used for calculations.

When n is not the same in each group, the function is used:

 
  
> Pwr.2p.test (h=es.h (. 65,.6), sig.level=.05,power=.9,alternative= "greater")
     
              H = 0.1033347
              n = 1604.007
      Sig.level = 0.05
          Power = 0.9
    Alternative = Greater
Note:same Sample Sizes

10.2.6 Chi-Square inspection

The Pwr.chisq.test () function evaluates the effectiveness of chi-square test, the effect value, and the desired sample size. The format is:

Where w is the effect value, n is the total sample size, and DF is the degree of freedom. Here, the effect value w is defined as follows:

p0i = probability in cell I of H0

p1i = probability in cell I of H1

> Prob<-matrix (C (. 42,.28,.03,.07,.10,.10), byrow=true,nrow=3)
> es.w2 (Prob)
[1] 0.1853198
> Pwr.chisq.test (w=.1853198,df=2,sig.level=.05,power=.9)
     
              W = 0.1853198
              N = 368.4529
             DF = 2
      Sig.level = 0.05
          Power = 0.9
Note:n is the number of observations

10.2.7 selecting the appropriate effect value in the new case

In efficacy analysis, the expected effect value is the most difficult parameter to determine.

Sample size required to detect significant effects in single-factor ANOVA

> Library (PWR)
> Es<-seq (. 1,.5,.01)
> Nes<-length (es)
> Samsize<-null
> for (i in 1:nes) {
+ result<-pwr.anova.test (k=5,f=es[i],sig.level=.05,power=.9)
+ samsize[i]<-ceiling (result$n)
+ }
> Plot (samsize,es,type= "L", lwd=2,col= "Red",
+ ylab= "effect size",
+ xlab= "Sample size (per cell)",
+ main= "one-Anova with power=.90 and alpha=.05")

10.3 Drawing Efficacy Analysis Graphics

Assuming the statistical significance of the correlation coefficient of the test, the calculation of a series of effects and efficacy level of the required sample amount, at this time can be used pwr.r.test () function and for loop to complete the task to test the correlation of various effect values of the required sample size curve

Library (PWR)

R<-seq (. 1,.5,.01)

Nr<-length (R)

P<-seq (. 4,.9,.1)

Np<-length (P)

Samsize<-array (Numeric (NR*NP), Dim=c (NR,NP))

For (i in 1:NP) {

For (j in 1: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)

}

Xrange<-range (R)

Yrange<-round (range (samsize))

Colors<-rainbow (Length (p))

Plot (xrange,yrange,type= "n",

Xlab= "Correlationcoefficient (R)",

ylab= "Sample size (n)")

For (i in 1:NP) {

Lines (r,samsize[,1],type= "L", Lwd=2,col=colors[i])

}

Abline (V=0,h=seq (0,yrange[2],50), lty=2,col= "grey89")

Abline (H=0,v=seq (xrange[1],xrange[2],.02), lty=2,col= "grey89")

Title ("Sanple size")

Legend ("TopRight", title= "Power", As.character (p), fill=colors)

10.4 Other Packages

Asypow calculation of efficacy by progressive likelihood ratio method

Effect analysis of sequence design of PWRGSD group

Efficacy analysis of stochastic effect in Pamm mixed model

Calculation of efficacy and sample size in survival analysis of Powersurvepi epidemiological studies

Powerpkg disease sibling Pairing method and TdT (Transmissiondisequilibrium test, Transmission unbalance test) set

Efficiency analysis of the meter

Effect calculation of Powergwasinteractiongwas interaction

Pedantics some functions that contribute to the analysis of the effectiveness of population gene research

Gap some cases the function of calculating efficiency and sample quantity in the cohort research design

Calculation of sample size in SSIZE.FDR microarray experiment

R in Action reading notes (13) Tenth chapter efficacy 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.