function retRes = Ex4gPOCREPath(inPType)
%function retRes = Ex4gPOCREPath(inPType)

% An example to show how to use gPOCRE to analyze simglmdata.txt with the
% tuning parameter chosen by EBIC.
%
% Input:
%   inPType -- type of penalization:
%            'ebtz' ~ EBT w/ z-transformation (by default),
%            'ebt' ~ EBT w/o z-transformation,
%            'l1' ~ L1,
%            'scad' ~ SCAD (with gamma=3.7),
%            'mcp' ~ MCP (with gamma=3.7).
%
% Dabao Zhang     August 2, 2014
%
% Revised by:
%
% Copyright (c) 2013-2014 by Zhang.

if( nargin<1 ) inPType='ebtz'; end

YX = load('simglmdata.txt');

% Standardization is unnecessary if there are no constant covariates.
% Otherwise, output X from Standardize(...) exclude constant covariates.
[X,idxX] = Standardize(YX(:,2:end));    % Standardizing all covariates

% Settings:
option.delta = 0.05;        % 0.1,0.05,0.02, or 0.01
option.covidx = [15 16];    % covariates of no interest
option.ptype = inPType;

%-------------------------------------------------------------
% Use EBIC to Choose Tuning Parameter
%-------------------------------------------------------------
retRes = gPOCREPath(YX(:,1),X,'binomial','logit',option);
save('simglmdatares.mat','retRes');

% msc in (0,1]: EBIC (Chen & Chen, 2010),
resp25 = SelectModel(retRes,0.25);
disp(['EBIC(gamma=0.25): #[beta~=0] = ' num2str(sum(abs(resp25.beta)>0))]);
disp(['p-values of components:' num2str(resp25.pvalue')]);
disp(['Sequential p-values of components:' num2str(resp25.seqpv')]);
disp(['p-values of individual components:' num2str(resp25.indpv')]);

% Plot lambda vs. (R^2, #[beta~=0])
plotrsqnzbeta(retRes);

% Plot lambda vs. (beta, R^2)
plotbetarsq(retRes);

% Plot lambda vs. (beta, #[beta~=0])
plotbetanzbeta(retRes);

% Plot all components:
plotcomponents(resp25);
