Advertisement
Guest User

vitd

a guest
Jun 26th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. vitd.curve <- function( N, type = c("placebo","fixed-dose","dynamic-dose", "cross-placebo-fixed-dose", "cross-placebo-dynamic-dose"), start = 0, end = 2, cross = .5*(start + end), Min.Height = 10, Max.Height = 80, Flat.Height = 50, Spread.Min = 1, Spread.Max = 1, Spread.FH = 1, supp.dose = 20, north.hemi = TRUE, res = 40, omega = 1, b = 0, beta = 0, x = 1) ){
  2.  
  3. if( !( type %in% c("placebo","fixed-dose","dynamic-dose", "cross-placebo-fixed-dose", "cross-placebo-dynamic-dose") ) )
  4. stop("Argument 'type' is not valid.")
  5.  
  6. if( any( c(start < 0, end < 0, end <= start ) ) ) stop("Arguments 'start' and 'end' must be positive with 'end' > 'start'")
  7. if( any( c(Min.Height < 0, Max.Height < 0, Max.Height < Min.Height) ) ) stop("Arguments 'Min.Height' and 'Max.Height' must be positive with 'Max.Height' > 'Min.Height'")
  8. #if( Flat.Height < 0 | Flat.Height > Max.Height ) stop("Argument Flat.Height must be positive. Sensible values will be less than 'Max.Height'.")
  9. if( any( c(Spread.Min < 0, Spread.Max < 0, Spread.FH < 0) ) ) stop( "Arguments 'Spread.Min', 'Spread.Max', 'Spread.FH' must be positive." )
  10. if( supp.dose < 0 ) stop("Argument 'supp.dose' must be positive.")
  11.  
  12. if ( N > 1 ){
  13. Amplitude <- Max.Height - Min.Height
  14. Height <- Min.Height
  15. years <- end - start
  16. time1 <- seq( start*pi, end*pi, length.out=years*(12*res) + 1 ) # pi is one year
  17. cross1 <- cross*pi
  18. time <- ( time1 * (12/pi) ) # gives time in terms of months
  19.  
  20. if( Spread.Min > 100 || Spread.Max > 100 || Spread.FH > 100
  21. || Spread.Min < 1 || Spread.Max < 1 || Spread.FH < 1 ) stop("Spread must be from 1-100")
  22.  
  23. Spread.A <- 100 / Spread.Max
  24. Spread.H <- 100 / Spread.Min
  25. Spread.FH <- 100 / Spread.FH
  26.  
  27. if( type == "placebo" ){
  28.  
  29. y <- list( time, random.sine( N , k.A = Spread.A, k.H = Spread.H, H.0 = Height,
  30. A.0 = Amplitude, time = omega*time1 + b) +beta*(time1^x), Height, Max.Height,
  31. Spread.Min, Spread.Max, Spread.FH, type, supp.dose, north.hemi, res )
  32. names( y ) <- c( "time", "curve", "min.height", "max.height", "spread.min", "spread.max",
  33. "spread.fh", "type", "supp.dose", "north.hemi", "res" )
  34. names( y[[2]] ) <- c( "outp", "min.heights", "max.heights" )
  35.  
  36. }else if( type == "fixed-dose" ){
  37.  
  38. y <- list( time, random.sine( N , k.A = Spread.A, k.H = Spread.H, H.0 = supp.dose + Height,
  39. A.0 = Amplitude, time = omega*time1 + b) +beta*(time1^x), Height, Max.Height,
  40. Spread.Min, Spread.Max, Spread.FH, type, supp.dose, north.hemi, res )
  41. names( y ) <- c( "time", "curve", "min.height", "max.height", "spread.min", "spread.max",
  42. "spread.fh", "type", "supp.dose", "north.hemi", "res" )
  43. names( y[[2]] ) <- c( "outp", "min.heights", "max.heights" )
  44.  
  45. }else if( type == "dynamic-dose" ){
  46.  
  47. y <- list( time, random.flatsine( N, k.A = Spread.A, k.H = Spread.H,
  48. k.FH = Spread.FH, H.0 = Height,
  49. A.0 = Amplitude, FH.0 = Flat.Height, time = omega*time1 + b) +beta*(time1^x), Height, Max.Height,
  50. Flat.Height, Spread.Min, Spread.Max, Spread.FH, type, supp.dose, north.hemi, res )
  51. names( y ) <- c( "time", "curve", "min.height", "max.height", "flatheight",
  52. "spread.min", "spread.max", "spread.fh", "type", "supp.dose", "north.hemi", "res" )
  53. names( y[[2]] ) <- c( "outp", "min.heights", "max.heights", "flatheights" )
  54.  
  55. }else if( type == "cross-placebo-fixed-dose" ){
  56.  
  57. y <- list( time, random.sine( N , k.A = Spread.A, k.H = Spread.H, H.0 = Height,
  58. A.0 = Amplitude, time = omega*time1 + b, cross=cross1, delta=supp.dose ) +beta*(time1^x), Height, Max.Height,
  59. Spread.Min, Spread.Max, Spread.FH, type, supp.dose, north.hemi, cross1, res )
  60. names( y ) <- c( "time", "curve", "min.height", "max.height", "spread.min", "spread.max",
  61. "spread.fh", "type", "supp.dose", "north.hemi", "cross", "res" )
  62. names( y[[2]] ) <- c( "outp", "min.heights", "max.heights" )
  63.  
  64. }else if( type == "cross-placebo-dynamic-dose" ){
  65.  
  66. y <- list( time, random.flatsine( N, k.A = Spread.A, k.H = Spread.H,
  67. k.FH = Spread.FH, H.0 = Height,
  68. A.0 = Amplitude, FH.0 = Flat.Height, time = omega*time1 +b, cross=cross1 ) +beta*(time1^x), Height, Max.Height,
  69. Flat.Height, Spread.Min, Spread.Max, Spread.FH, type, supp.dose, north.hemi, cross1, res )
  70. names( y ) <- c( "time", "curve", "min.height", "max.height", "flatheight",
  71. "spread.min", "spread.max", "spread.fh", "type", "supp.dose", "north.hemi", "cross", "res" )
  72. names( y[[2]] ) <- c( "outp", "min.heights", "max.heights", "flatheights" )
  73.  
  74. }
  75.  
  76. class( y ) <- "vitd.curve"
  77. return( y )
  78.  
  79. }else{ stop("Invalid number of participants: N must be > 1") } # warning or stop?
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement