1
$\begingroup$

I need expected values of a list where the random variable to take expectations over should be an input into expressions defined earlier. I suspect Set[] and SetDelayed[] tripped me. (Or Map and Table?)

I hope the intention is reasonably clear from the code: I am interested in expressions of six numbers in [0,1] where I suspect (model) that they have been measured with error (errors being independent and uniform here, but answers truncated to lie in the meaningful range anyway). I don't get the solution I expect, only an expression substituted into.

Input:

AList = {a1,a2,a3,a4,a5,a6}
answers := (Min[1,Max[# ,0]])& /@ (AList+errors)
dlist ={answers[[5]],answers[[6]],answers[[3]]/answers[[1]],answers[[4]]/answers[[2]]} 
deltasbetas = Expectation[dlist,errors\[Distributed]Table[UniformDistribution[],{6}]]

(note that errors are defined within Expectation, as I think it should be) Output:

{Min[1,Max[0,0.8 +UniformDistribution[{0,1}]]],Min[1,Max[0,0.7 +UniformDistribution[{0,1}]]],Min[1,Max[0,0.5 +UniformDistribution[{0,1}]]]/Min[1,Max[0,0.8 +UniformDistribution[{0,1}]]],Min[1,Max[0,0.4 +UniformDistribution[{0,1}]]]/Min[1,Max[0,0.7 +UniformDistribution[{0,1}]]]}
$\endgroup$
16
  • 3
    $\begingroup$ what are AList and errors? $\endgroup$
    – rm -rf
    Jul 13, 2012 at 13:39
  • 1
    $\begingroup$ I think you need to use TransformedDistribution ... but how?:) $\endgroup$
    – kglr
    Jul 13, 2012 at 14:41
  • 1
    $\begingroup$ I think maybe you have to explicitly use something like {e1, e2, e3, e4, e5, e6} \[Distributed] UniformDistribution[{{0,1},{0,1},{0,1},{0,1},{0,1},{0,1}}] instead of just one errors variable. $\endgroup$
    – Silvia
    Jul 13, 2012 at 14:56
  • 2
    $\begingroup$ errors=Array[er,6] before you use errors; and then use errors \[Distributed] UniformDistribution[Table[{0, 1}, {6}] instead of errors \[Distributed] Table.... $\endgroup$
    – kglr
    Jul 13, 2012 at 15:12
  • 1
    $\begingroup$ @László, pls ignore the Thread comment. Regarding er going undefined, errors=Array[er,{6}] defines errors as a list with 6 elements with names er[1] thru er[6]. So, you can use the symbol errors instead of {e1,e2,...,e6}. $\endgroup$
    – kglr
    Jul 13, 2012 at 15:46

2 Answers 2

2
$\begingroup$

If there is no way to use a "list variable" for the random vector, an explicit list of scalars can be filled in with the right distribution, thanks to @Silvia:

underlying := {0.8, 0.7, 0.5, 0.4, 0.8, 0.7}
answers := (Min[1, Max[# , 0]]) & /@ (underlying + {e1, e2, e3, e4, e5, e6})
dlist := {answers[[5]], answers[[6]], answers[[3]]/answers[[1]], answers[[4]]/answers[[2]]} 
deltasbetas = Expectation[dlist,
         {e1, e2, e3, e4, e5, e6} \[Distributed] UniformDistribution[Table[{0, 0.1}, {6}]]]

{0.85, 0.75, 0.647807, 0.600891}
$\endgroup$
1
  • $\begingroup$ You are welcome :) $\endgroup$
    – Silvia
    Jul 13, 2012 at 15:10
2
$\begingroup$

Using assumptions on the aList, namely, that all a[i]s are in the unit interval, we get symbolic results for Expectation:

aList = Array[a, {6}];
errors = Array[er, 6];
answers = (Min[1, Max[#, 0]]) & /@ (aList + errors);
dlist = {answers[[5]], answers[[6]], answers[[3]]/answers[[1]], answers[[4]]/answers[[2]]};
deltasbetas = Expectation[dlist, 
errors \[Distributed] UniformDistribution[Table[{0, 1}, {6}]], 
Assumptions -> {And @@ Table[0 < a[i] <= 1, {i, 6}]}]

we get

enter image description here

EDIT 1: For UniformDistribution[0,1/10]

 Expectation[dlist,  errors \[Distributed] 
 UniformDistribution[Table[{0, 1/10}, {6}]], Assumptions -> {And @@ Table[0 < a[i] <= 1, {i, 6}]}]

we get

enter image description here

Evaluating at underlying:

 % /. Thread[aList -> underlying]

we get

{0.85, 0.75, 0.647807, 0.600891}

EDIT 2: Alternative specifications of the joint distribution under Expectation:

 Expectation[dlist, errors \[Distributed] 
 ProductDistribution[Table[UniformDistribution[], {6}]], 
 Assumptions -> {And @@ Table[0 < a[i] <= 1, {i, 6}]}]

give the same result.

So does

 trdist = TransformedDistribution[dlist, 
 errors \[Distributed] UniformDistribution[Table[{0, 1}, {6}]]];
 Expectation[z, z \[Distributed] trdist, 
 Assumptions -> {And @@ Table[0 < a[i] <= 1, {i, 6}]}]
$\endgroup$
3
  • $\begingroup$ Nice, thank you! So I can Manipulate the result be giving it values of aList (or a?) And still Plot the resulting list in terms of the range of the error distribution (simply numerically 1 in the example)? $\endgroup$
    – László
    Jul 13, 2012 at 16:30
  • $\begingroup$ Only 40 more to 10k (which you should reach today). Congrats in advance! :) $\endgroup$
    – rm -rf
    Jul 13, 2012 at 18:43
  • $\begingroup$ @R.M thank you!! $\endgroup$
    – kglr
    Jul 13, 2012 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.