Tag Info

Hot answers tagged

17

A nice question. Sampling from tCopula is done in stages. First a sample is generated from the copula with uniform marginal distributions, and then quantiles of appropriate marginal distributions are applied to the respective slots. Most of the time goes into evaluation of these quantiles, and they are expensive to compute. Being interested in $\geqslant ...


11

Following the method on the wikipedia page mentioned in the comments, I came up with this interp[pts_] := Module[{delta, mlst, zeropos, tau, h00, h01, h10, h11}, delta = #2/#1 & @@@ Differences[pts]; mlst = Flatten[{delta[[1]], MovingAverage[delta, 2], delta[[-1]]}]; tau = Min[#, 1] & /@ (3 delta/Sqrt[(Most[mlst]^2 + Rest[mlst]^2)]); tau ...


10

The code in Heike's answer is a bit long, but only because it does not exploit the fact that piecewise Hermite interpolation is already supported by Mathematica as Interpolation[]. Thus, here is a shorter way to implement Fritsch-Carlson monotonic cubic interpolation: fcint[data_] := Module[{del, slopes, tau}, del = #2/#1 & @@@ ...


8

InverseSurvivalFunction[] is the nearest to what you want; for a given confidence level $\alpha$ and degree of freedom $\nu$, InverseSurvivalFunction[ChiSquareDistribution[ν], α] gives the result you want. Alternatives include InverseCDF[ChiSquareDistribution[ν], 1 - α] and Quantile[ChiSquareDistribution[ν], 1 - α].


8

Add the argument "Probability" to the Histogram command. To be precise, if list is your list of data, then Histogram[list,Automatic,"Probability"] should do the trick. The Automatic argument specifies the bin size.


8

Let's make a set of points: pts = Select[RandomReal[{-1, 1}, {1000, 2}], Norm[#] < 1 &]; ListPlot[pts, AspectRatio -> Automatic] Construct the density and plot it, including a contour line at the manually selected value of 0.1, all in one go: g = SmoothDensityHistogram[pts, Mesh -> {{.1}}, PlotRange -> 1.5 {{-1, 1}, {-1, 1}}] Use ...


7

The natural way is to use RectangleChart since your data is already processed. I will just show how to use Histogram for your purposes, it requires step back to create the data, that's why Mike's solution is better. data = {{{0, 17}, {17, 24}, {24, 44}, {44, 64}, {64, 84}}, {86031, 26671, 91927, 93983, 32232}}; dat = RandomReal[#, ...


7

Based solely on the information provided IMO you need to use RectangleChart. I'm not sure how to create the histogram you desire using Histogram and only the information in your question -- here is the RectangleChart implementation: {widths, totals} = {{17, 7, 20, 20, 20}, {86031, 26671, 91927, 93983, 32232}}; RectangleChart[Transpose@{widths, ...


7

Perhaps use UnitStep and Mean. This should be pretty fast. f[logr_, x_] := Mean[UnitStep[logr - x]] f[logr, 0] (*1597/3018*) Now to plot it. Plot[f[logr, t], {t, -.1, .1}, Exclusions -> None]


7

TransformedDistribution contains a collection of identities known to it, like that of sum of normals being equal in distribution to another normal random variable, and a general machinery to work out properties of the functions of random variables. Most of the time the computation will be done by the general machinery, which relies on solvers, like ...


7

Update: The link in the late Jens-Peer Kuska's MathGroup post is no longer working, and it seems there are no other locations on the web to download the package from. So, here I post the contents of the package with gratitute to Jens-Peer Kuska for his continuing service to the Mathematica community. Nonparametric Splines package - Jens-Peer Kuska ...


6

As far as I know there are no test suites that can be invoked directly from Mathematica. One can of course use the traditional ones such as the one you mention or the NIST or the Marsaglia's diehard tests. I implemented some "toy tests" in this Wolfram Demonstration to illustrate Mathematica's various built-in PRNGs, which fail or succeed the toy tests ...


6

With the help of comments on this and other stackexchange pages I managed to solve the problem of how to use custom distributions in things like CopulaDistribution (and other functions like RandomVariate, Expectation, etc), and given that it took me a couple of days’ hard slog I thought I’d share my discoveries with this community. Please excuse the flippant ...


6

list = {{3, 5}, {7, 6}, {15, 6}, {23, 123}} DeleteCases[list, {x_, _} /; x < 10] DeleteCases[list, {_?(# < 10 &), _}] Cases[list, {x_, _} /; x >= 10] Cases[list, {_?(# >= 10 &), _}] Select[list, First[#] >= 10 &] Pick[list, First[#] >= 10 & /@ list] list /. {x_, _} /; x < 10 :> Sequence[] list /. {_?(# < ...


6

Alternatively you can fix both the bin end points and their heights explicitly. I've set 120 as a reasonable endpoint for the last bin. The zero in the input data is just there as a place holder and is effectively ignored. Histogram[{0}, {{0, 18, 25, 45, 65, 120}}, {86031/17, 26671/7, 91927/20, 93983/20, 32232/20} &] I would use the rectangle ...


5

EmpiricalDistribution can assign probabilities to each element in a set of discrete values: Here's an example: In[1]:= d = EmpiricalDistribution[{1/3, 1/2, 1/6} -> {1, 2, 3}]; In[2]:= Mean[d] Out[2]= 11/6 In[3]:= PDF[d, x] Out[3]= 1/3 Boole[1 == x] + 1/2 Boole[2 == x] + 1/6 Boole[3 == x] In[4]:= CDF[d, x] Out[4]= 1/3 Boole[1 <= x] + 1/2 Boole[2 ...


5

You could set this up in symbolic form as a bivariate distribution with pmf $f(x,y)$: Then, using the mathStatica add-on to Mathematica, the correlation you seek is: Corr[{x, y}, f] $\frac{607}{\sqrt{1467199}}$ Note that this is slightly different to the solution you posted,as the numerical value is: 0.501123... (not 0.0501). You can make Mma do ...


5

You can use DistributionDomain to find the domain of a distribution, which will also tell you the dimension. I do not know where this is documented, but it does appear in some examples in the documentation. Usage examples: DistributionDomain[NormalDistribution[]] (* Interval[{-∞, ∞}] *) DistributionDomain[ParetoDistribution[xmin, alpha]] (* ...


4

Assuming you have version 9 you can do the following. data = {{-1, 0}, {0, 0}, {1, 0}, {-2, 1}, {2, 1}, {-1, 3}, {1, 3}}; dist = EmpiricalDistribution[data]; Table[Expectation[y \[Conditioned] x == i, {x, y} \[Distributed] dist], {i, -2, 2}] (*{1, 3/2, 0, 3/2, 1}*) Note: Conditional probabilities and expectations didn't work for EmpiricalDistribution ...


4

If we reformulate your question as: Given a box with 30 balls, of which 10 are red, what is the probability that 4 balls drawn at random (without replacement) don't have any red balls in them you can model it by the HypergeometricDistribution: A hypergeometric distribution gives the distribution of the number of successes in $n$ draws from a ...


4

The Wolfram Demonstration Project has 13 submissions that use Bayes Theorem: See here More specifically: Probability Of Being Sick After Having Tested Positive For A Disease Bayes's Theorem And Inverse Probability Total Probability And Bayes's Theorem All of these will have downloadable code to help you learn this. Good luck.


4

There is a undocumented input form such as: DegreeGraphDistribution[indegree, outdegree] For example: g = RandomGraph[ DegreeGraphDistribution[{1, 3, 3, 1, 2}, {3, 1, 3, 2, 1}]]; VertexInDegree[g] {1, 3, 3, 1, 2} VertexOutDegree[g] {3, 1, 3, 2, 1}


4

You can use ProbabilityDistribution to define your own probability distribution from a CDF: dist = ProbabilityDistribution[{"CDF", 1/2 Erfc[(0.1 - x)/(Sqrt[2] 1.2)]}, {x, -∞, ∞}] With some data data = RandomVariate[NormalDistribution[], 50]; you can now perform KolmogorovSmirnovTest[data, dist]


2

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 ...


2

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]], ...


2

As @belisarius comments, the answer is usually, No, you can't do things faster by-passing built-in functions. (Sometimes the answer is yes.) Here, with the particular distribution of the OP, one can do as well by getting the explicit formula and compiling it. d = ProbabilityDistribution[Piecewise[{{x/36, 0 <= x <= 6}, {(12 - x)/36, 6 < x <= ...


2

I should perhaps make this post a comment and not an answer. However, I wish to fully support the comments of @AndyRoss (and have +1 his answer). cas = Cases[list, {#, y_} :> y] & /@ Range[-2, 2]; ans = {Mean[#], Mean[(# - Mean[#])^2]} & /@ cas; Style[Prepend[ MapThread[Prepend[#1, #2] &, {ans, Range[-2, 2]}], {"x", "E[Y|X=x]", ...


2

This comes with several caveats: (1) It is also often slow. I have reason to believe it gets careless about certain "painted into a corner" situations, and thus might simply fail. (2) It gives results that are in no sense uniformly random, across the range of possible graphs that meet the requirements. (3) I wrote it some time ago and no longer understand ...


2

You can use igraph through my RLink-based package IGraphR. mat = Import["https://dl.dropboxusercontent.com/u/62056077/TestMatrix.m", "Package"]; mat == Transpose[mat] (* ==> False *) Your adjacency matrix is not symmetric. Are you looking for directed or undirected graphs? degs = Total[mat]; This degree sequence happens to be graphical, so let's ...


2

Not completely sure I'm understanding. Anyway, for Directed Graphs without self loops: randomDegreeGraph[m_List] := Module[{n, t, t1, obj, s, x}, n = Length@m; t = Table[If[i != j, x[i, j], Sequence @@ {}], {i, n}, {j, n}]; t1 = Table[If[i != j, x[i, j], 0], {i, n}, {j, n}]; obj = Transpose[{List /@ m, t}]; t1 /. ...



Only top voted, non community-wiki answers of a minimum length are eligible