Compute vector of loglikelihood for fitted mash object on new data

mash_compute_vloglik(g, data, algorithm.version = c("Rcpp", "R"))

Arguments

g

A mash object.

data

A set of data on which to compute the loglikelihood.

algorithm.version

Indicate R or Rcpp version

Value

The vector of log-likelihoods for each data point computed using g.

Details

The log-likelihood for each element is \(p(Bhat_j | Shat_j,g,\alpha)\) where \(Bhat_j | B_j, Shat_j \sim N(B_j, Shat_j)\) and \(B_j/Shat_j^\alpha | Shat_j \sim g\) Here the value of \(\alpha\) is set when setting up the data object in `mash_set_data`. If g is a mash object (safest!) then the function will check that this value matches the \(\alpha\) used when fitting `mash`. Note: as a convenience, this function can also be called with g a mixture distribution with same structure as the fitted_g from a mash object. This is mostly useful when doing simulations, where you might want to compute the likelihood under the "true" g. When used in this way the user is responsible for making sure that the g makes sense with the alpha set in data.

Examples

simdata = simple_sims(50,5,1)
data = mash_set_data(simdata$Bhat, simdata$Shat)
m = mash(data, cov_canonical(data))
#>  - Computing 200 x 151 likelihood matrix.
#>  - Likelihood calculations took 0.01 seconds.
#>  - Fitting model with 151 mixture components.
#>  - Model fitting took 0.18 seconds.
#>  - Computing posterior matrices.
#>  - Computation allocated took 0.00 seconds.
mash_compute_vloglik(m,data)
#>              [,1]
#>   [1,]  -7.479756
#>   [2,]  -6.765900
#>   [3,]  -6.346920
#>   [4,]  -8.543689
#>   [5,]  -7.370509
#>   [6,]  -6.574892
#>   [7,]  -8.110833
#>   [8,]  -5.655011
#>   [9,]  -7.540940
#>  [10,]  -7.742493
#>  [11,]  -7.927045
#>  [12,]  -7.828399
#>  [13,]  -5.496245
#>  [14,]  -6.679480
#>  [15,]  -6.098145
#>  [16,]  -8.311050
#>  [17,]  -7.528929
#>  [18,]  -7.763508
#>  [19,]  -5.478474
#>  [20,]  -6.199140
#>  [21,]  -7.625196
#>  [22,]  -8.334562
#>  [23,]  -6.492579
#>  [24,]  -5.496679
#>  [25,]  -5.552340
#>  [26,]  -6.720046
#>  [27,]  -6.080104
#>  [28,]  -5.784585
#>  [29,]  -7.777515
#>  [30,]  -6.549114
#>  [31,]  -7.007001
#>  [32,]  -5.714566
#>  [33,]  -7.199930
#>  [34,]  -8.773924
#>  [35,]  -5.904277
#>  [36,]  -6.927347
#>  [37,]  -7.962434
#>  [38,]  -6.281372
#>  [39,]  -5.027298
#>  [40,]  -8.844530
#>  [41,]  -7.597093
#>  [42,]  -8.116511
#>  [43,]  -9.483300
#>  [44,]  -6.670452
#>  [45,]  -7.888945
#>  [46,]  -6.326428
#>  [47,]  -7.045428
#>  [48,]  -5.661185
#>  [49,]  -6.883048
#>  [50,]  -5.819426
#>  [51,]  -7.212468
#>  [52,]  -7.333312
#>  [53,] -11.806629
#>  [54,]  -7.599366
#>  [55,]  -9.645199
#>  [56,]  -8.999323
#>  [57,]  -9.299451
#>  [58,]  -9.898181
#>  [59,]  -9.471296
#>  [60,]  -7.524837
#>  [61,]  -9.221230
#>  [62,]  -7.136848
#>  [63,]  -9.486567
#>  [64,]  -6.623411
#>  [65,]  -7.398140
#>  [66,] -10.066014
#>  [67,] -10.542137
#>  [68,] -14.091857
#>  [69,] -12.085286
#>  [70,] -13.018037
#>  [71,]  -8.376584
#>  [72,]  -9.249776
#>  [73,] -13.386756
#>  [74,]  -7.939128
#>  [75,] -13.655895
#>  [76,] -10.405125
#>  [77,]  -6.331709
#>  [78,] -16.292567
#>  [79,]  -8.914492
#>  [80,] -10.474061
#>  [81,] -12.164843
#>  [82,]  -8.125435
#>  [83,] -10.758708
#>  [84,] -11.045730
#>  [85,] -10.263574
#>  [86,]  -7.907271
#>  [87,] -10.537550
#>  [88,]  -5.562916
#>  [89,]  -9.501366
#>  [90,] -11.571608
#>  [91,]  -6.474862
#>  [92,]  -8.822869
#>  [93,] -10.888837
#>  [94,]  -6.986096
#>  [95,]  -8.924081
#>  [96,]  -8.455804
#>  [97,] -10.241926
#>  [98,]  -6.415116
#>  [99,]  -6.901904
#> [100,]  -5.459803
#> [101,]  -6.153957
#> [102,]  -6.009456
#> [103,]  -5.694071
#> [104,]  -5.602469
#> [105,]  -6.304543
#> [106,]  -7.841946
#> [107,]  -5.321497
#> [108,]  -8.064941
#> [109,] -10.797573
#> [110,]  -7.557331
#> [111,]  -6.838517
#> [112,]  -6.905758
#> [113,]  -6.958404
#> [114,]  -6.189789
#> [115,]  -6.630908
#> [116,]  -6.460466
#> [117,] -10.229567
#> [118,]  -7.652139
#> [119,] -11.758998
#> [120,]  -5.415419
#> [121,]  -9.521740
#> [122,]  -8.126388
#> [123,]  -8.855640
#> [124,]  -6.986084
#> [125,]  -5.458232
#> [126,]  -5.273942
#> [127,]  -8.117747
#> [128,]  -7.240926
#> [129,]  -7.322907
#> [130,]  -8.033077
#> [131,]  -6.660673
#> [132,]  -7.261205
#> [133,] -10.033616
#> [134,]  -5.839334
#> [135,]  -8.935967
#> [136,]  -8.758978
#> [137,] -11.469527
#> [138,]  -5.905810
#> [139,]  -9.141114
#> [140,]  -6.917834
#> [141,]  -6.390059
#> [142,]  -7.580998
#> [143,]  -5.754718
#> [144,] -10.193169
#> [145,]  -5.976582
#> [146,]  -7.877831
#> [147,]  -7.539450
#> [148,]  -7.770518
#> [149,]  -8.758527
#> [150,]  -6.932952
#> [151,]  -8.219938
#> [152,]  -8.291445
#> [153,]  -7.068228
#> [154,]  -6.265829
#> [155,]  -5.812913
#> [156,]  -9.023985
#> [157,] -10.884336
#> [158,]  -7.886958
#> [159,]  -5.741434
#> [160,] -10.626845
#> [161,]  -8.153787
#> [162,] -10.365180
#> [163,]  -8.026847
#> [164,]  -9.682709
#> [165,]  -8.735336
#> [166,]  -7.915623
#> [167,]  -8.534058
#> [168,]  -9.635701
#> [169,]  -8.654309
#> [170,]  -8.478314
#> [171,]  -6.118095
#> [172,]  -8.712342
#> [173,] -10.653891
#> [174,]  -7.454171
#> [175,] -10.262429
#> [176,]  -6.297631
#> [177,]  -8.293048
#> [178,]  -6.166626
#> [179,]  -5.688303
#> [180,] -11.768599
#> [181,]  -5.285613
#> [182,]  -6.201529
#> [183,]  -5.836774
#> [184,]  -7.828565
#> [185,]  -8.358317
#> [186,]  -5.611297
#> [187,]  -6.141978
#> [188,]  -6.009994
#> [189,]  -8.463672
#> [190,]  -8.448310
#> [191,]  -8.421256
#> [192,]  -9.702697
#> [193,]  -7.219442
#> [194,]  -6.660384
#> [195,]  -8.725727
#> [196,]  -8.019712
#> [197,]  -8.773134
#> [198,]  -7.135388
#> [199,]  -7.076499
#> [200,]  -5.665784