3
$\begingroup$

I wonder whats the best way to visualize a formula (code for R would be nice, but the question is more general about what to visualize)

The formula (a stochastic distribution function) takes two arguments, a and b, and the result is mainly based on the three terms, relying on three variables and the two arguments of the function

I tried by plotting 2D (as shown below, but this does not help much), my next approach would be a 3d plot with x,y representing a and b, while z showing the result, colored by the relative value of the three variables for r/b/g... is this a good approch? Or is there a better way to get am impression how the variables have impact on the result?

a <- c(seq(0.1, 10, by=0.1)) 
b <- c(seq(0.1, 2, by=0.1)) 
var1 <- 0.1
var2 <- 0.1
var3 <- 0.1

myF <- function(a,b){ 
    if (a==0) return (0)
    if (b==0) return (0)
    term1 =  exp(1) ^ ( -1* ( var1 + var3 ) * a )   
    term2 =  exp(1) ^ ( -1* ( var2 + var3 ) * b )
    term3 =  exp(1) ^ ( -1*  var1 * a - var2 * b  - var3 * max(a ,b ))   
    return ( 1- term1 - term2 + term3) 
    }
par(mfrow=c(3,3))
for (var1 in c(1,2,3)) {  
    for (var2 in c(1,2,3)) {
        var3=0
        myFV <- Vectorize(myF)(a,b)
        main = substitute(   paste( "var1: ", var1, " var2: ", var2 , " var3: " , var3),    list(var1 = var1, var2 = var2, var3=var3))
        xlab = "a:0.1 .. 10, b: 0.1 .. 2"
        plot(myFV,  xlab=xlab, ylab="", main=main)
    }
}
$\endgroup$
4
  • $\begingroup$ This is a good question but it might be better suited for Math.SE $\endgroup$ Commented Jan 10, 2015 at 5:55
  • 2
    $\begingroup$ actualy the function is a stochastic distribution function, therefor I thought it fits here best, but if you or somebody peferes to move it: please go ahead, I dont know how to do it - thanks in advance $\endgroup$ Commented Jan 10, 2015 at 6:10
  • 1
    $\begingroup$ You should edit that into your question. Someone might have a more targeted suggestion for you. $\endgroup$ Commented Jan 10, 2015 at 6:12
  • $\begingroup$ I wonder if this question would make more sense in the context of a stats website, if it was titled as "How to visualize impact of parameters on a distribution?" It seems to me that the "variables" (in the programming sense) a and b essentially correspond to distribution parameters, while var1 to var3 are the variables whose distribution is being modelled. $\endgroup$
    – Silverfish
    Commented Jan 12, 2015 at 15:21

1 Answer 1

4
$\begingroup$

One way to show how a function varies as you change two parameters is using a trellis chart (also known as "lattice", "grid", "panel" or by Tufte's term, "small multiples"). The rows and columns show the possible values of the two parameters, and the grid allows you to see how their effects on your distribution interact.

The graph below is one such example, best viewed at full-size, that I posted with R code (using facet_grid in ggplot2, see documentation) in an answer to a question about the distribution of the sample $R^2$ for a multiple regression when the population slope coefficients are all zero. In this situation, a linear model was being fitted to normally distributed data with constant mean (so that if $R^2$ had been calculated for the whole population it would be zero) and the sample $R^2$ has a distribution whose density function depends on $k$, the number of fitted parameters in the regression model (varying across the columns) and $n$, the sample size (varying across the rows).

Distribution of R2 for small sample sizes

Note that this was a univariate distribution, so that for any given $n$ and $k$, the probability density (on the vertical axis) was a function of $R^2$ alone (on the horizontal axis). What if we have a function of more than one variable? This means that a solution in ggplot2 is no longer viable, since that package can only handle two-dimensional plots. Other R packages allow you to plot 3D charts with multiple facets, though.

For what the results might look like, there is an example in the (open access) article: Azmeri Khan and Glen D. Rayner, "Robustness to non-normality of common tests for the many-sample location problem," Journal of Applied Mathematics and Decision Sciences, vol. 7, no. 4, pp. 187-206, 2003. doi:10.1155/S1173912603000178

In Figure 1 they show how the g-and-k distribution varies for various values of the skewness parameter $g$ and the kurtosis parameter $k$, in a similar way to my plot above. But in Figure 2 they illustrate various different power surfaces for an ANOVA test applied to non-normal data drawn from a g-and-k distribution: the power surfaces are faceted by the $g$ and $k$ values illustrated in Figure 1. So the underlying distributions shown in Figure 1, produce a power surface in the corresponding facet of Figure 2. The power surfaces are 3D plots because they show how power varies across changes to the group means $\mu_1$ and $\mu_2$. The graphs make more sense in the context of the original paper, which is quite straightforward to read, but if you want to understand the visualization I will include both figures in my answer (the authors released the article under a Creative Commons Attribution license).

Khan and Rayner g-and-k distributions Khan and Rayner ANOVA power surfaces over g-and-k distributions

It seems that the function you want to plot actually depends on three variables (which you have listed as var1, var2 and var3) and you want to see how that function changes as you vary a and b. This is a harder challenge; for each facet you need to consider how to visualize 4-dimensional data.

In fact Khan and Rayner had a similar issue, as they wanted to show how the power curves varied with sample size as well as with $g$ and $k$. The way they achieved this was to use the same sample size for each trellis chart, but then produce different charts to show the effect of changing sample sizes. Figure 2 had $n=3$, Figure 3 had $n=5$ and Figure 4 had $n=15$. This effectively let them panel a function of two variables (power as a function of $\mu_1$ and $\mu_2$) by three other variables ($g$, $k$ and $n$). Your issue is subtly different as you have a function of three variables which you would ideally like to panel by $a$ and $b$, but adopting a variant of their approach is one option available to you.

As a separate issue: you seem to be trying to plot a multivariate cumuluative distribution function. I wonder whether you'd find it more informative to plot the probability density instead.

$\endgroup$
1
  • $\begingroup$ Thanks you for the informative answer (not enough reputation to upvote yet) $\endgroup$ Commented Jan 11, 2015 at 4:09

Your Answer

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

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