Here's my function. If probKern is a Null, I want to return a Null, otherwise, I want to calculate the PDF for the sample, with the distribution. I can't quite get a handle on matching the types to make this work though.

Given two numbers, it produces the symbolic value, rather than the -1 I was expect. (The -1 is just a placeholder)

In[39]:= calcPDF[3, 3]
Out[39]= calcPDF[3, 3]

EDIT dec 5th:
Running calcPDF by hand seems to result in correct results, but now, when it is threaded over data, the result is a single result of whatever you return in the Except case. There's two sets of distributions I'm running over the sample data, so the final result is a list of two Nulls (or -1's).

If you remove the Except case, you get closer to the expected result - two lists 205 elements long, containing PDF's for entries with matching Distributions, and PDF[Null, value] for those without.

f[dist_, samp_]:=something[dist, samp] /; TrueQ[dist==DataDistribution] Seems to do the trick. if my function isn't passed a valid Data Distribution it falls through to the default case.
–
StevenDec 4 '12 at 22:01

Your question is a bit cryptic. Do you mean perhaps that you want to test whether dist is either a distribution that belongs to your null hypothesis or a DataDistribution? For comparing distributions we have DistributionFitTest.
–
Sjoerd C. de VriesDec 4 '12 at 22:01

Sorry, I'm looking to test whether dist is a DataDistribution or otherwise (I'm passing null myself). If it's a data distribution, I want to use it in a PDF. Otherwise, I want to pass on a Null value. as it stands when mathematica comes across the Null value, it passes on PDF[Null, some value].
–
StevenDec 4 '12 at 22:31

Steven, you can format blocks of code by selecting them and pressing the { } button above the text box while editor your post. See Editing Help for more.
–
Mr.Wizard♦Dec 5 '12 at 6:58

I believe your confusion comes from what == is doing in your checks. When you try dist == DataDistribution you are asking if a particular object dist is the symbol DataDistribution. What you really want to know is whether the Head of dist is DataDistribution.

Edit 2:

Lets say you wanted to use this approach to compute CDF for distributions returning -1 if the computation isn't possible. You could set this up as.

cdf[dist_?DistributionParameterQ, x_]:= CDF[dist,x]
cdf[_,x_]:= -1

If you want separate treatment for DataDistribution say you can do that as well. Here I'm telling it to report what type of distribution was used and return the expression and -1 if it isn't a distribution.

This is absolutely what I want to do. At a later time I'll be doing different things based on the distribution. But for now, just answering the question is this a distribution or not gets me 95% of the way there.
–
StevenDec 4 '12 at 22:39

I'm still having trouble with this. What you have looks like it should work, but in test cases it doesn't. I'm sure I'm misunderstanding something though.
–
StevenDec 5 '12 at 5:04

Is there any way to make a fallthrough for not a distribution, rather than matching specific types (like numericQ). I thought of matching Numeric, string, etc but that seemed like a hacky way to go.
–
StevenDec 5 '12 at 17:20

This is what I have in the end. It seems far too messy for what it should be. There's no negation in the type pattern matching available is there? Something like ?!DataDistribution? calcPDF[probKern_DataDistribution, samp_] := PDF[probKern, samp] calcPDF[probKern_?NumericQ, samp_] := -1 calcPDF[probKern_?StringQ, samp_] := -1 calcPDF[probKern_?ListQ, samp_] := -1
–
StevenDec 5 '12 at 18:28

Yes, that is too messy. If you want it to return -1 for anything that isn't a DataDistribution just replace your last 3 definitions with calcPDF[Except[_DataDistribution],samp_]:= -1.
–
Andy RossDec 5 '12 at 18:40

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.