Question: How to extract the coefficients of the random variables in a linear combination of random variables?

How to use collect() or coeffs() on random variables instead of standard variables?

I need to re-organize a linear combination of RVs nu[1], nu[2], u[1], u[2], u[3] by collecting the coefficients on each of these 5 RVs. Note that the Xs are correlated with each other and the Ys are correlated with each other (but Xs and Ys are uncorrelated).

For example, nu is a 2D gaussian vector where nu[1] and nu[2] are defined in terms of _R1, _R2, means, standard deviations and correlation coefficient. They are quite "nested" and the 3D gaussian vector u is even worse, so when these enter a linear combination it becomes hard to identify them back as simply nu[1], nu[2], u[1], u[2], u[3].

Is there a way to "isolate" them in a linear combination by using collect()-like or coeffs()-like functions (i) directly on the RVs or (ii) indireclty on the explicit expressions of _Rs, means, standard devs, correlation coeffs? 

(I already checked the answers to these two somewhat similar questions but did not help for my case:


See my script below: 

For example, I would want collect() on nu[1] (or equivalently on _R1*sigma__v[1]+nu__0[1]) to give me X__1+X__3 (as you easily see from my definition of Omega).

# 2.2.1 Define the Omega random variable as Omega__1+Omega__2+Omega__3:

`Ω__1` := X__1*(nu[1]-`μ__1`-`λ__1`*(u[1]+X__1)); `Ω__2` := X__2*(nu[2]-`μ__2`-`λ__2`*(u[2]+X__2)); `Ω__3` := X__3*(nu[1]+nu[2]-`μ__3`-`λ__3`*(u[3]+X__3)); Omega := `Ω__1`+`Ω__2`+`Ω__3`

X__1*(sigma__v[1]*_R1+nu__0[1]-mu__1-lambda__1*(_R3*sigma__u[1]+X__1))+X__2*(sigma__v[2]*rho__v[1, 2]*_R1+(-rho__v[1, 2]^2+1)^(1/2)*sigma__v[2]*_R2+nu__0[2]-mu__2-lambda__2*(rho__u[1, 2]*sigma__u[2]*_R3+(-rho__u[1, 2]^2+1)^(1/2)*sigma__u[2]*_R4+X__2))+X__3*(sigma__v[1]*_R1+nu__0[1]+sigma__v[2]*rho__v[1, 2]*_R1+(-rho__v[1, 2]^2+1)^(1/2)*sigma__v[2]*_R2+nu__0[2]-mu__3-lambda__3*(rho__u[1, 3]*sigma__u[3]*_R3-sigma__u[3]*(rho__u[1, 2]*rho__u[1, 3]-rho__u[2, 3])*_R4/(-rho__u[1, 2]^2+1)^(1/2)+((-2*rho__u[1, 2]*rho__u[1, 3]*rho__u[2, 3]+rho__u[1, 2]^2+rho__u[1, 3]^2+rho__u[2, 3]^2-1)/(rho__u[1, 2]^2-1))^(1/2)*sigma__u[3]*_R5+X__3))


# 2.2.2 Simplify and re-arrange the Omega RV to obtain the easy-to-read version (a,b,c,d,e,f are the coefficients):
#Omega__* = a + b*nu[1] + c*nu[2] + d*u[1] + e*u[2] + f*u[3];
# How to do it? Collect() does not work...simplify() doesn't make it any easier...

`Ω__*` := collect(Omega, [_R1*`σ__v`[1]+`ν__0`[1], `σ__v`[2]*`ρ__v`[1, 2]*_R1+sqrt(-`ρ__v`[1, 2]^2+1)*`σ__v`[2]*_R2+`ν__0`[2], `σ__u`[1]*_R3, `σ__u`[2]*`ρ__u`[1, 2]*_R3+sqrt(-`ρ__u`[1, 2]^2+1)*`σ__u`[2]*_R4, `σ__u`[3]*`ρ__u`[1, 3]*_R3-`σ__u`[3]*(`ρ__u`[1, 2]*`ρ__u`[1, 3]-`ρ__u`[2, 3])*_R4/sqrt(-`ρ__u`[1, 2]^2+1)+sqrt((-2*`ρ__u`[1, 2]*`ρ__u`[1, 3]*`ρ__u`[2, 3]+`ρ__u`[1, 2]^2+`ρ__u`[1, 3]^2+`ρ__u`[2, 3]^2-1)/(`ρ__u`[1, 2]^2-1))*`σ__u`[3]*_R5])

Error, (in collect) cannot collect _R1*sigma__v[1]+nu__0[1]


`Ω__col` := collect(Omega, [nu[1], nu[2], u[1], u[2], u[3]])

Error, (in collect) cannot collect _R1*sigma__v[1]+nu__0[1]




This has been branched into the following page(s):
Please Wait...