Tuesday 15 January 2013

function - using argmax or something simpler in R -


I am trying to install a Gibbs Sampler in R where I update my values ​​in each step. I have a function in R which I want to maximize for 2 values; My last value and a new one let me know the maximum result from the function applied on both values ​​but then how do I choose the best input without manually doing it? (I need many iterations) Here's an idea of ​​code and variables:

  g0 < -function (k) {sample (0: 1, k, substitution = t)}   

This is the AC dimensional vector that is equally with 1 or 0 entries for my series Beginners start point if I include i'th variables in the design matrix then = 1.

X1 Design Matrix

  Xg < -function (g) x [[1] * j [1], x1 [, 2] * j [2], x1 [, 3] * j [3], x1 [, 4] * j [4] Returns (excog [, which ((excog, 2, 2, x] [x] [5] * j [5], x1 [, 6] * j [6], x1 [, 7] * j [7] Fun = Apply Function (X) {All (X == 0)}))))}} Xg0 & lt; Less design matrix for <-xg (g0)   

g0

  c & lt; -1: 100000mp & lt; -function (g) {mp & lt; -sum ((1 / (c * (c + 1) ^ - ((q + 1) / 2)) * (ti)% *% y- (c / (c + 1)) t ( Y)% *% Xg (g)% *% solution (t (exg (g))% *% xg (g))% * t (xg (g))% *% y) ^ (- 27/2 ) Return (MP)}   

This is my function I

So if I have mp (g) and mp (G *) , g and g * for 2 inputs, the maximum is that mp (g *) i < Code> g

Thanks for any help and if you have any questions ask, sorry about the dirty code; I have not used this site before.

like this:

  input and lieutenant; - List (G, G2) Output & lt; - sapply (input, mp) best. Input & lt; - Input [which.max (output)]    

No comments:

Post a Comment