Learn R Programming

segmented (version 2.1-1)

pwr.seg: Power Analysis in segmented regression

Description

Given the appropriate input values, the function computes the power (sample size) corresponding to the specifed sample size (power). If a segmented fit object is provided, the power is computed taking the parameter estimates as input values.

Usage

pwr.seg(oseg, pow, n, z = "1:n/n", psi, d, s, n.range = c(10,300), 
    X = NULL, break.type=c("break","jump"), alpha = 0.01, round.n = TRUE, 
    alternative = c("two.sided", "greater", "less"), msg = TRUE, ci.pow=0)

Value

The computed power or sample size, with or without message (depending on msg)

Arguments

oseg

The fitted segmented object. If provided, the power is computed at the model parameter estimates, and all the remaining arguments but alternative and alpha are ignored.

pow

The desired power level. If provided n has to be missing

n

The fixed sample size. If provided pow has to be missing

z

The covariate understood to have a segmented effect. Default is "1:n/n", i.e. equispaced values in (0,1). More generally a string indicating the quantile function having p and possible other numerical values as arguments. For istance "qunif(p,0,1)", "qnorm(p,2,5)", or "qexp(p)". "qunif(p,1,n)" can be also specified, but attention should be paid to guarantee psi within the covariate range. Finally, it could be also a numerical vector meaning the actual covariate, but pow has to be missing. Namely if the covariate is supplied (and n is known), only the relevant power can be estimated.

psi

The breakpoint value within the covariate range

d

The slope difference

s

The response standard deviation

n.range

When pow is provided and the relevant sample size estimate has to be returned, the function evaluates 50 sample sizes equally spaced in n.range. However the function can also compute, via spline interpolation, sample sizes outside the specified range.

X

The design matrix including additional linear variables in the regression equation. Default to NULL which means intercept and linear term for the segmented covariate.

break.type

Type of breakpoint. break.type='break' means piecewise linear (segmented), break.type='jump' refers to piecewise constant.

alpha

The type-I error probability. Default to 0.01.

round.n

logical. If TRUE the (possible) returned sample size value is rounded.

alternative

a character string specifying the alternative hypothesis, must be one of "two.sided", "greater" or "less". Note, this refers to the sign of the slope difference.

msg

logical. If TRUE the output is returned along with a simple message, otherwise only the values are returned

ci.pow

Numerical. If oseg has been supplied, ci.pow replicates are drawn to build a 95% confidence interval for the power.

Author

Nicoletta D'Angelo and Vito Muggeo

Details

The function exploits the sampling distribution of the pseudo Score statistic under the alternative hypothesis of one breakpoint.

References

D'Angelo N, Muggeo V.M.R. (2021) Power analysis in segmented regression, working paper
https://www.researchgate.net/publication/355885747.

Muggeo, V.M.R. (2016) Testing with a nuisance parameter present only under the alternative: a score-based approach with application to segmented modelling. J of Statistical Computation and Simulation, 86, 3059--3067.

See Also

pscore.test

Examples

Run this code
  ## pwr.seg(pow=.7, psi=.5, d=1.5, s=.5) #returns the sample size
  ## pwr.seg(n=219, psi=.5, d=1.5, s=.5) #returns the power
  ## pwr.seg(n=20,z="qnorm(p, 2,5)", psi=3, d=.5, s=2) #the covariate is N(2,5)
  ## pwr.seg(n=20,z="qexp(p)", psi=.1, d=.5, s=.1) #the covariate is Exp(1)

    

Run the code above in your browser using DataLab