knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(PWEALL)

Scaling leads to faster speed

Scaling the event rates and/or the times to more manageable scale generally leads to improvement of speed. For example, when we have timeline prediction that has a wide range, say 0 to 120 months, it is usually helpful to first scale to year or even scale it into the unit interval.

Define weight function(s)

The following function can be used to facilitate defining of the weight functions via either T-splines or B-splines.

fun1 <- function(degree=3,inner.knots=c(1,2,2.5),boundary.knots=c(0,6),bt=rep(0,1+degree+length(inner.knots)),base='T',tau=1,type=-1,a=tau,b=1,c=0) {
  force(degree)
  force(inner.knots)
  force(boundary.knots)
  force(bt)
  force(base)
  force(tau)
  force(type)
  force(a)
  force(b)
  force(c)
  fun2 <- function(x) {
    tx=trany(x,tau=tau,type=type,a=a,b=b,c=c)$ty
    txinner.knots=trany(inner.knots,tau=tau,type=type,a=a,b=b,c=c)$ty
    txboundary.knots=trany(boundary.knots,tau=tau,type=type,a=a,b=b,c=c)$ty
    if (base=='T'){
          XB=tbase(tx,iknots=txinner.knots,lk=txboundary.knots[1],hk=txboundary.knots[2],deg=degree)
    }
    else if (base=='B'){
          XB=splines2::bSpline(tx,knots=txinner.knots, degree=degree,intercept=TRUE,Boundary.knots=txboundary.knots)
    }
    XB%*%bt
  }
  return(fun2)
}

The following code provides an example on how to define the weight functions using the above code.

wfunctions=c(1,2,3,4,5,6)
alpha=c(0.005,0.025)
onesided=TRUE
pi1=0.5

n.weights=length(wfunctions)
degree=3
inner.knots=c(0.5,3,6,10,20)
boundary.knots=c(0,36)
np=degree+1+length(inner.knots)
btmatrix=matrix(0,nrow=n.weights,ncol=np)
btmatrix[1,1]=1
btmatrix[2,]=c(-0.03047602,1.466433,0.3813386,-5.616564,0.01741583,13.59455,-16.21707,7.195338,21.47292)
btmatrix[3,]=c(0.4408064,-0.7547523,1.813175,-2.673851,-6.57252e-13,1.092402,2.334763,-0.7490225,4.920812)
btmatrix[4,]=c(0.4161905,-0.02885027,0.2652066,-0.299486,2.415845e-13,-1.205081,2.827345, -3.35227,-11.20574)
btmatrix[5,]=c(0.01057016,-0.01427205,0.1756744,0.01080043,3.552714e-15,-0.210763,2.069093,-2.031769,5.139737)
btmatrix[6,]=c(0.002961566,0.08252436,3.053774,-4.985592,-1.421085e-14,2.001894,5.431488,-2.260589,-6.868965)

mc.weightfuns <- vector("list", n.weights)
for (i in 1:n.weights) {
  mc.weightfuns [[i]] <- fun1(degree=3,inner.knots=inner.knots,boundary.knots=boundary.knots,bt=btmatrix[i,],base='T',type=1,tau=36,a=34/2,b=1,c=0)
}


marvels2031/PWEALL_1.4.0 documentation built on April 22, 2022, 12:52 a.m.