I have a moment generating function, so I differentiate it and substitute 0 for the moment of X. I don't know how to do it in R, can you please enlighten me.
In Octave,
pkg load symbolic; #octave symbolic package which itself uses sympy
syms y, x; #declare x,y as symbols
mgf = y / (y - x); #mgf for an exponential variable
mgf1 = diff(mgf, x, 1); #1st derivative of mgf
mgf1_0 = subs(mgf1, x, 0); #substituting 0 in mgf1 for E(X)
I understand R doesn't have built-in symbolic functionality but given what I am trying to do is simply differentiation and substitution, something frequently needed when dealing with pdf/mgf/functions of RVs and other series expansion, I would like to know how I can perform in R in a simple manner (so I can focus on what to calculate, not how).
mgf <- expression(y / (y-x));
mgf1 <- D(mgf, "x");
#no symbolic substitute for x? eval won't work as y remains a variable