Last data update: 2014.03.03

R: This function fits a GLD regression linear model
GLD.lmR Documentation

This function fits a GLD regression linear model

Description

Similar to lm, this function fits a linear model using RS/FKML GLDs and assess the goodness of fit of GLD with respect to the data via qq plot and Kolmogorov-Smirnoff test.

Usage

GLD.lm(formula, data, param, maxit = 20000, fun, method = "Nelder-Mead", 
diagnostics = TRUE, range = c(0.01, 0.99), init = NULL)

Arguments

formula

A symbolic expression of the model to be fitted, similar to the formula argument in lm, see formula for more information

data

Dataset containing variables of the model

param

Can be "rs", "fmkl" or "fkml"

maxit

Maximum number of iterations for numerical optimisation

fun

If param="fmkl" or "fkml", this can be one of fun.RMFMKL.ml.m, fun.RMFMKL.ml, for maximum likelihood estimation (*.ml.m is a faster implementation of *.ml) and fun.RMFMKL.lm for L moment matching.

If param="rs", this can be one of fun.RPRS.ml.m, fun.RPRS.ml, for maximum likelihood estimation (*.ml.m is a faster implementation of *.ml) and fun.RPRS.lm for L moment matching.

method

Defaults to "Nelder-Mead" algorithm, can also be "SANN" but this is a lot slower and may not as good

diagnostics

Defaults to TRUE, which computes Kolmogorov-Smirnoff test and do QQ plot

range

The is the quantile range to plot the QQ plot, defaults to 0.01 and 0.99 to avoid potential problems with extreme values of GLD which might be -Inf or Inf.

init

Choose a different set of initial values to start the optimisation process. This can either be full set of parameters including GLD parameter estimates, or it can just be the coefficient estimates of the regression model.

Value

Message

Short description of estimation method used and whether the result converged

Bias Correction

Bias correction used to ensure the line has zero mean residuals

Estimated parameters

A set of estimate coefficients from GLD regression

Fitted

Predicted response value from model

Residual

Residual of model

formula

Formula used in the model

param

Specify whether RS/FKML/FMKL GLD was used

y

The response variable

x

The explanatory variable(s)

fun

GLD fitting function used in the computation process, outputted for internal programming use

Author(s)

Steve Su

References

Su (2014) "Flexible Parametric Quantile Regression Model" Statistics & Computing

See Also

GLD.lm.full, GLD.quantreg

Examples


## Dummy example

library(GLDEX)

## Create dataset

set.seed(10)

x<-rnorm(200,3,2)
y<-3*x+rnorm(200)

dat<-data.frame(y,x)

## Fit a FKML GLD regression

example<-GLD.lm(y~x,data=dat,fun=fun.RMFMKL.ml.m,param="fkml")

## Not run: 

## Extract the Engel dataset 
library(quantreg)
data(engel)

## Fit GLD Regression
engel.fit<-GLD.lm(foodexp~income,data=engel,param="fmkl",fun=fun.RMFMKL.ml.m)

## Extract the mammals dataset 
library(MASS)

mammals.fit<-GLD.lm(log(brain)~log(body),data=mammals,param="rs",
fun=fun.RPRS.lm)

## Using quantile regression coefficients as starting values
library(quantreg)

mammals.fit1<-GLD.lm(log(brain)~log(body),data=mammals,param="rs",
fun=fun.RPRS.lm,init=rq(log(brain)~log(body),data=mammals)$coeff)

# As an exercise, use the result from mammals.fit1 as initial values

GLD.lm(log(brain)~log(body),data=mammals,param="rs",
fun=fun.RPRS.lm,init=mammals.fit1[[3]])

## End(Not run)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(GLDreg)
Loading required package: GLDEX
Loading required package: cluster
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/GLDreg/GLD.lm.Rd_%03d_medium.png", width=480, height=480)
> ### Name: GLD.lm
> ### Title: This function fits a GLD regression linear model
> ### Aliases: GLD.lm
> ### Keywords: model
> 
> ### ** Examples
> 
> 
> ## Dummy example
> 
> library(GLDEX)
> 
> ## Create dataset
> 
> set.seed(10)
> 
> x<-rnorm(200,3,2)
> y<-3*x+rnorm(200)
> 
> dat<-data.frame(y,x)
> 
> ## Fit a FKML GLD regression
> 
> example<-GLD.lm(y~x,data=dat,fun=fun.RMFMKL.ml.m,param="fkml")
     [,1]                                                                      
[1,] "This analysis was carried out using FKML GLD"                            
[2,] "The error distribution was estimated using Maximum Likelihood Estimation"
[3,] "The optimisation procedure used was Nelder-Mead and it has converged"    
(Intercept)           x          L1          L2          L3          L4 
 0.05895140  3.01981005 -0.01457362  1.29930852  0.22981644  0.20182903 
> 
> ## Not run: 
> ##D 
> ##D ## Extract the Engel dataset 
> ##D library(quantreg)
> ##D data(engel)
> ##D 
> ##D ## Fit GLD Regression
> ##D engel.fit<-GLD.lm(foodexp~income,data=engel,param="fmkl",fun=fun.RMFMKL.ml.m)
> ##D 
> ##D ## Extract the mammals dataset 
> ##D library(MASS)
> ##D 
> ##D mammals.fit<-GLD.lm(log(brain)~log(body),data=mammals,param="rs",
> ##D fun=fun.RPRS.lm)
> ##D 
> ##D ## Using quantile regression coefficients as starting values
> ##D library(quantreg)
> ##D 
> ##D mammals.fit1<-GLD.lm(log(brain)~log(body),data=mammals,param="rs",
> ##D fun=fun.RPRS.lm,init=rq(log(brain)~log(body),data=mammals)$coeff)
> ##D 
> ##D # As an exercise, use the result from mammals.fit1 as initial values
> ##D 
> ##D GLD.lm(log(brain)~log(body),data=mammals,param="rs",
> ##D fun=fun.RPRS.lm,init=mammals.fit1[[3]])
> ## End(Not run)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>