diff --git a/dev/api/bayesian_regression/index.html b/dev/api/bayesian_regression/index.html index b0ff3be..d4c7ea1 100644 --- a/dev/api/bayesian_regression/index.html +++ b/dev/api/bayesian_regression/index.html @@ -1,5 +1,5 @@ -Bayesian Regression Models · CRRao.jl

Bayesian Regression Models

CRRao.BayesianRegressionType
BayesianRegression{RegressionType}

Type to represent bayesian regression models returned by fit functions. This type is used internally by the package to represent all bayesian regression models. RegressionType is a Symbol representing the model class.

source

Linear Regression

Linear Regression with User Specific Gaussian Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LinearRegression, prior::Prior_Gauss, alpha_prior_mean::Float64, alpha_prior_sd::Float64, beta_prior_mean::Vector{Float64}, beta_prior_sd::Vector{Float64}, sim_size::Int64 = 1000)

Fit a Bayesian Linear Regression model on the input data with a Gaussian prior with user specific prior mean and sd for α and β.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+Bayesian Regression Models · CRRao.jl

Bayesian Regression Models

CRRao.BayesianRegressionType
BayesianRegression{RegressionType}

Type to represent bayesian regression models returned by fit functions. This type is used internally by the package to represent all bayesian regression models. RegressionType is a Symbol representing the model class.

source

Linear Regression

Linear Regression with User Specific Gaussian Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LinearRegression, prior::Prior_Gauss, alpha_prior_mean::Float64, alpha_prior_sd::Float64, beta_prior_mean::Vector{Float64}, beta_prior_sd::Vector{Float64}, sim_size::Int64 = 1000)

Fit a Bayesian Linear Regression model on the input data with a Gaussian prior with user specific prior mean and sd for α and β.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> df = dataset("datasets", "mtcars");  
 julia> CRRao.set_rng(StableRNG(123));                                                                                             
 julia> container = fit(@formula(MPG ~ HP + WT + Gear), df, LinearRegression(), Prior_Gauss(),30.0,10.0,[0.0,-3.0,1.0],[0.1,1.0,1.0],1000)
@@ -33,7 +33,7 @@
         β[1]   24.9976   29.6654   31.4881   33.5860   37.6309
         β[2]   -0.0546   -0.0430   -0.0373   -0.0311   -0.0200
         β[3]   -4.2471   -3.5287   -3.1438   -2.7626   -1.9238
-        β[4]   -0.0285    0.7312    1.0926    1.4948    2.1519
source

Linear Regression with Ridge Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LinearRegression, prior::Prior_Ridge, h::Float64 = 0.01, sim_size::Int64 = 1000)

Fit a Bayesian Linear Regression model on the input data with a Ridge prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+        β[4]   -0.0285    0.7312    1.0926    1.4948    2.1519
source

Linear Regression with Ridge Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LinearRegression, prior::Prior_Ridge, h::Float64 = 0.01, sim_size::Int64 = 1000)

Fit a Bayesian Linear Regression model on the input data with a Ridge prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> df = dataset("datasets", "mtcars")
 32×12 DataFrame
  Row │ Model              MPG      Cyl    Disp     HP     DRat     WT       QSec     VS     AM     Gear   Carb  
@@ -84,7 +84,7 @@
         β[1]   17.0694   25.0878   28.6635   32.2368   39.1438
         β[2]   -0.0594   -0.0462   -0.0398   -0.0327   -0.0198
         β[3]   -4.5435   -3.3350   -2.6938   -2.1350   -0.7247
-        β[4]   -0.2647    0.9636    1.5983    2.2412    3.6841
source

Linear Regression with Laplace Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LinearRegression, prior::Prior_Laplace, h::Float64 = 0.01, sim_size::Int64 = 1000)

Fit a Bayesian Linear Regression model on the input data with a Laplace prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+        β[4]   -0.2647    0.9636    1.5983    2.2412    3.6841
source

Linear Regression with Laplace Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LinearRegression, prior::Prior_Laplace, h::Float64 = 0.01, sim_size::Int64 = 1000)

Fit a Bayesian Linear Regression model on the input data with a Laplace prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> df = dataset("datasets", "mtcars")
 32×12 DataFrame
  Row │ Model              MPG      Cyl    Disp     HP     DRat     WT       QSec     VS     AM     Gear   Carb  
@@ -133,7 +133,7 @@
         β[1]   17.7583   25.3061   28.8668   32.2456   38.1808
         β[2]   -0.0615   -0.0469   -0.0398   -0.0329   -0.0187
         β[3]   -4.4721   -3.3004   -2.7042   -2.0441   -0.7107
-        β[4]   -0.1806    0.8682    1.5224    2.1637    3.6193
source

Linear Regression with Cauchy Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LinearRegression, prior::Prior_Cauchy, sim_size::Int64 = 1000)

Fit a Bayesian Linear Regression model on the input data with a Cauchy prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+        β[4]   -0.1806    0.8682    1.5224    2.1637    3.6193
source

Linear Regression with Cauchy Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LinearRegression, prior::Prior_Cauchy, sim_size::Int64 = 1000)

Fit a Bayesian Linear Regression model on the input data with a Cauchy prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> df = dataset("datasets", "mtcars")
 32×12 DataFrame
  Row │ Model              MPG      Cyl    Disp     HP     DRat     WT       QSec     VS     AM     Gear   Carb  
@@ -181,7 +181,7 @@
         β[1]   20.5220   26.8878   30.1467   33.4241   38.9193
         β[2]   -0.0600   -0.0454   -0.0400   -0.0334   -0.0192
         β[3]   -4.4784   -3.3625   -2.8345   -2.2815   -1.1017
-        β[4]   -0.2688    0.6897    1.3047    1.8932    3.0914
source

Linear Regression with T-distributed Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LinearRegression, prior::Prior_TDist, h::Float64 = 2.0, sim_size::Int64 = 1000)

Fit a Bayesian Linear Regression model on the input data with a t(ν) distributed prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsPlots, StatsModels
+        β[4]   -0.2688    0.6897    1.3047    1.8932    3.0914
source

Linear Regression with T-distributed Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LinearRegression, prior::Prior_TDist, h::Float64 = 2.0, sim_size::Int64 = 1000)

Fit a Bayesian Linear Regression model on the input data with a t(ν) distributed prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsPlots, StatsModels
 julia> df = dataset("datasets", "mtcars")
 32×12 DataFrame
  Row │ Model              MPG      Cyl    Disp     HP     DRat     WT       QSec     VS     AM     Gear   Carb  
@@ -233,7 +233,7 @@
         β[3]   -4.3684   -3.3394   -2.8206   -2.2711   -1.0594
         β[4]   -0.2602    0.7464    1.3014    1.8909    3.1216
         
-julia> plot(container.chain)
source

Linear Regression with Horse Shoe Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm,data::DataFrame,modelClass::LinearRegression,prior::Prior_HorseShoe,sim_size::Int64 = 1000)

Fit a Bayesian Linear Regression model on the input data with a HorseShoe prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsPlots, StatsModels
+julia> plot(container.chain)
source

Linear Regression with Horse Shoe Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm,data::DataFrame,modelClass::LinearRegression,prior::Prior_HorseShoe,sim_size::Int64 = 1000)

Fit a Bayesian Linear Regression model on the input data with a HorseShoe prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsPlots, StatsModels
 julia> df = dataset("datasets", "mtcars");                                                                                                 
 julia> CRRao.set_rng(StableRNG(123));
 julia> container = fit(@formula(MPG ~ HP + WT + Gear), df, LinearRegression(), Prior_HorseShoe())
@@ -279,7 +279,7 @@
         β[3]   -4.7741   -3.6626   -3.1250   -2.5222   -1.0155
         β[4]   -0.3640    0.3357    0.8594    1.4728    2.8541
 
-julia> plot(container.chain)
source

Logistic Regression

Logistic Regression with Ridge Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LogisticRegression, Link::CRRaoLink, prior::Prior_Ridge, h::Float64 = 0.1, level::Float64 = 0.95, sim_size::Int64 = 1000)

Fit a Bayesian Logistic Regression model on the input data with a Ridge prior with the provided Link function.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+julia> plot(container.chain)
source

Logistic Regression

Logistic Regression with Ridge Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LogisticRegression, Link::CRRaoLink, prior::Prior_Ridge, h::Float64 = 0.1, level::Float64 = 0.95, sim_size::Int64 = 1000)

Fit a Bayesian Logistic Regression model on the input data with a Ridge prior with the provided Link function.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> turnout = dataset("Zelig", "turnout")
 2000×5 DataFrame
   Row │ Race   Age    Educate  Income   Vote  
@@ -437,7 +437,7 @@
         β[3]   -0.1352    0.0549    0.1552    0.2700    0.4495
         β[4]    0.1679    0.2128    0.2384    0.2667    0.3222
         β[5]    0.1142    0.1420    0.1580    0.1754    0.2121
-
source

Logistic Regression with Laplace Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LogisticRegression, Link::CRRaoLink, prior::Prior_Laplace, h::Float64 = 0.1, level::Float64 = 0.95, sim_size::Int64 = 1000)

Fit a Bayesian Logistic Regression model on the input data with a Laplace prior with the provided Link function.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+
source

Logistic Regression with Laplace Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LogisticRegression, Link::CRRaoLink, prior::Prior_Laplace, h::Float64 = 0.1, level::Float64 = 0.95, sim_size::Int64 = 1000)

Fit a Bayesian Logistic Regression model on the input data with a Laplace prior with the provided Link function.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> CRRao.set_rng(StableRNG(123))
 StableRNGs.LehmerRNG(state=0x000000000000000000000000000000f7)
 julia> turnout = dataset("Zelig", "turnout")
@@ -590,7 +590,7 @@
         β[2]    0.0210    0.0260    0.0293    0.0319    0.0380
         β[3]   -0.1352    0.0447    0.1375    0.2297    0.4357
         β[4]    0.1680    0.2130    0.2378    0.2663    0.3196
-        β[5]    0.1178    0.1461    0.1615    0.1769    0.2070     
source

Logistic Regression with Cauchy Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LogisticRegression, Link::CRRaoLink, prior::Prior_Cauchy, h::Float64 = 0.1, level::Float64 = 0.95, sim_size::Int64 = 1000)

Fit a Bayesian Logistic Regression model on the input data with a Cauchy prior with the provided Link function.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+        β[5]    0.1178    0.1461    0.1615    0.1769    0.2070     
source

Logistic Regression with Cauchy Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LogisticRegression, Link::CRRaoLink, prior::Prior_Cauchy, h::Float64 = 0.1, level::Float64 = 0.95, sim_size::Int64 = 1000)

Fit a Bayesian Logistic Regression model on the input data with a Cauchy prior with the provided Link function.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> CRRao.set_rng(StableRNG(123))
 StableRNGs.LehmerRNG(state=0x000000000000000000000000000000f7)
 julia> turnout = dataset("Zelig", "turnout")
@@ -738,7 +738,7 @@
         β[2]    0.0211    0.0270    0.0301    0.0329    0.0384
         β[3]   -0.1105    0.0282    0.1117    0.2168    0.3907
         β[4]    0.1603    0.2064    0.2324    0.2627    0.3157
-        β[5]    0.1166    0.1501    0.1669    0.1839    0.2152
source

Logistic Regression with T-Distributed Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LogisticRegression, Link::CRRaoLink, prior::Prior_TDist, h::Float64 = 1.0, level::Float64 = 0.95, sim_size::Int64 = 1000)

Fit a Bayesian Logistic Regression model on the input data with a T-Dist prior with the provided Link function.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+        β[5]    0.1166    0.1501    0.1669    0.1839    0.2152
source

Logistic Regression with T-Distributed Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LogisticRegression, Link::CRRaoLink, prior::Prior_TDist, h::Float64 = 1.0, level::Float64 = 0.95, sim_size::Int64 = 1000)

Fit a Bayesian Logistic Regression model on the input data with a T-Dist prior with the provided Link function.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> CRRao.set_rng(StableRNG(123))
 StableRNGs.LehmerRNG(state=0x000000000000000000000000000000f7)
 julia> turnout = dataset("Zelig", "turnout")
@@ -911,7 +911,7 @@
         β[2]    0.0218    0.0271    0.0300    0.0330    0.0388
         β[3]   -0.1336    0.0643    0.1646    0.2552    0.4311
         β[4]    0.1592    0.2092    0.2368    0.2650    0.3271
-        β[5]    0.1218    0.1508    0.1661    0.1819    0.2157
source

Logistic Regression with Horse Shoe Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm,data::DataFrame,modelClass::LogisticRegression,Link::CRRaoLink,prior::Prior_HorseShoe,level::Float64 = 0.95,sim_size::Int64 = 1000)

Fit a Bayesian Logistic Regression model on the input data with a HorseShoe prior with the provided Link function.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+        β[5]    0.1218    0.1508    0.1661    0.1819    0.2157
source

Logistic Regression with Horse Shoe Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm,data::DataFrame,modelClass::LogisticRegression,Link::CRRaoLink,prior::Prior_HorseShoe,level::Float64 = 0.95,sim_size::Int64 = 1000)

Fit a Bayesian Logistic Regression model on the input data with a HorseShoe prior with the provided Link function.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> turnout = dataset("Zelig", "turnout");
 julia> CRRao.set_rng(StableRNG(7740))
 julia> container_logit = fit(@formula(Vote ~ Age + Race + Income + Educate), turnout, LogisticRegression(), Logit(), Prior_HorseShoe())
@@ -1098,7 +1098,7 @@
         β[3]   -0.1005    0.0049    0.0767    0.1826    0.4019
         β[4]    0.1614    0.2127    0.2382    0.2638    0.3140
         β[5]    0.1201    0.1472    0.1657    0.1804    0.2148
-
source

Negative Binomial Regression

Negative Binomial Regression with Ridge Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::NegBinomRegression, prior::Prior_Ridge, h::Float64 = 0.1, sim_size::Int64 = 1000)

Fit a Bayesian Negative Binomial Regression model on the input data with a Ridge prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+
source

Negative Binomial Regression

Negative Binomial Regression with Ridge Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::NegBinomRegression, prior::Prior_Ridge, h::Float64 = 0.1, sim_size::Int64 = 1000)

Fit a Bayesian Negative Binomial Regression model on the input data with a Ridge prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> sanction = dataset("Zelig", "sanction")
 78×8 DataFrame
  Row │ Mil    Coop   Target  Import  Export  Cost   Num    NCost         
@@ -1170,7 +1170,7 @@
 0.9868233460913254
 24.39047761169405
 1.1542620442281972
-8.219200484970807
source

Negative Binomial Regression with Laplace Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::NegBinomRegression, prior::Prior_Laplace, h::Float64 = 0.01, sim_size::Int64 = 1000)

Fit a Bayesian Negative Binomial Regression model on the input data with a Laplace prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+8.219200484970807
source

Negative Binomial Regression with Laplace Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::NegBinomRegression, prior::Prior_Laplace, h::Float64 = 0.01, sim_size::Int64 = 1000)

Fit a Bayesian Negative Binomial Regression model on the input data with a Laplace prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> sanction = dataset("Zelig", "sanction")
 78×8 DataFrame
  Row │ Mil    Coop   Target  Import  Export  Cost   Num    NCost         
@@ -1242,7 +1242,7 @@
 1.0011451666062938
 23.744012407689187
 1.1547110091441486
-8.611185000528977
source

Negative Binomial Regression with Cauchy Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::NegBinomRegression, prior::Prior_Cauchy, h::Float64 = 1.0, sim_size::Int64 = 1000)

Fit a Bayesian Negative Binomial Regression model on the input data with a Cauchy prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+8.611185000528977
source

Negative Binomial Regression with Cauchy Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::NegBinomRegression, prior::Prior_Cauchy, h::Float64 = 1.0, sim_size::Int64 = 1000)

Fit a Bayesian Negative Binomial Regression model on the input data with a Cauchy prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> sanction = dataset("Zelig", "sanction")
 78×8 DataFrame
  Row │ Mil    Coop   Target  Import  Export  Cost   Num    NCost         
@@ -1299,7 +1299,7 @@
         β[4]   -1.1899   -0.5662   -0.1798    0.1778    0.9467
         β[5]    0.6384    1.0495    1.2673    1.4884    1.9266
         β[6]   -0.4275   -0.0388    0.1676    0.3465    0.7206
-
source

Negative Binomial Regression with T-Distributed Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::NegBinomRegression, prior::Prior_TDist, h::Float64 = 1.0, sim_size::Int64 = 1000)

Fit a Bayesian Negative Binomial Regression model on the input data with a t(ν) distributed prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+
source

Negative Binomial Regression with T-Distributed Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::NegBinomRegression, prior::Prior_TDist, h::Float64 = 1.0, sim_size::Int64 = 1000)

Fit a Bayesian Negative Binomial Regression model on the input data with a t(ν) distributed prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> sanction = dataset("Zelig", "sanction")
 78×8 DataFrame
  Row │ Mil    Coop   Target  Import  Export  Cost   Num    NCost         
@@ -1354,7 +1354,7 @@
         β[4]   -1.2265   -0.5194   -0.1622    0.2064     0.8424
         β[5]    0.6213    1.0451    1.2792    1.4909     1.8955
         β[6]   -0.4084   -0.0453    0.1477    0.3433     0.7080
-
source

Negative Binomial Regression with HorseShoe Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm,data::DataFrame,modelClass::NegBinomRegression,prior::Prior_HorseShoe,sim_size::Int64 = 1000)

Fit a Bayesian Negative Binomial Regression model on the input data with a HorseShoe prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsPlots, StatsModels
+
source

Negative Binomial Regression with HorseShoe Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm,data::DataFrame,modelClass::NegBinomRegression,prior::Prior_HorseShoe,sim_size::Int64 = 1000)

Fit a Bayesian Negative Binomial Regression model on the input data with a HorseShoe prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsPlots, StatsModels
 julia> sanction = dataset("Zelig", "sanction");
 julia> CRRao.set_rng(StableRNG(123))
 julia> container = fit(@formula(Num ~ Target + Coop + NCost), sanction, NegBinomRegression(), Prior_HorseShoe())
@@ -1406,7 +1406,7 @@
         β[3]    0.7268    0.8657    0.9770    1.0755    1.2406
         β[4]   -0.9419   -0.2720   -0.0234    0.1072    0.6187
         β[5]    0.6108    1.0708    1.2936    1.5336    1.8016
-        β[6]   -0.3937   -0.1448   -0.0029    0.1130    0.4378
source

Poisson Regression

Poisson Regression with Ridge Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::PoissonRegression, prior::Prior_Ridge, h::Float64 = 0.1, sim_size::Int64 = 1000)

Fit a Bayesian Poisson Regression model on the input data with a Ridge prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+        β[6]   -0.3937   -0.1448   -0.0029    0.1130    0.4378
source

Poisson Regression

Poisson Regression with Ridge Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::PoissonRegression, prior::Prior_Ridge, h::Float64 = 0.1, sim_size::Int64 = 1000)

Fit a Bayesian Poisson Regression model on the input data with a Ridge prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> sanction = dataset("Zelig", "sanction")
 78×8 DataFrame
  Row │ Mil    Coop   Target  Import  Export  Cost   Num    NCost         
@@ -1479,7 +1479,7 @@
     23.451157821412178
     1.0317165509592108
     5.726972543900231
-        
source

Poisson Regression with Laplace Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::PoissonRegression, prior::Prior_Laplace, h::Float64 = 0.1, sim_size::Int64 = 1000)

Fit a Bayesian Poisson Regression model on the input data with a Laplace prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+        
source

Poisson Regression with Laplace Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::PoissonRegression, prior::Prior_Laplace, h::Float64 = 0.1, sim_size::Int64 = 1000)

Fit a Bayesian Poisson Regression model on the input data with a Laplace prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> sanction = dataset("Zelig", "sanction")
 78×8 DataFrame
  Row │ Mil    Coop   Target  Import  Export  Cost   Num    NCost         
@@ -1549,7 +1549,7 @@
     0.7892315194893381
     23.288584913402246
     1.0177004055294072
-    5.759286021571133
source

Poisson Regression with Cauchy Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LinearRegression, prior::Prior_Cauchy, h::Float64 = 1.0, sim_size::Int64 = 1000)

Fit a Bayesian Poisson Regression model on the input data with a Cauchy prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+    5.759286021571133
source

Poisson Regression with Cauchy Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::LinearRegression, prior::Prior_Cauchy, h::Float64 = 1.0, sim_size::Int64 = 1000)

Fit a Bayesian Poisson Regression model on the input data with a Cauchy prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> sanction = dataset("Zelig", "sanction")
 78×8 DataFrame
  Row │ Mil    Coop   Target  Import  Export  Cost   Num    NCost         
@@ -1601,7 +1601,7 @@
         β[3]    1.0131    1.0925    1.1303    1.1680    1.2368
         β[4]   -0.7701   -0.4356   -0.2757   -0.1448    0.1045
         β[5]    1.5159    1.6388    1.7020    1.7689    1.9046
-        β[6]    0.0738    0.2632    0.3881    0.5176    0.7230
source

Poisson Regression with T-Distributed Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::PoissonRegression, prior::Prior_TDist, h::Float64 = 2.0, sim_size::Int64 = 1000)

Fit a Bayesian Poisson Regression model on the input data with a t(ν) distributed prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+        β[6]    0.0738    0.2632    0.3881    0.5176    0.7230
source

Poisson Regression with T-Distributed Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm, data::DataFrame, modelClass::PoissonRegression, prior::Prior_TDist, h::Float64 = 2.0, sim_size::Int64 = 1000)

Fit a Bayesian Poisson Regression model on the input data with a t(ν) distributed prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> CRRao.set_rng(StableRNG(123))
 StableRNGs.LehmerRNG(state=0x000000000000000000000000000000f7)
 julia> sanction = dataset("Zelig", "sanction")
@@ -1657,7 +1657,7 @@
         β[3]    1.0322    1.0932    1.1310    1.1688    1.2362
         β[4]   -0.7680   -0.4694   -0.3020   -0.1519    0.1128
         β[5]    1.5030    1.6252    1.7037    1.7682    1.8936
-        β[6]    0.0701    0.2710    0.3911    0.5023    0.7236
source

Poisson Regression with Horse Shoe Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm,data::DataFrame,modelClass::PoissonRegression,prior::Prior_HorseShoe,sim_size::Int64 = 1000)

Fit a Bayesian Poisson Regression model on the input data with a Horse Shoe prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
+        β[6]    0.0701    0.2710    0.3911    0.5023    0.7236
source

Poisson Regression with Horse Shoe Prior

StatsAPI.fitFunction
fit(formula::FormulaTerm,data::DataFrame,modelClass::PoissonRegression,prior::Prior_HorseShoe,sim_size::Int64 = 1000)

Fit a Bayesian Poisson Regression model on the input data with a Horse Shoe prior.

Example

julia> using CRRao, RDatasets, StableRNGs, StatsModels
 julia> sanction = dataset("Zelig", "sanction");
 julia> CRRao.set_rng(StableRNG(123))
 julia> container = fit(@formula(Num ~ Target + Coop + NCost), sanction, PoissonRegression(), Prior_HorseShoe())
@@ -1709,4 +1709,4 @@
         β[5]    1.4992    1.6387    1.7051    1.7718    1.9102
         β[6]    0.0305    0.2485    0.3763    0.4911    0.7002
 julia> using StatsPlots
-julia> plot(container.chain)
source
+julia> plot(container.chain)
source
diff --git a/dev/api/frequentist_regression/index.html b/dev/api/frequentist_regression/index.html index ff07e84..bfca559 100644 --- a/dev/api/frequentist_regression/index.html +++ b/dev/api/frequentist_regression/index.html @@ -1,5 +1,5 @@ -Frequentist Regression Models · CRRao.jl

Frequentist Regression Models

CRRao.FrequentistRegressionType
FrequentistRegression{RegressionType}

Type to represent frequentist regression models returned by fit functions. This type is used internally by the package to represent all frequentist regression models. RegressionType is a Symbol representing the model class.

source

Linear Regression

StatsAPI.fitMethod
fit(formula::FormulaTerm, data::DataFrame, modelClass::LinearRegression; kwargs...)

Fit an OLS Linear Regression model on the input data. Uses the lm method from the GLM package under the hood. Returns an object of type FrequentistRegression{:LinearRegression}. Supports the same keyword arguments as lm.

Example

julia> using CRRao, RDatasets, StatsPlots, StatsModels
+Frequentist Regression Models · CRRao.jl

Frequentist Regression Models

CRRao.FrequentistRegressionType
FrequentistRegression{RegressionType}

Type to represent frequentist regression models returned by fit functions. This type is used internally by the package to represent all frequentist regression models. RegressionType is a Symbol representing the model class.

source

Linear Regression

StatsAPI.fitMethod
fit(formula::FormulaTerm, data::DataFrame, modelClass::LinearRegression; kwargs...)

Fit an OLS Linear Regression model on the input data. Uses the lm method from the GLM package under the hood. Returns an object of type FrequentistRegression{:LinearRegression}. Supports the same keyword arguments as lm.

Example

julia> using CRRao, RDatasets, StatsPlots, StatsModels
 julia> df = dataset("datasets", "mtcars")
 32×12 DataFrame
  Row │ Model              MPG      Cyl    Disp     HP     DRat     WT       QSec     VS     AM     Gear   Carb  
@@ -83,7 +83,7 @@
  -2.1180653993795957
   1.6259525228014837
  -1.7939863113843444
-julia> plot(cooksdistance(container))
source

Logistic Regression

StatsAPI.fitMethod
fit(formula::FormulaTerm, data::DataFrame, modelClass::LogisticRegression, Link::Logit; kwargs...)

Fit a Logistic Regression model on the input data using the Logit link. Uses the glm method from the GLM package under the hood. Returns an object of type FrequentistRegression{:LogisticRegression}. Supports the same keyword arguments as glm.

Example

julia> using CRRao, RDatasets, StatsModels
+julia> plot(cooksdistance(container))
source

Logistic Regression

StatsAPI.fitMethod
fit(formula::FormulaTerm, data::DataFrame, modelClass::LogisticRegression, Link::Logit; kwargs...)

Fit a Logistic Regression model on the input data using the Logit link. Uses the glm method from the GLM package under the hood. Returns an object of type FrequentistRegression{:LogisticRegression}. Supports the same keyword arguments as glm.

Example

julia> using CRRao, RDatasets, StatsModels
 julia> turnout = dataset("Zelig", "turnout")
 2000×5 DataFrame
   Row │ Race   Age    Educate  Income   Vote  
@@ -132,7 +132,7 @@
 julia> aic(container)
 2033.981263703115
 julia> bic(container)
-2061.9857760008254
source
StatsAPI.fitMethod
fit(formula::FormulaTerm, data::DataFrame, modelClass::LogisticRegression, Link::Probit; kwargs...)

Fit a Logistic Regression model on the input data using the Probit link. Uses the glm method from the GLM package under the hood. Returns an object of type FrequentistRegression{:LogisticRegression}. Supports the same keyword arguments as glm.

source
StatsAPI.fitMethod
fit(formula::FormulaTerm, data::DataFrame, modelClass::LogisticRegression, Link::Cloglog; kwargs...)

Fit a Logistic Regression model on the input data using the Cloglog link. Uses the glm method from the GLM package under the hood. Returns an object of type FrequentistRegression{:LogisticRegression}. Supports the same keyword arguments as glm.

source
StatsAPI.fitMethod
fit(formula::FormulaTerm, data::DataFrame, modelClass::LogisticRegression, Link::Cauchit; kwargs...)

Fit a Logistic Regression model on the input data using the Cauchit link. Uses the glm method from the GLM package under the hood. Returns an object of type FrequentistRegression{:LogisticRegression}. Supports the same keyword arguments as glm.

source

Negative Binomial Regression

StatsAPI.fitMethod
fit(formula::FormulaTerm, data::DataFrame, modelClass::NegBinomRegression; kwargs...)

Fit a Negative Binomial Regression model on the input data (with the default link function being the Log link). Uses the negbin method from the GLM package under the hood. Returns an object of type FrequentistRegression{:NegativeBinomialRegression}. Supports the same keyword arguments as negbin.

Example

julia> using CRRao, RDatasets, StatsModels
+2061.9857760008254
source
StatsAPI.fitMethod
fit(formula::FormulaTerm, data::DataFrame, modelClass::LogisticRegression, Link::Probit; kwargs...)

Fit a Logistic Regression model on the input data using the Probit link. Uses the glm method from the GLM package under the hood. Returns an object of type FrequentistRegression{:LogisticRegression}. Supports the same keyword arguments as glm.

source
StatsAPI.fitMethod
fit(formula::FormulaTerm, data::DataFrame, modelClass::LogisticRegression, Link::Cloglog; kwargs...)

Fit a Logistic Regression model on the input data using the Cloglog link. Uses the glm method from the GLM package under the hood. Returns an object of type FrequentistRegression{:LogisticRegression}. Supports the same keyword arguments as glm.

source
StatsAPI.fitMethod
fit(formula::FormulaTerm, data::DataFrame, modelClass::LogisticRegression, Link::Cauchit; kwargs...)

Fit a Logistic Regression model on the input data using the Cauchit link. Uses the glm method from the GLM package under the hood. Returns an object of type FrequentistRegression{:LogisticRegression}. Supports the same keyword arguments as glm.

source

Negative Binomial Regression

StatsAPI.fitMethod
fit(formula::FormulaTerm, data::DataFrame, modelClass::NegBinomRegression; kwargs...)

Fit a Negative Binomial Regression model on the input data (with the default link function being the Log link). Uses the negbin method from the GLM package under the hood. Returns an object of type FrequentistRegression{:NegativeBinomialRegression}. Supports the same keyword arguments as negbin.

Example

julia> using CRRao, RDatasets, StatsModels
 julia> sanction = dataset("Zelig", "sanction")
 78×8 DataFrame
  Row │ Mil    Coop   Target  Import  Export  Cost   Num    NCost         
@@ -166,7 +166,7 @@
 NCost: major loss   -0.23511       0.511443  -0.46    0.6457  -1.23752    0.7673
 NCost: modest loss   1.30767       0.276012   4.74    <1e-05   0.766698   1.84865
 NCost: net gain      0.183453      0.275387   0.67    0.5053  -0.356296   0.723202
-──────────────────────────────────────────────────────────────────────────────────
source

Poisson Regression

StatsAPI.fitMethod
fit(formula::FormulaTerm, data::DataFrame, modelClass::PoissonRegression; kwargs...)

Fit a Poisson Regression model on the input data (with the default link function being the Log link). Uses the glm method from the GLM package under the hood. Returns an object of type FrequentistRegression{:PoissonRegression}. Supports the same keyword arguments as glm.

Example

julia> using CRRao, RDatasets, StatsModels
+──────────────────────────────────────────────────────────────────────────────────
source

Poisson Regression

StatsAPI.fitMethod
fit(formula::FormulaTerm, data::DataFrame, modelClass::PoissonRegression; kwargs...)

Fit a Poisson Regression model on the input data (with the default link function being the Log link). Uses the glm method from the GLM package under the hood. Returns an object of type FrequentistRegression{:PoissonRegression}. Supports the same keyword arguments as glm.

Example

julia> using CRRao, RDatasets, StatsModels
 julia> sanction = dataset("Zelig", "sanction")
 78×8 DataFrame
  Row │ Mil    Coop   Target  Import  Export  Cost   Num    NCost         
@@ -200,7 +200,7 @@
 NCost: major loss   -0.324051   0.230055   -1.41    0.1590  -0.774951    0.126848
 NCost: modest loss   1.71973    0.100518   17.11    <1e-64   1.52272     1.91674
 NCost: net gain      0.463907   0.16992     2.73    0.0063   0.13087     0.796944
-─────────────────────────────────────────────────────────────────────────────────
source

Extended functions from StatsAPI.jl

StatsAPI.coeftableMethod
coeftable(container::FrequentistRegression)

Table of coefficients and other statistics of the model. Extends the coeftable method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
+─────────────────────────────────────────────────────────────────────────────────
source

Extended functions from StatsAPI.jl

StatsAPI.coeftableMethod
coeftable(container::FrequentistRegression)

Table of coefficients and other statistics of the model. Extends the coeftable method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
 
 # Get the dataset
 mtcars = dataset("datasets", "mtcars")
@@ -209,7 +209,7 @@
 container = fit(@formula(MPG ~ HP + WT + Gear), mtcars, LinearRegression())
 
 # Get table of coefficients
-coeftable(container)
source
StatsAPI.r2Method
r2(container::FrequentistRegression)

Coeffient of determination. Extends the r2 method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
+coeftable(container)
source
StatsAPI.r2Method
r2(container::FrequentistRegression)

Coeffient of determination. Extends the r2 method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
 
 # Get the dataset
 mtcars = dataset("datasets", "mtcars")
@@ -218,7 +218,7 @@
 container = fit(@formula(MPG ~ HP + WT + Gear), mtcars, LinearRegression())
 
 # Get r2
-r2(container)
source
StatsAPI.adjr2Method
adjr2(container::FrequentistRegression)

Adjusted coeffient of determination. Extends the adjr2 method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
+r2(container)
source
StatsAPI.adjr2Method
adjr2(container::FrequentistRegression)

Adjusted coeffient of determination. Extends the adjr2 method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
 
 # Get the dataset
 mtcars = dataset("datasets", "mtcars")
@@ -227,7 +227,7 @@
 container = fit(@formula(MPG ~ HP + WT + Gear), mtcars, LinearRegression())
 
 # Get adjr2
-adjr2(container)
source
StatsAPI.loglikelihoodMethod
loglikelihood(container::FrequentistRegression)

Log-likelihood of the model. Extends the loglikelihood method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
+adjr2(container)
source
StatsAPI.loglikelihoodMethod
loglikelihood(container::FrequentistRegression)

Log-likelihood of the model. Extends the loglikelihood method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
 
 # Get the dataset
 mtcars = dataset("datasets", "mtcars")
@@ -236,7 +236,7 @@
 container = fit(@formula(MPG ~ HP + WT + Gear), mtcars, LinearRegression())
 
 # Get loglikelihood
-adjr2(container)
source
StatsAPI.aicMethod
aic(container::FrequentistRegression)

Akaike's Information Criterion. Extends the aic method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
+adjr2(container)
source
StatsAPI.aicMethod
aic(container::FrequentistRegression)

Akaike's Information Criterion. Extends the aic method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
 
 # Get the dataset
 mtcars = dataset("datasets", "mtcars")
@@ -245,7 +245,7 @@
 container = fit(@formula(MPG ~ HP + WT + Gear), mtcars, LinearRegression())
 
 # Get aic
-aic(container)
source
StatsAPI.bicMethod
bic(container::FrequentistRegression)

Bayesian Information Criterion. Extends the bic method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
+aic(container)
source
StatsAPI.bicMethod
bic(container::FrequentistRegression)

Bayesian Information Criterion. Extends the bic method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
 
 # Get the dataset
 mtcars = dataset("datasets", "mtcars")
@@ -254,7 +254,7 @@
 container = fit(@formula(MPG ~ HP + WT + Gear), mtcars, LinearRegression())
 
 # Get bic
-bic(container)
source
CRRao.sigmaMethod
sigma(container::FrequentistRegression)

The sigma computes the residual standard error from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
+bic(container)
source
CRRao.sigmaMethod
sigma(container::FrequentistRegression)

The sigma computes the residual standard error from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
 
 # Get the dataset
 mtcars = dataset("datasets", "mtcars")
@@ -263,7 +263,7 @@
 container = fit(@formula(MPG ~ HP + WT + Gear), mtcars, LinearRegression())
 
 # Get sigma
-sigma(container)
source
StatsAPI.predictMethod
predict(container::FrequentistRegression)

Predicted response of the model. Extends the predict method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
+sigma(container)
source
StatsAPI.predictMethod
predict(container::FrequentistRegression)

Predicted response of the model. Extends the predict method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
 
 # Get the dataset
 mtcars = dataset("datasets", "mtcars")
@@ -272,7 +272,7 @@
 container = fit(@formula(MPG ~ HP + WT + Gear), mtcars, LinearRegression())
 
 # Get predicted response
-predict(container)
source
StatsAPI.residualsMethod
residuals(container::FrequentistRegression)

Residuals of the model. Extends the residuals method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
+predict(container)
source
StatsAPI.residualsMethod
residuals(container::FrequentistRegression)

Residuals of the model. Extends the residuals method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
 
 # Get the dataset
 mtcars = dataset("datasets", "mtcars")
@@ -281,7 +281,7 @@
 container = fit(@formula(MPG ~ HP + WT + Gear), mtcars, LinearRegression())
 
 # Get residuals
-residuals(container)
source
StatsAPI.cooksdistanceMethod
cooksdistance(container::FrequentistRegression)

Compute Cook's distance for each observation in a linear model. Extends the cooksdistance method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
+residuals(container)
source
StatsAPI.cooksdistanceMethod
cooksdistance(container::FrequentistRegression)

Compute Cook's distance for each observation in a linear model. Extends the cooksdistance method from StatsAPI.jl.

Example

using CRRao, RDatasets, StatsModels
 
 # Get the dataset
 mtcars = dataset("datasets", "mtcars")
@@ -290,4 +290,4 @@
 container = fit(@formula(MPG ~ HP + WT + Gear), mtcars, LinearRegression())
 
 # Get vector of Cook's distances
-cooksdistance(container)
source
+cooksdistance(container)
source
diff --git a/dev/api/interface/index.html b/dev/api/interface/index.html index 814328b..e50f51a 100644 --- a/dev/api/interface/index.html +++ b/dev/api/interface/index.html @@ -2,5 +2,5 @@ General Interface · CRRao.jl

General Interface

Understanding the interface

CRRao exports the fit function, which is used to train all types of models supported by the package. As of now, the function supports the following signatures.

fit(formula, data, modelClass)
 fit(formula, data, modelClass, link)
 fit(formula, data, modelClass, prior)
-fit(formula, data, modelClass, link, prior)

It should be noted that not all model classes support every type of signature. The parameters passed above mean the following.

  1. The parameter formula must be a formula of type StatsModels.FormulaTerm. Any formula has an LHS and an RHS. The LHS represents the response variable, and the RHS represents the independent variables.

  2. The parameter data must be a DataFrame. This variable represents the dataset on which the model must be trained.

  3. modelClass represents the type of the statistical model to be used. Currently, CRRao supports four regression models, and the type of modelClass must be one of the following:

  4. Certain model classes (like Logistic Regression) support link functions; this is represented by the link parameter. Currently four link functions are supported: Logit, Probit, Cloglog and Cauchit. So, the type of link must be one of the following:

  5. CRRao also supports Bayesian models, and the priors to be can be specified while calling fit. Currently CRRao supports six different kinds of priors, and the type of the prior parameter must be one of the following.

Model Classes and Data Models

CRRao.LinearRegressionType
LinearRegression

Type representing the Linear Regression model class.

\[y =\alpha + X \beta+ \varepsilon,\]

where

\[\varepsilon \sim N(0,\sigma^2),\]

  • $y$ is the response vector of size $n$,
  • $X$ is the matrix of predictor variable of size $n \times p$,
  • $n$ is the sample size, and $p$ is the number of predictors,
  • $\alpha$ is the intercept of the model,
  • $\beta$ is the regression coefficients of the model, and
  • $\sigma$ is the standard deviation of the noise $\varepsilon$.
source
CRRao.LogisticRegressionType
LogisticRegression

Type representing the Logistic Regression model class.

\[y_i \sim Bernoulli(p_i), \]

where $i=1,2,\cdots,n, 0 < p_i < 1$,

  • $\mathbb{E}(y_i)=p_i$,
  • $\mathbb{P}(y_i=1) = p_i$ and $\mathbb{P}(y_i=0) = 1-p_i$, such that

\[\mathbb{E}(y_i)= p_i =g(\alpha +\mathbf{x}_i^T\beta),\]

  • $g(.)$ is the link-function,
  • $y_i$ is the $i^{th}$ element of the response vector $y$,
  • $\mathbf{x}_i=(x_{i1},x_{i2},\cdots,x_{in})$ is the $i^{th}$ row of the design matix of size $n \times p$,
  • $\alpha$ is the intercept of the model, and
  • $\beta$ is the regression coefficients of the model.
source
CRRao.NegBinomRegressionType
NegBinomRegression

Type representing the Negative Binomial Regression model class.

\[y_i \sim NegativeBinomial(\mu_i,\phi), i=1,2,\cdots,n\]

where

\[\mu_i = \exp(\alpha +\mathbf{x}_i^T\beta),\]

  • $y_i$ is the $i^{th}$ element of the response vector $y$,
  • $\mathbf{x}=(x_{i1},x_{i2},\cdots,x_{in})$ is the $i^{th}$ row of the design matix of size $n \times p$,
  • $\alpha$ is the intercept of the model, and
  • $\beta$ is the regression coefficients of the model.
source
CRRao.PoissonRegressionType
PoissonRegression

Type representing the Poisson Regression model class.

\[y_i \sim Poisson(\lambda_i), i=1,2,\cdots,n\]

where

\[\lambda_i = \exp(\alpha +\mathbf{x}_i^T\beta),\]

  • $y_i$ is the $i^{th}$ element of the response vector $y$,
  • $\mathbf{x}=(x_{i1},x_{i2},\cdots,x_{in})$ is the $i^{th}$ row of the design matix of size $n \times p$,
  • $\alpha$ is the intercept of the model, and
  • $\beta$ is the regression coefficients of the model.
source
CRRao.CRRaoLinkType
CRRaoLink

Abstract type representing link functions which are used to dispatch to appropriate calls.

source
CRRao.LogitType
Logit <: CRRaoLink

A type representing the Logit link function, which is defined by the formula

\[z\mapsto \dfrac{1}{1 + \exp(-z)}\]

source
CRRao.ProbitType
Probit <: CRRaoLink

A type representing the Probit link function, which is defined by the formula

\[z\mapsto \mathbb{P}[Z\le z]\]

where $Z\sim \text{Normal}(0, 1)$.

source
CRRao.CloglogType
Cloglog <: CRRaoLink

A type representing the Cloglog link function, which is defined by the formula

\[z\mapsto 1 - \exp(-\exp(z))\]

source
CRRao.CauchitType
Cauchit <: CRRaoLink

A type representing the Cauchit link function, which is defined by the formula

\[z\mapsto \dfrac{1}{2} + \dfrac{\text{atan}(z)}{\pi}\]

source

Prior Distributions

CRRao.Prior_GaussType
Prior_Gauss

Type representing the Gaussian Prior. Users have specific prior mean and standard deviation, for $\alpha$ and $\beta$ for linear regression model.

Prior model

\[\sigma \sim InverseGamma(a_0,b_0),\]

\[\alpha | \sigma,v \sim Normal(\alpha_0,\sigma_{\alpha_0}),\]

\[\beta | \sigma,v \sim Normal_p(\beta_0,\sigma_{\beta_0}),\]

Likelihood or data model

\[\mu_i= \alpha + \mathbf{x}_i^T\beta\]

\[y_i \sim N(\mu_i,\sigma),\]

Note: $N()$ is Gaussian distribution of $y_i$, where

  • $\mathbf{E}(y_i)=g(\mu_i)$, and
  • $Var(y_i)=\sigma^2$.
source
CRRao.Prior_RidgeType
Prior_Ridge

Type representing the Ridge Prior.

Prior model

\[v \sim InverseGamma(h,h),\]

\[\sigma \sim InverseGamma(a_0,b_0),\]

\[\alpha | \sigma,v \sim Normal(0,v*\sigma),\]

\[\beta | \sigma,v \sim Normal_p(0,v*\sigma),\]

Likelihood or data model

\[\mu_i= \alpha + \mathbf{x}_i^T\beta\]

\[y_i \sim D(\mu_i,\sigma),\]

Note: $D()$ is appropriate distribution of $y_i$ based on the modelClass, where

  • $\mathbf{E}(y_i)=g(\mu_i)$, and
  • $Var(y_i)=\sigma^2$.
source
CRRao.Prior_LaplaceType
Prior_Laplace

Type representing the Laplace Prior.

Prior model

\[v \sim InverseGamma(h,h),\]

\[\sigma \sim InverseGamma(a_0,b_0),\]

\[\alpha | \sigma,v \sim Laplace(0,v*\sigma),\]

\[\beta | \sigma,v \sim Laplace(0,v*\sigma),\]

Likelihood or data model

\[\mu_i= \alpha + \mathbf{x}_i^T\beta\]

\[y_i \sim D(\mu_i,\sigma),\]

Note: $D()$ is appropriate distribution of $y_i$ based on the modelClass, where

  • $\mathbf{E}(y_i)=g(\mu_i)$, and
  • $Var(y_i)=\sigma^2$.
source
CRRao.Prior_CauchyType
Prior_Cauchy

Type representing the Cauchy Prior.

Prior model

\[\sigma \sim Half-Cauchy(0,1),\]

\[\alpha | \sigma \sim Cauchy(0,\sigma),\]

\[\beta | \sigma \sim Cauchy(0,v*\sigma),\]

Likelihood or data model

\[\mu_i= \alpha + \mathbf{x}_i^T\beta\]

\[y_i \sim D(\mu_i,\sigma),\]

Note: $D()$ is appropriate distribution of $y_i$ based on the modelClass, where

  • $\mathbf{E}(y_i)=g(\mu_i)$, and
  • $Var(y_i)=\sigma^2$.
source
CRRao.Prior_TDistType
Prior_TDist

Type representing the T-Distributed Prior.

Prior model

\[v \sim InverseGamma(h,h),\]

\[\sigma \sim InverseGamma(a_0,b_0),\]

\[\alpha | \sigma,v \sim \sigma t(v),\]

\[\beta | \sigma,v \sim \sigma t(v),\]

Likelihood or data model

\[\mu_i= \alpha + \mathbf{x}_i^T\beta\]

\[y_i \sim D(\mu_i,\sigma),\]

Note: $D()$ is appropriate distribution of $y_i$ based on the modelClass, where

  • $\mathbf{E}(y_i)=g(\mu_i)$, and
  • $Var(y_i)=\sigma^2$.
  • The $t(v)$ is $t$ distribution with $v$ degrees of freedom.
source
CRRao.Prior_HorseShoeType
Prior_HorseShoe

Type representing the HorseShoe Prior.

Prior model

\[\tau \sim HalfCauchy(0,1),\]

\[\lambda_j \sim HalfCauchy(0,1), j=1,2,\cdots,p\]

\[\sigma \sim HalfCauchy(0,1),\]

\[\alpha | \sigma,\tau \sim N(0,\tau *\sigma),\]

\[\beta_j | \sigma,\lambda_j ,\tau \sim Normal(0,\lambda_j *\tau *\sigma),\]

Likelihood or data model

\[\mu_i= \alpha + \mathbf{x}_i^T\beta\]

\[y_i \sim D(\mu_i,\sigma), i=1,2,\cdots,n\]

Note: $D()$ is appropriate distribution of $y_i$ based on the modelClass, where

  • $\mathbf{E}(y_i)=g(\mu_i)$,
  • $Var(y_i)=\sigma^2$, and
  • $\beta$=($\beta_1,\beta_2,\cdots,\beta_p$)
source

Setting Random Number Generators

CRRao.set_rngFunction
set_rng(rng)

Set the random number generator. This is useful if you want to work with reproducible results. rng must be a random number generator.

Example

using StableRNGs
-CRRao.set_rng(StableRNG(1234))
source
+fit(formula, data, modelClass, link, prior)

It should be noted that not all model classes support every type of signature. The parameters passed above mean the following.

  1. The parameter formula must be a formula of type StatsModels.FormulaTerm. Any formula has an LHS and an RHS. The LHS represents the response variable, and the RHS represents the independent variables.

  2. The parameter data must be a DataFrame. This variable represents the dataset on which the model must be trained.

  3. modelClass represents the type of the statistical model to be used. Currently, CRRao supports four regression models, and the type of modelClass must be one of the following:

  4. Certain model classes (like Logistic Regression) support link functions; this is represented by the link parameter. Currently four link functions are supported: Logit, Probit, Cloglog and Cauchit. So, the type of link must be one of the following:

  5. CRRao also supports Bayesian models, and the priors to be can be specified while calling fit. Currently CRRao supports six different kinds of priors, and the type of the prior parameter must be one of the following.

Model Classes and Data Models

CRRao.LinearRegressionType
LinearRegression

Type representing the Linear Regression model class.

\[y =\alpha + X \beta+ \varepsilon,\]

where

\[\varepsilon \sim N(0,\sigma^2),\]

  • $y$ is the response vector of size $n$,
  • $X$ is the matrix of predictor variable of size $n \times p$,
  • $n$ is the sample size, and $p$ is the number of predictors,
  • $\alpha$ is the intercept of the model,
  • $\beta$ is the regression coefficients of the model, and
  • $\sigma$ is the standard deviation of the noise $\varepsilon$.
source
CRRao.LogisticRegressionType
LogisticRegression

Type representing the Logistic Regression model class.

\[y_i \sim Bernoulli(p_i), \]

where $i=1,2,\cdots,n, 0 < p_i < 1$,

  • $\mathbb{E}(y_i)=p_i$,
  • $\mathbb{P}(y_i=1) = p_i$ and $\mathbb{P}(y_i=0) = 1-p_i$, such that

\[\mathbb{E}(y_i)= p_i =g(\alpha +\mathbf{x}_i^T\beta),\]

  • $g(.)$ is the link-function,
  • $y_i$ is the $i^{th}$ element of the response vector $y$,
  • $\mathbf{x}_i=(x_{i1},x_{i2},\cdots,x_{in})$ is the $i^{th}$ row of the design matix of size $n \times p$,
  • $\alpha$ is the intercept of the model, and
  • $\beta$ is the regression coefficients of the model.
source
CRRao.NegBinomRegressionType
NegBinomRegression

Type representing the Negative Binomial Regression model class.

\[y_i \sim NegativeBinomial(\mu_i,\phi), i=1,2,\cdots,n\]

where

\[\mu_i = \exp(\alpha +\mathbf{x}_i^T\beta),\]

  • $y_i$ is the $i^{th}$ element of the response vector $y$,
  • $\mathbf{x}=(x_{i1},x_{i2},\cdots,x_{in})$ is the $i^{th}$ row of the design matix of size $n \times p$,
  • $\alpha$ is the intercept of the model, and
  • $\beta$ is the regression coefficients of the model.
source
CRRao.PoissonRegressionType
PoissonRegression

Type representing the Poisson Regression model class.

\[y_i \sim Poisson(\lambda_i), i=1,2,\cdots,n\]

where

\[\lambda_i = \exp(\alpha +\mathbf{x}_i^T\beta),\]

  • $y_i$ is the $i^{th}$ element of the response vector $y$,
  • $\mathbf{x}=(x_{i1},x_{i2},\cdots,x_{in})$ is the $i^{th}$ row of the design matix of size $n \times p$,
  • $\alpha$ is the intercept of the model, and
  • $\beta$ is the regression coefficients of the model.
source
CRRao.CRRaoLinkType
CRRaoLink

Abstract type representing link functions which are used to dispatch to appropriate calls.

source
CRRao.LogitType
Logit <: CRRaoLink

A type representing the Logit link function, which is defined by the formula

\[z\mapsto \dfrac{1}{1 + \exp(-z)}\]

source
CRRao.ProbitType
Probit <: CRRaoLink

A type representing the Probit link function, which is defined by the formula

\[z\mapsto \mathbb{P}[Z\le z]\]

where $Z\sim \text{Normal}(0, 1)$.

source
CRRao.CloglogType
Cloglog <: CRRaoLink

A type representing the Cloglog link function, which is defined by the formula

\[z\mapsto 1 - \exp(-\exp(z))\]

source
CRRao.CauchitType
Cauchit <: CRRaoLink

A type representing the Cauchit link function, which is defined by the formula

\[z\mapsto \dfrac{1}{2} + \dfrac{\text{atan}(z)}{\pi}\]

source

Prior Distributions

CRRao.Prior_GaussType
Prior_Gauss

Type representing the Gaussian Prior. Users have specific prior mean and standard deviation, for $\alpha$ and $\beta$ for linear regression model.

Prior model

\[\sigma \sim InverseGamma(a_0,b_0),\]

\[\alpha | \sigma,v \sim Normal(\alpha_0,\sigma_{\alpha_0}),\]

\[\beta | \sigma,v \sim Normal_p(\beta_0,\sigma_{\beta_0}),\]

Likelihood or data model

\[\mu_i= \alpha + \mathbf{x}_i^T\beta\]

\[y_i \sim N(\mu_i,\sigma),\]

Note: $N()$ is Gaussian distribution of $y_i$, where

  • $\mathbf{E}(y_i)=g(\mu_i)$, and
  • $Var(y_i)=\sigma^2$.
source
CRRao.Prior_RidgeType
Prior_Ridge

Type representing the Ridge Prior.

Prior model

\[v \sim InverseGamma(h,h),\]

\[\sigma \sim InverseGamma(a_0,b_0),\]

\[\alpha | \sigma,v \sim Normal(0,v*\sigma),\]

\[\beta | \sigma,v \sim Normal_p(0,v*\sigma),\]

Likelihood or data model

\[\mu_i= \alpha + \mathbf{x}_i^T\beta\]

\[y_i \sim D(\mu_i,\sigma),\]

Note: $D()$ is appropriate distribution of $y_i$ based on the modelClass, where

  • $\mathbf{E}(y_i)=g(\mu_i)$, and
  • $Var(y_i)=\sigma^2$.
source
CRRao.Prior_LaplaceType
Prior_Laplace

Type representing the Laplace Prior.

Prior model

\[v \sim InverseGamma(h,h),\]

\[\sigma \sim InverseGamma(a_0,b_0),\]

\[\alpha | \sigma,v \sim Laplace(0,v*\sigma),\]

\[\beta | \sigma,v \sim Laplace(0,v*\sigma),\]

Likelihood or data model

\[\mu_i= \alpha + \mathbf{x}_i^T\beta\]

\[y_i \sim D(\mu_i,\sigma),\]

Note: $D()$ is appropriate distribution of $y_i$ based on the modelClass, where

  • $\mathbf{E}(y_i)=g(\mu_i)$, and
  • $Var(y_i)=\sigma^2$.
source
CRRao.Prior_CauchyType
Prior_Cauchy

Type representing the Cauchy Prior.

Prior model

\[\sigma \sim Half-Cauchy(0,1),\]

\[\alpha | \sigma \sim Cauchy(0,\sigma),\]

\[\beta | \sigma \sim Cauchy(0,v*\sigma),\]

Likelihood or data model

\[\mu_i= \alpha + \mathbf{x}_i^T\beta\]

\[y_i \sim D(\mu_i,\sigma),\]

Note: $D()$ is appropriate distribution of $y_i$ based on the modelClass, where

  • $\mathbf{E}(y_i)=g(\mu_i)$, and
  • $Var(y_i)=\sigma^2$.
source
CRRao.Prior_TDistType
Prior_TDist

Type representing the T-Distributed Prior.

Prior model

\[v \sim InverseGamma(h,h),\]

\[\sigma \sim InverseGamma(a_0,b_0),\]

\[\alpha | \sigma,v \sim \sigma t(v),\]

\[\beta | \sigma,v \sim \sigma t(v),\]

Likelihood or data model

\[\mu_i= \alpha + \mathbf{x}_i^T\beta\]

\[y_i \sim D(\mu_i,\sigma),\]

Note: $D()$ is appropriate distribution of $y_i$ based on the modelClass, where

  • $\mathbf{E}(y_i)=g(\mu_i)$, and
  • $Var(y_i)=\sigma^2$.
  • The $t(v)$ is $t$ distribution with $v$ degrees of freedom.
source
CRRao.Prior_HorseShoeType
Prior_HorseShoe

Type representing the HorseShoe Prior.

Prior model

\[\tau \sim HalfCauchy(0,1),\]

\[\lambda_j \sim HalfCauchy(0,1), j=1,2,\cdots,p\]

\[\sigma \sim HalfCauchy(0,1),\]

\[\alpha | \sigma,\tau \sim N(0,\tau *\sigma),\]

\[\beta_j | \sigma,\lambda_j ,\tau \sim Normal(0,\lambda_j *\tau *\sigma),\]

Likelihood or data model

\[\mu_i= \alpha + \mathbf{x}_i^T\beta\]

\[y_i \sim D(\mu_i,\sigma), i=1,2,\cdots,n\]

Note: $D()$ is appropriate distribution of $y_i$ based on the modelClass, where

  • $\mathbf{E}(y_i)=g(\mu_i)$,
  • $Var(y_i)=\sigma^2$, and
  • $\beta$=($\beta_1,\beta_2,\cdots,\beta_p$)
source

Setting Random Number Generators

CRRao.set_rngFunction
set_rng(rng)

Set the random number generator. This is useful if you want to work with reproducible results. rng must be a random number generator.

Example

using StableRNGs
+CRRao.set_rng(StableRNG(1234))
source
diff --git a/dev/index.html b/dev/index.html index c0a934e..7d18d7f 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,2 +1,2 @@ -Home · CRRao.jl

Documentation for CRRao.

CRRao

CRRao is a package that implements statistical models. The implementation of statistical models becomes straightforward for most Julia users with the help of this package. This is going to be a wrapper package; leveraging the strength of wonderful Julia packages that already exist, such as StatsBase.jl, StatsModels.jl, Distributions.jl, GLM.jl, Turing.jl, Dataframes.jl, LinearAlgebra.jl etc.

CRRao is a consistent framework through which callers interact with a large suite of models. For the end-user, it reduces the cost and complexity of estimating/training statistical models. It offers convenient guidelines through which development of additional statistical models can take place in the future.

We follow a framework which makes contribution to this package easy.

Note

You can read more about Prof C.R. Rao here.

Manual

API Reference

+Home · CRRao.jl

Documentation for CRRao.

CRRao

CRRao is a package that implements statistical models. The implementation of statistical models becomes straightforward for most Julia users with the help of this package. This is going to be a wrapper package; leveraging the strength of wonderful Julia packages that already exist, such as StatsBase.jl, StatsModels.jl, Distributions.jl, GLM.jl, Turing.jl, Dataframes.jl, LinearAlgebra.jl etc.

CRRao is a consistent framework through which callers interact with a large suite of models. For the end-user, it reduces the cost and complexity of estimating/training statistical models. It offers convenient guidelines through which development of additional statistical models can take place in the future.

We follow a framework which makes contribution to this package easy.

Note

You can read more about Prof C.R. Rao here.

Manual

API Reference

diff --git a/dev/man/guide/index.html b/dev/man/guide/index.html index b13e47f..a45f68b 100644 --- a/dev/man/guide/index.html +++ b/dev/man/guide/index.html @@ -41,49 +41,49 @@ ────────────────────────────────────────────────────────────────────────────
julia> sigma(model)2.5741691724978972

We can also get the predicted response of the model, along with other measures like the vector of Cook's distances using the predict and cooksdistance functions exported by CRRao. Here's a plot of the vector of Cook's distances.

plot(cooksdistance(model))
- + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + +

To understand more about these functions and in general how frequentist models work in CRRao along with a complete set of getter functions that can be used, please visit the section of the API reference on Frequentist Regression Models.

Tutorial: Bayesian Logistic Regression

Next, let's see an example of doing bayesian statistical inference with CRRao. In this example, we will perform bayesian logistic regression on the turnout dataset from R's Zelig. Further, we will use the Logit link function with a Ridge prior (Prior_Ridge).

With this example, we'll also showcase how to use random number generators to get reproducible results. For this, we will use the StableRNGs package (although any random number generator can be used). So, first we import the required modules.

julia> using CRRao, RDatasets, StableRNGs, StatsModels

Then, we use a StableRNG with random seed 123 as our random number generator.

julia> CRRao.set_rng(StableRNG(123))StableRNGs.LehmerRNG(state=0x000000000000000000000000000000f7)

(Check the documentation of the CRRao.set_rng method for more details). Next, let us load our dataset.

julia> turnout = dataset("Zelig", "turnout")2000×5 DataFrame
   Row │ Race   Age    Educate  Income   Vote
       │ Cat…   Int32  Float64  Float64  Int32
@@ -111,8 +111,8 @@
 Iterations        = 501:1:1500
 Number of chains  = 1
 Samples per chain = 1000
-Wall duration     = 54.77 seconds
-Compute duration  = 54.77 seconds
+Wall duration     = 60.13 seconds
+Compute duration  = 60.13 seconds
 parameters        = λ, β[1], β[2], β[3], β[4], β[5]
 internals         = lp, n_steps, is_accept, acceptance_rate, log_density, hamiltonian_energy, hamiltonian_energy_error, max_hamiltonian_energy_error, tree_depth, numerical_error, step_size, nom_step_size
 
@@ -137,4 +137,4 @@
         β[2]    0.0202    0.0246    0.0268    0.0292    0.0336
         β[3]   -0.0505    0.1277    0.2255    0.3224    0.5127
         β[4]    0.1259    0.1614    0.1766    0.1941    0.2246
-        β[5]    0.1251    0.1512    0.1680    0.1806    0.2077
+ β[5] 0.1251 0.1512 0.1680 0.1806 0.2077 diff --git a/dev/search/index.html b/dev/search/index.html index 7eca223..93f4202 100644 --- a/dev/search/index.html +++ b/dev/search/index.html @@ -1,2 +1,2 @@ -Search · CRRao.jl

Loading search...

    +Search · CRRao.jl

    Loading search...