statmodel

package
v0.0.0-...-ee97d3e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2021 License: BSD-3-Clause Imports: 9 Imported by: 1

README

statmodel is a set of type definitions and generic functions to support Go packages that fit statistical models. It does not implement any specific statistical models. Some other packages that use this package to fit specific families of statistical models are:

  • goglm for Generalized Linear Models

  • duration for Cox proportional hazards regression models

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetVcov

func GetVcov(model RegFitter, params Parameter) ([]float64, error)

GetVcov returns the sampling variance/covariance matrix for the parameter estimates.

Types

type BaseResults

type BaseResults struct {
	// contains filtered or unexported fields
}

BaseResults contains the results after fitting a model to data.

func NewBaseResults

func NewBaseResults(model RegFitter, loglike float64, params []float64, xnames []string, vcov []float64) BaseResults

NewBaseResults returns a BaseResults corresponding to the given fitted model.

func (*BaseResults) FittedValues

func (rslt *BaseResults) FittedValues(da [][]Dtype) []float64

FittedValues returns the fitted linear predictor for a regression model. If da is nil, the fitted values are based on the data used to fit the model. Otherwise, the provided data stream is used to produce the fitted values, so it must have the same columns as the training data.

func (*BaseResults) LogLike

func (rslt *BaseResults) LogLike() float64

LogLike returns the log-likelihood or objective function value for the fitted model.

func (*BaseResults) Model

func (rslt *BaseResults) Model() RegFitter

Model produces the model value used to produce the results.

func (*BaseResults) Names

func (rslt *BaseResults) Names() []string

Names returns the covariate names for the variables in the model.

func (*BaseResults) PValues

func (rslt *BaseResults) PValues() []float64

PValues returns the p-values for the null hypothesis that each parameter's population value is equal to zero.

func (*BaseResults) Params

func (rslt *BaseResults) Params() []float64

Params returns the point estimates for the parameters in the model.

func (*BaseResults) StdErr

func (rslt *BaseResults) StdErr() []float64

StdErr returns the standard errors for the parameters in the model.

func (*BaseResults) VCov

func (rslt *BaseResults) VCov() []float64

VCov returns the sampling variance/covariance model for the parameters in the model. The matrix is vetorized to one dimension.

func (*BaseResults) ZScores

func (rslt *BaseResults) ZScores() []float64

ZScores returns the Z-scores (the parameter estimates divided by the standard errors).

type BaseResultser

type BaseResultser interface {
	Model() RegFitter
	Names() []string
	LogLike() float64
	Params() []float64
	VCov() []float64
	StdErr() []float64
	ZScores() []float64
	PValues() []float64
}

BaseResultser is a fitted model that can produce results (parameter estimates, etc.).

type Dataset

type Dataset interface {

	// Data returns all variables in the dataset, stored column-wise.
	Data() [][]Dtype

	// Names returns the names of the variables in the dataset,
	// in the same order as the data are stored in the Data field.
	Names() []string
}

Dataset defines a way to pass data to a statistical model.

func NewDataset

func NewDataset(data [][]Dtype, names []string) Dataset

NewDataset returns a dataset containing the given data columns.

type Dtype

type Dtype = float64

Dtype is a type alias that is used to define the datatype of all data passed to the statistical models. It should be set to float64 or float32.

type Fmter

type Fmter func(interface{}, string) []string

Fmter formats the elements of an array of values.

type Focuser

type Focuser interface {
	NumParams() int
	NumObs() int
	Focus(int, []float64, []float64) RegFitter
	LogLike(Parameter, bool) float64
	Score(Parameter, []float64)
	Hessian(Parameter, HessType, []float64)
}

Focuser restricts a model to one parameter.

type HessType

type HessType int

HessType indicates the type of a Hessian matrix for a log-likelihood.

const (
	ObsHess HessType = iota
	ExpHess
)

ObsHess (observed Hessian) and ExpHess (expected Hessian) are the two type of log-likelihood Hessian matrices

type Knockoff

type Knockoff struct {
	// contains filtered or unexported fields
}

Knockoff is a dstream that creates knockoff versions of variables from another dstream. The specific approach implemented here is the "equivariant knockoff" of Barber and Candes (2014). As with any other dstream transform, do not retain the source dstream after creating a knockoff from it.

func NewKnockoff

func NewKnockoff(data dstream.Dstream, kovars []string) (*Knockoff, error)

NewKnockoff creates a knockoff data stream from the given source data stream. A knockoff variable is constructed for each variable in 'kovars'. All knockoff variables (both the original and the knockoff version of the variable) are standardized. Variables not listed in kovars are retained but are not standardized or otherwise altered. The returned Knockoff struct value satisfies the dstream interface.

func (*Knockoff) Close

func (ko *Knockoff) Close()

Close returns the underlying reader for the dstream.

func (*Knockoff) CrossProd

func (ko *Knockoff) CrossProd() []float64

CrossProd returns the knockoff cross product matrix.

func (*Knockoff) CrossProdMinEig

func (ko *Knockoff) CrossProdMinEig() float64

CrossProdMinEig returns the minimum eigenvalue of the knockoff cross product matrix.

func (*Knockoff) Get

func (ko *Knockoff) Get(name string) interface{}

Get returns the data for the variable with the given name.

func (*Knockoff) GetPos

func (ko *Knockoff) GetPos(j int) interface{}

GetPos returns the data for the jth variable in the dstream.

func (*Knockoff) Names

func (ko *Knockoff) Names() []string

Names returns the variable names for the dstream.

func (*Knockoff) Next

func (ko *Knockoff) Next() bool

Next advances the dstream to the next chunk and returns true, or returns false if the dstream has been fully read.

func (*Knockoff) NumObs

func (ko *Knockoff) NumObs() int

NumObs returns the number of observations in the dstream.

func (*Knockoff) NumVar

func (ko *Knockoff) NumVar() int

NumVar returns the number of variables in the dstream.

func (*Knockoff) Reset

func (ko *Knockoff) Reset()

Reset returns the knockoff datastream to its beginning.

type KnockoffResult

type KnockoffResult struct {
	// contains filtered or unexported fields
}

KnockoffResult contains the results of fitting a regression model using the knockoff method.

func NewKnockoffResult

func NewKnockoffResult(result BaseResultser, plus bool) *KnockoffResult

NewKnockoffResult creates a knockoff result from a fitted regression model that has been fit to a Knockoff dataset.

func (*KnockoffResult) FDR

func (kr *KnockoffResult) FDR() []float64

FDR returns the estimated false discovery rate values for the variables in the regression model.

func (*KnockoffResult) Names

func (kr *KnockoffResult) Names() []string

Names returns the names of the variables in the knockoff analysis. For each original/knockoff variable pair, only the original name is included.

func (*KnockoffResult) Params

func (kr *KnockoffResult) Params() []float64

Params returns the estimated coefficients for the non-knockoff variables in the regression model.

func (*KnockoffResult) Stat

func (kr *KnockoffResult) Stat() []float64

Stat returns the knockoff statistic values for the variables in the regression model. These statistics are obtained by comparing the coefficient for an actual variable to the coefficient for its knockoff counterpart, so one number is returned for each actual/knockoff pair of variables.

type Parameter

type Parameter interface {

	// Get the coefficients of the covariates in the linear
	// predictor.  The returned value should be a reference so
	// that changes to it lead to corresponding changes in the
	// parameter itself.
	GetCoeff() []float64

	// Set the coefficients of the covariates in the linear
	// predictor.
	SetCoeff([]float64)

	// Clone creates a deep copy of the Parameter struct.
	Clone() Parameter
}

Parameter is the parameter of a model.

func FitL1Reg

func FitL1Reg(model Focuser, param Parameter, l1wgt, offset []float64, checkstep bool) Parameter

FitL1Reg fits the provided L1RegFitter and returns the array of parameter values.

type RegFitter

type RegFitter interface {

	// Number of parameters in the model.
	NumParams() int

	// Number of observations in the data set
	NumObs() int

	// Positions of the covariates
	Xpos() []int

	Dataset() [][]Dtype

	// The log-likelihood function
	LogLike(Parameter, bool) float64

	// The score vector
	Score(Parameter, []float64)

	// The Hessian matrix
	Hessian(Parameter, HessType, []float64)
}

RegFitter is a regression model that can be fit to data.

type SummaryTable

type SummaryTable struct {

	// Title
	Title string

	// Column names
	ColNames []string

	// Formatters for the column values
	ColFmt []Fmter

	// Cols[j] is the j^th column.  It's concrete type should
	// be an array, e.g. of numbers or strings.
	Cols []interface{}

	// Values at the top of the summary
	Top []string

	// Messages displayed below the table
	Msg []string
	// contains filtered or unexported fields
}

SummaryTable holds the summary values for a fitted model.

func (*SummaryTable) String

func (s *SummaryTable) String() string

String returns the table as a string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL