You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: spm_mar_prior.m
    path of file: ./repos/spm12/toolbox/spectral
    
    the code of the file until where you have to start completion: function [prior] = spm_mar_prior (d,p,type)

    
function [prior] = spm_mar_prior (d,p,type)
% Specify ARD-type prior for Bayesian MAR model
% function [prior] = spm_mar_prior (d,p,type)
%
% d         Number of time series
% p         Order of MAR model
% type      'global', 'lag','interaction','lag-inter',
%           'silly','ran2','triu' (see code below)
%
% prior     data structure to be passed to spm_mar.m
%___________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Will Penny 
% $Id: spm_mar_prior.m 1143 2008-02-07 19:33:33Z spm $

k=p*d*d;
switch type,
    case 'global',
        prior.type='global';
        prior.groups=1;
        prior.group(1).index=ones(k,1);
    case 'ran2',
        % Randomly group together weights into 2 groups
        k1=floor(k/2);
        prior.type='ran2';
        prior.groups=2;
        Ij=randperm(k);
        prior.group(1).index=zeros(k,1);
        prior.group(1).index(Ij(1:k1))=ones(1,k/2);
        prior.group(2).index=zeros(k,1);
        prior.group(2).index(Ij(k1+1:k))=ones(1,k/2);
    case 'silly',
        % Randomly group together 2 weights
        prior.type='silly';
        prior.groups=k/2;
        Ij=randperm(k);
        for j=1:k/2,
            prior.group(j).index=zeros(k,1);
            prior.group(j).index(Ij(j))=1;
            prior.group(j).index(Ij(j+k/2))=1;
        end