# Main function for CUBE models

### Description

Main function to estimate and validate a CUBE model for given ratings, explaining uncertainty, feeling and overdispersion.

### Usage

1 2 |

### Arguments

`ordinal` |
Vector of ordinal responses |

`m` |
Number of ordinal categories (if omitted, it will be assigned to the number of categories specified in the global environment) |

`Y` |
Matrix of covariates for explaining the uncertainty component. If omitted (default), no covariate is included in the model |

`W` |
Matrix of covariates for explaining the feeling component. If omitted (default), no covariate is included in the model |

`Z` |
Matrix of covariates for explaining the overdispersion component. If omitted (default), no covariate is included in the model |

`starting` |
Initial parameters estimates to start the optimization algorithm. If missing, the function calls specific routines computing the best initial estimates available |

`maxiter` |
Maximum number of iterations allowed for running the optimization algorithm (default: maxiter=1000) |

`toler` |
Fixed error tolerance for final estimates (default: toler = 1e-6, except for the model including covariates for all the three parameters, in which case toler=1e-2) |

`makeplot` |
Logical: if TRUE (default) and no covariate is included in the model, the function returns a graphical plot comparing fitted probabilities and observed relative frequencies |

`expinform` |
Logical: if TRUE and no covariate is included in the model, the function returns the expected variance-covariance matrix (default is FALSE) |

`summary` |
Logical: if TRUE (default), summary results of the fitting procedure are displayed on screen |

### Details

It is the main function for CUBE models, calling for the corresponding functions whenever
covariates are specified: it is possible to select covariates for explaining all the three parameters
or only the feeling component.

The program also checks if the estimated variance-covariance matrix is positive definite: if not,
it prints a warning message and returns a matrix and related results with NA entries.
The optimization procedure is run via "optim". If covariates are included only for feeling,
the variance-covariance matrix is computed as the inverse of the returned numerically differentiated
Hessian matrix (option: hessian=TRUE as argument for "optim"), and the estimation procedure is not
iterative, so a NULL result for $niter is produced.
If the estimated variance-covariance matrix is not positive definite, the function returns a
warning message and produces a matrix with NA entries.

### Value

An object of the class "CUBE" is a list containing the following results:

`estimates` |
Maximum likelihood estimates: |

`loglik` |
Log-likelihood function at the final estimates |

`varmat` |
Variance-covariance matrix of final estimates |

`niter` |
Number of executed iterations |

`BIC` |
BIC index for the estimated model |

### References

Iannario M. (2014). Modelling Uncertainty and Overdispersion in Ordinal Data,
*Communications in Statistics - Theory and Methods*, **43**, 771–786

Piccolo D. (2015). Inferential issues for CUBE models with covariates,
*Communications in Statistics. Theory and Methods*, **44**(23), 771–786.

Iannario M. (2015). Detecting latent components in ordinal data with overdispersion by means
of a mixture distribution, *Quality & Quantity*, **49**, 977–987

Iannario M. (2016). Testing the overdispersion parameter in CUBE models.
*Communications in Statistics: Simulation and Computation*, **45**(5), 1621–1635.

### See Also

`probcube`

, `loglikCUBE`

, `loglikcuben`

, `inibestcube`

,
`inibestcubecsi`

, `inibestcubecov`

,
`varmatCUBE`

### Examples

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ```
data(relgoods)
m<-10
ordinal<-na.omit(relgoods[,37])
model<-CUBE(ordinal,starting=c(0.1,0.1,0.1),summary=TRUE)
model$estimates # Final ML estimates
model$loglik # Maximum value of the log-likelihood function
model$varmat
model$niter
model$BIC
########################
ordinal<-relgoods[,40]
cov<-relgoods[,2]
nona<-na.omit(cbind(ordinal,cov))
modelcovcsi<-CUBE(nona[,1],W=nona[,2],summary=TRUE)
modelcov<-CUBE(nona[,1],Y=nona[,2],W=nona[,2], Z=nona[,2])
modelcov$BIC
modelcovcsi$BIC
#######################################
data(univer)
m<-7
ordinal<-univer[,8]
starting<-inibestcube(m,ordinal)
model<-CUBE(ordinal,starting=starting,summary=TRUE)
``` |