TABLE OF CONTENTS


MetropolisHastings/mh.weight [ Functions ]

NAME

    mh.weight --- MH for spline component weight for either hazard or frailty

FUNCTION

Metropolis-Hastings step for relative weight of spline and parametric components. Works for either hazard or frailty curve, depending on the setting of "which".

SYNOPSIS

2839 mh.weight <- function(which, hazard, frailty, regression)

INPUTS

    which      string, can be either "hazard" or "frailty"
    hazard     RCurve for hazard
    frailty    RCurve for frailty
    regression RRegression structure

OUTPUTS

    curve      updated RCurve for either hazard or frailty

SOURCE

2842 {
2843     # get the curve and likelihood function for the value of "which"
2844     which <- match.arg(which, c("hazard", "frailty"))
2845     if(which == "frailty"){
2846         curve <- frailty
2847         fun <- mklik.weight.frail
2848     }
2849     if(which == "hazard"){
2850         curve <- hazard
2851         fun <- mklik.weight.haz
2852     }
2853     # generate candidate weight as beta
2854     if(!curve$haspar | !curve$hasspline) return(curve)
2855     w <- min(max(curve$weight, .01), .99)
2856     v <- curve$weight.tun
2857     alpha <- w * (w * (1 - w) / v - 1)
2858     beta <- (1 - w) / w * alpha
2859     cand <- rbeta(1, alpha, beta)
2860     if(is.nan(cand)){
2861         curve$weight.accept <- FALSE;
2862         return(curve)
2863     }
2864     # compute transition ratio
2865     alphac <- cand * (cand * (1 - cand) / v - 1)
2866     betac <- (1 - cand) / cand * alphac
2867     baselik <- fun(w, hazard, frailty, regression)
2868     candlik <- fun(cand, hazard, frailty, regression)
2869     puc <- suppressWarnings(dbeta(cand, alpha, beta))
2870     pcu <- suppressWarnings(dbeta(w, alphac, betac))
2871     acc <- acceptreject(baselik, candlik, pcu / puc)
2872     if(acc){
2873         curve$weight <- cand
2874         curve <- weightcurve(curve)
2875     }
2876     curve$weight.accept <- acc
2877     return(curve)
2878 }