Prev Up Next
Go backward to 5.6 User Defined Links and Distributions
Go up to 5 Advanced Topics and Examples
Go forward to 5.8 The Default Data Directory

5.7 Example: User Defined Distributions

Nelder and Pregibon [8] and McCullagh and Nelder [7], Chapter 9 discuss quasi-likelihood, where the complete error distribution need not be specified; all that is required is information about the first two moments (the mean and the variance). As an example, consider including a new distribution specified by the variance function 

V(µ)=µ4.  
This variance function defines one of the Tweedie family of distributions (defined in Tweedie [10]), sometimes called a positive stable distribution.

To incorporate such a distribution in glmlab, proceed as follows:

  1. The first step is to create a file that contains the pertinent information. Suppose that the file for the given variance function is called dfourpwr.m. (The d at the start of the file name is mandatory for defining new distributions; in a similar fashion, new link functions must be created in files that begin with an l.) The first step then is to create this file in the dist subdirectory of the fit directory (or the link subdirectory if a new link is being defined). The best way is to copy the file dstyle.m to dfourpwr.m. The file dstyle.m contains the template style for making new distributions (lstyle.m for new link functions).  
  2. The second step is to edit the file named dfourpwr.m using any text editor. Near the end of the file is a section with the following information:

     

    
    %Calculate
    if strcmp(what,'varfn'),
       %%%In here, you need lines to find the variance function
       %%%from  mu  and  y.
       %%%The section should return the variance function as  answ
    elseif strcmp(what,'scdev');
       %%%In here, you need lines to find the scaled deviance
       %%%from  mu  and  y.
       %%%The section should return the scaled deviance as  answ
    end;
    
    
     

    It should be clear that there are two sections to alter: One section requires information about the variance function, and the other about the deviance. For the variance function given in Equation (5.7), the MATLAB equivalent code is
      answ = mu .^ 4;
    This line should be entered into the section requiring information about the variance function. The deviance can be found from the integral

    D(y,µ)=-2INTyµ(y-u)/(V(u)) du,
    which, for the given variance function, is
    D=(1)/(6y2) + (y)/(3µ3)-(1)/(2µ2).
    The equivalent MATLAB code is
      answ=1/(6*y^2) + ( y./(3*mu.^3) ) - ( 1/(2*mu.^2) );
    This line of code is placed in the section requiring the deviance. Now glmlab has the information that it requires; it now needs to know to use the file dfourpwr.m.
  3. In the dist directory, there is a file called dlist.m which lists all the files that contain information about distributions. (There is a corresponding file llist.m for the link functions.) Add a new line to the end of this file that says only
    dfourpwr.m
  4. All the required tasks have been completed. Next time glmlab is started, there should be a distribution named fourpwr at the bottom of list of distributions.

A similar procedure is used for defining new link functions, but the corresponding files in the link subdirectory of the fit directory are used. Adding new distribution or link functions is not recommended unless the user knows the use of the distribution or link function, as odd results may eventuate otherwise.

 


Peter Dunn

Prev Up Next