Tips and Tricks

Once you have completed the Introduction to DSC, you should be ready to write your own DSC.

This file introduces you to some of the most convenient syntax short-cuts we have implemented to make DSCs easier to write and read.

Combining definitions of similar modules

Sometimes modules share much of their definition. For example:

mean: R(y = mean(x))
  x: $data
  $est_mean: y

median: R(y = median(x))
  x: $data
  $est_mean: y

Here DSC allows a shorthand syntax to define both modules:

mean, median: R(y = mean(x)), R(y=median(x))
  x: $data
  $est_mean: y

Aliasing

Renaming a parameter

This feature allows one to use a different name for a parameter than is used in a script. For example:

t: R( y = rt(m, df=2))
  n: 100, 1000
  $data: y
  $true_mean: 3
  @ALIAS: m = n

This defines a module with parameter n, and the ALIAS command tells DSC to pass the parameter value to the script variable m (rather than the default, which is to pass it to the script variable of the same name as the parameter).

This can be useful when you want two different modules to have the same parameter names, even when the scripts use different script variables.

Module inheritance

Syntax module(base_module) allows constructing a module by first inheriting from a base_module, ie, another module very similar to the new module to be created, then modify it by re-defining its input, parameters and / or output to create the new module. For example the code below creates a new module called shifted_normal based on a normal module but set mu: 1 to override mu: 0 in the original module to “shift” the mean of the distribution:

normal: R( x = mu + rnorm(n) )
  n: 100, 1000
  mu: 0
  $data: x
  $true_mean: mu

shifted_normal(normal):
  mu: 1