Skip to content

Commit

Permalink
version 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpnijmeijer authored and cran-robot committed Mar 29, 2017
1 parent 2f1b7fe commit 21113e3
Show file tree
Hide file tree
Showing 42 changed files with 1,677 additions and 803 deletions.
10 changes: 5 additions & 5 deletions DESCRIPTION
@@ -1,18 +1,18 @@
Package: lmvar
Type: Package
Title: Linear Regression with Non-Constant Variances
Version: 1.0.0
Version: 1.1.0
Author: Posthuma Partners <info@posthuma-partners.nl>
Maintainer: Marco Nijmeijer <nijmeijer@posthuma-partners.nl>
Description: Runs a linear regression in which both the expected value and the variance can vary per observation. The expected values mu follows the standard linear model mu = X_mu * beta_mu. The standard deviation sigma follows the model log(sigma) = X_sigma * beta_sigma. The package comes with two vignettes: 'Intro' gives an introduction, 'Math' gives mathematical details.
License: GPL-3
LazyData: TRUE
Imports: Matrix (>= 1.2-4), matrixcalc (>= 1.0-3), nleqslv (>= 3.0.3),
Imports: Matrix (>= 1.2-4), matrixcalc (>= 1.0-3), maxLik (>= 1.3-4),
stats (>= 3.2.5)
RoxygenNote: 6.0.1
Suggests: testthat, knitr, rmarkdown, R.rsp
Suggests: testthat, knitr, rmarkdown, R.rsp, MASS
VignetteBuilder: knitr, R.rsp
NeedsCompilation: no
Packaged: 2017-02-16 16:39:12 UTC; Marc
Packaged: 2017-03-29 07:29:11 UTC; Marc
Repository: CRAN
Date/Publication: 2017-02-17 14:38:14
Date/Publication: 2017-03-29 12:17:35 UTC
76 changes: 38 additions & 38 deletions MD5
@@ -1,66 +1,66 @@
0da3dd6021303151430b92d13b01bc04 *DESCRIPTION
41b7f05cd32d8769ef2208ad6368d7e9 *NAMESPACE
2edd2292dd3f51dff8535729b90bb4dd *DESCRIPTION
52973f7e6426bc4359492c3024b599e1 *NAMESPACE
b65a0f5077bda01695c98aa4bd29aa30 *NEWS.md
799ae591e93eb076cea0d9f8150235dd *R/AIC.lmvar.R
b0137d370c4c1a01bc5ceb87d8cc6285 *R/alias.lmvar.R
c5a11e9f3431dd97d7e32a2df0f1fbd5 *R/beta_sigma_names.R
08618c12995a54734f49b0735c535257 *R/coef.lmvar.R
010573949388442cd98049ecc6b0e7b2 *R/df.residual.lmvar.R
a9d9d476093ad924986c191b5241769b *R/dfree.R
6d527a34b60bbee5b434a3eb19b542a3 *R/coef.lmvar.R
e2a1a06a401c6301a201079f420b545c *R/dfree.R
39b90ad72cc9880282de9bf614d68133 *R/examples/AIC_examples.R
bd9d7d3681defffd188f22a59df22c77 *R/examples/alias_examples.R
13fa82f04c348bab1ab18187053eea3b *R/examples/beta_sigma_names_examples.R
c5ae01de2d2f10f7b4bfa919e3f388a6 *R/examples/coef_examples.R
ee365be6d30d6714e4a6454e6a0bfef7 *R/examples/df.residual_examples.R
9d526fd9bc9b4c72c55cc5cd2614b4fa *R/examples/dfree_examples.R
dd73ddf4aff15db9a6a6407af1a59577 *R/examples/fisher_examples.R
698ac483d76f91ef2a49fc965577ee33 *R/examples/fitted_examples.R
8cb1e5039896f1872911159fc875f758 *R/examples/lmvar_examples.R
de72e46ee5d6f79ef95e6546a123fe54 *R/examples/fitted_examples.R
f077a55e199e58dae1d27d25335db884 *R/examples/lmvar_examples.R
e93509e8f18367eae4c7a21672482354 *R/examples/logLik_examples.R
02000462392443088a7b9628b773cd8a *R/examples/nobs_examples.R
f28168301e48d6a216067c9e6f46320a *R/examples/predict_examples.R
8bbfa2ac0a52f0be3d68985b972e0ea3 *R/examples/predict_examples.R
014ab1c3a4fb3f2511a5df2dbe775723 *R/examples/residuals_examples.R
3b54dd7601fce2246ecfe4fbebaf345f *R/examples/summary_examples.R
ef613a5445aeaf5860f2c5fe24ea69b8 *R/examples/summary_examples.R
2139927b488f26929811b608c885885f *R/examples/vcov_examples.R
65c5d7d3efb959034969ce25081d0525 *R/fisher.R
bb4e182ff8110e449ab82117c67b5f6f *R/fitted.lmvar.R
f7f5e1b02453dee36675c0b93c29e044 *R/fitted.lmvar.R
d97d4f2dd4613ba9af5c79e8c683d4b7 *R/gaussian_var.R
ae576df528a3f5b30cac7df2df9dce68 *R/lmvar.R
e52430dee384e8fc8c25fe9e2dc1e615 *R/lmvar.R
8a5f8803d15359cd28f236e6a59d3d1d *R/logLik.lmvar.R
11a615ab05ce7c6a45d5905a064587b6 *R/make_matrix_full_rank.R
c6eb72596cb95e6d1f12968a110a1fcb *R/matrix_column_names.R
d3f6d391dc6c4b1d11d42cc305cc14c7 *R/make_matrix_full_rank.R
f3288867bdf9afe76559cb414d136f40 *R/matrix_column_names.R
4f63ac17353588bd3d9497d181ace9cb *R/nobs.lmvar.R
f37f6f29c93effe8ebfdc3998dc28a20 *R/predict.lmvar.R
af17a34e533280763874b7faa31208a1 *R/print.summary_lmvar.R
51408820b0c6ceb5a05ba9572bcf563b *R/predict.lmvar.R
6e05efb82387a3ee531c8c2f5383caa0 *R/print.summary_lmvar.R
68ba53a968caa6fc52a96117a4b2a537 *R/residuals.lmvar.R
6f3aa4fe0edbf10588592d9bef786368 *R/summary.lmvar.R
b07e75a5335b4375cedc45d4e876594f *R/vcov.lmvar.R
058e5cb3b2ffde63a0e073c229b7ca24 *README.md
9a51ea3e128c9edff4d3fe1f448b53a5 *build/vignette.rds
828d6a905ed48145c432c23f00ef645c *inst/doc/Intro.R
475cfafe2a4d03be48ab649bab4d5f81 *inst/doc/Intro.Rmd
7fff116f96908a44f030b786be788671 *inst/doc/Intro.html
0d2d2347fc49b246c9f6607324c60005 *inst/doc/Math.ltx
604b46aa4979321bd4c90566bfa4cc44 *inst/doc/Math.pdf
84f68669bf255b36289779722a24c76a *R/summary.lmvar.R
7edbf99718bd27c73eef02ba0b3962bf *R/vcov.lmvar.R
4b781b692f552a9f22d261ef010b6d5a *README.md
c579eb4b11dc36f29724cfa28a9f628b *build/vignette.rds
f82e1918a45923e06c52f5e55835e713 *inst/doc/Intro.R
2439946a1cce9cce99a20fe0c0a740d1 *inst/doc/Intro.Rmd
4eac84742c5496ecfdee8fee837b8df5 *inst/doc/Intro.html
2e88d78c1f638f78fd981a4d677b730e *inst/doc/Math.ltx
b1fd4dff43279b5da2db5a2e54129aed *inst/doc/Math.pdf
cdc8775371ef46701cbbfdd098441d22 *man/AIC.lmvar.Rd
40be9e23383ce6cfb87f6158572eab2e *man/alias.lmvar.Rd
96870ffeb6e33b5476b9014730e99d0f *man/beta_sigma_names.Rd
dc231983bd8fc1c8234230199df56ebc *man/coef.lmvar.Rd
ae69a6216348af4e1787e9550574a03e *man/df.residual.lmvar.Rd
8a46914afe8717717af7868eb56fe898 *man/dfree.Rd
080d71de1dad4ff42e68810ec5e3c56f *man/coef.lmvar.Rd
d728f54df747c77aa92e6dc2c20e1897 *man/dfree.Rd
a5e5ccd1c0fafcdaee3bbeb7cab47cd5 *man/fisher.Rd
f84bf4c6fc34202b0f52fc560ac08b84 *man/fitted.lmvar.Rd
9105d49018403123fc7fe8430ec2299a *man/lmvar.Rd
0ae10d96bcc680bbf04b1011fe64662e *man/fitted.lmvar.Rd
992319913416906156e541f1a92addcd *man/lmvar.Rd
d3041936af6e96cdc0ae4464e0f52796 *man/logLik.lmvar.Rd
c33fe1105392aeab24e540c8f09459a4 *man/nobs.lmvar.Rd
85f6305560b23fac8565e52f25fc606a *man/predict.lmvar.Rd
91e5550ddd2e0347bf055aca01310f43 *man/predict.lmvar.Rd
080d695ec1395b492167dbf7e898c71a *man/print.summary_lmvar.Rd
9b35a0b154bc37c64d22c063fe84850e *man/residuals.lmvar.Rd
3001d4fdbb5a458419ddcac4c7e161f7 *man/summary.lmvar.Rd
103ad2096a2c2810478be7d856ea2b32 *man/vcov.lmvar.Rd
bde5eb3a375b2d0298b8c17d84eda405 *tests/create_test_data.R
f40cafc12225a417527d4e20d3940766 *man/summary.lmvar.Rd
869b39bcf7108f031d972e1883df6a22 *man/vcov.lmvar.Rd
2240bdeb95bf161a84eb0780c4f55a4f *tests/create_test_data.R
b5e9bbfbc1b319bc3baec90d163e1426 *tests/testthat.R
9181c1bb3ff9b24d1d5da2dcf1a0ce1e *tests/testthat/test_extractors.R
3dc4e0f80fc5c12cef9aadd1a98116f7 *tests/testthat/test_lmvar.R
18b7f56763d877e27e3f5083153c384f *tests/testthat/test_predict.R
475cfafe2a4d03be48ab649bab4d5f81 *vignettes/Intro.Rmd
0d2d2347fc49b246c9f6607324c60005 *vignettes/Math.ltx
e6bfe10c846af198d038690951ced931 *tests/testthat/test_gradient_and_hessian.R
42f498d5a3ca3706de5df38c4d4047c5 *tests/testthat/test_lmvar.R
2de1a3ebd02098ee93f67c401f92d281 *tests/testthat/test_predict.R
2439946a1cce9cce99a20fe0c0a740d1 *vignettes/Intro.Rmd
2e88d78c1f638f78fd981a4d677b730e *vignettes/Math.ltx
1f1187e559041319b24a3d5459fd64c7 *vignettes/bibliography.bib
1 change: 0 additions & 1 deletion NAMESPACE
Expand Up @@ -3,7 +3,6 @@
S3method(AIC,lmvar)
S3method(alias,lmvar)
S3method(coef,lmvar)
S3method(df.residual,lmvar)
S3method(fitted,lmvar)
S3method(logLik,lmvar)
S3method(nobs,lmvar)
Expand Down
27 changes: 27 additions & 0 deletions NEWS.md
@@ -0,0 +1,27 @@
Version 1.1.0
-------------

* To find the maximum likelihood, a set of non-linear equations must be solved. This is done by the function 'maxNR' from the package 'maxLik'. It results in faster and more robust solves, compared to the previous version of 'lmvar'.

* It is possible to pass on options to 'maxNR' from the call to 'lmvar'. For this, 'lmvar' has a new argument 'slvr_options'.

* It is possible to request the result log of 'maxNR'. For this, 'lmvar' has a new argument 'slvr_log'.

* It is possible to suppress the intercept terms in the model for mu and the model for log sigma. For this, 'lmvar' has the new arguments 'intercept_mu' and 'intercept_sigma'.

* The functions 'fitted.lmvar' and 'predict.lmvar' support the interval type 'prediction'.

* Input matrices X_mu and X_sigma to 'lmvar' that have only one column, can be of type 'numeric'.

* The matrix of coefficients shown by 'summary', can be restricted to only the coefficients 'beta_mu' or only the coefficients 'beta_sigma'. For this, 'summary.lmvar' has the new arguments 'mu' and 'sigma'. This option is useful when the length of the vector 'beta_mu' and/or 'beta_sigma' is large.

* The function 'df.residuals.lmvar' has been removed. The 'residual degrees of freedom' are a useful concept in a classical linear model where it specifies the degrees of freedom of the Student t-distribution for e.g. confidence intervals of beta. This distribution plays no role in the model of 'lmvar' which uses aymptotically normal distributions.

* Improved documentation, in particular the README and the vignettes 'Intro' and 'Math'

* Bug fixes

Version 1.0.0
-------------

First release-version.
2 changes: 2 additions & 0 deletions R/coef.lmvar.R
Expand Up @@ -20,6 +20,8 @@
#'
#' @seealso \code{\link{beta_sigma_names}} for the adaptation of the names of the coefficients in \eqn{\beta_\sigma}.
#'
#' \code{\link[stats]{confint}} for the calculation of confidence intervals of \eqn{\beta_\mu} and \eqn{\beta_\sigma}.
#'
#' @export
#'
#' @example R/examples/coef_examples.R
Expand Down
23 changes: 0 additions & 23 deletions R/df.residual.lmvar.R

This file was deleted.

2 changes: 0 additions & 2 deletions R/dfree.R
Expand Up @@ -22,8 +22,6 @@
#'
#' @export
#'
#' @seealso \code{\link{df.residual.lmvar}} for the residual degrees of freedom for an object of class 'lmvar'
#'
#' @example R/examples/dfree_examples.R
#'

Expand Down
26 changes: 0 additions & 26 deletions R/examples/df.residual_examples.R

This file was deleted.

5 changes: 5 additions & 0 deletions R/examples/fitted_examples.R
Expand Up @@ -32,6 +32,9 @@ fitted(fit)
# Calculate the expected values, the standard deviations and their 95% confidence intervals
fitted(fit, interval = "confidence")

# Calculate the expected values and the 90% prediction intervals
fitted(fit, interval = "prediction", level = 0.9)

# Fit the log of 'accel'
y = log(attenu$accel)
fit_log = lmvar(y, X, X_s)
Expand All @@ -45,3 +48,5 @@ fitted(fit_log, log = TRUE)
# Calculate the expected values and the standard deviations of 'accel',
# as well as their 90% confidence intervals
fitted(fit_log, log = TRUE, interval = "confidence", level = 0.9)


19 changes: 8 additions & 11 deletions R/examples/lmvar_examples.R
Expand Up @@ -17,16 +17,13 @@ X_s = cbind(attenu$mag, 1 / attenu$dist)
colnames(X_s) = c("mag", "dist_inv")

# Carry out the fit
fit_lmvar = lmvar(attenu$accel, X, X_s)
fit = lmvar(attenu$accel, X, X_s)

# Inspect the results. Note from the p-value for the difference in
# deviance that this fit appears to be significantly better than
# a classical linear fit
summary(fit_lmvar)
# Inspect the results
summary(fit)

# Carry out a classical linear fit for comparison
fit_lm = lm(attenu$accel ~ mag + dist, attenu)

# A comparison of the AIC values also favours the fit with 'lmvar'
AIC(fit_lm)
AIC(fit_lmvar)
# Carry out the fit with an inital estimate for beta and ask for
# a report of the solver-routine
beta_sigma_start = c(-4, 0, 0)
fit = lmvar(attenu$accel, X, X_s, slvr_options = list(start = beta_sigma_start), slvr_log = TRUE)
fit$slvr_log
5 changes: 4 additions & 1 deletion R/examples/predict_examples.R
Expand Up @@ -40,7 +40,10 @@ predict(fit, XP, XP_s, mu = FALSE)
predict(fit, XP, XP_s, sigma = FALSE, interval = "confidence")

# Calculate the standard deviations and their 90% confidence intervals
predict(fit, XP, XP_s, sigma = FALSE, interval = "confidence", level = 0.9)
predict(fit, XP, XP_s, mu = FALSE, interval = "confidence", level = 0.9)

# Calculate the expected values and the 90% prediction intervals of 'accel'
predict(fit, XP, XP_s, sigma = FALSE, interval = "prediction", level = 0.9)

# Change the model and fit the log of 'accel'
y = log(attenu$accel)
Expand Down
6 changes: 6 additions & 0 deletions R/examples/summary_examples.R
Expand Up @@ -16,5 +16,11 @@ fit = lmvar(attenu$accel, X, X_s)
# Print a summary of the fit
summary(fit)

# Include only the coefficients beta for the expected values
summary(fit, sigma = FALSE)

# Include only the coefficients beta for the standard deviations
summary(fit, mu = FALSE)

# Extract the matrix of coefficients from the summary
coef(summary(fit))
36 changes: 24 additions & 12 deletions R/fitted.lmvar.R
@@ -1,19 +1,19 @@
#' @title Fitted values for an 'lmvar' object
#'
#' @description Estimators and confidence intervals for the expected values and standard deviations of the response-vector \eqn{Y} of
#' an 'lmvar' model. The model can be a fit
#' to the response vector or to the logarithm of the response vector.
#' @description Estimators and confidence intervals for the expected values and standard deviations of the response vector \eqn{Y} of
#' an 'lmvar' model. Prediction intervals for \eqn{Y} as well. Alternatively, estimators and intervals can be for \eqn{e^Y}.
#'
#' @param object An 'lmvar' object
#' @param mu Boolean, specifies whether or not to return the expected values
#' @param sigma Boolean, specifies whether or not to return the standard deviations
#' @param log Boolean, specifies whether the observations \eqn{Y} have been fitted or the logarithm \eqn{\log Y}. In both cases,
#' \code{fitted.lmvar} returns expected values and standard deviations for \eqn{Y} itself.
#' @param log Boolean, specifies whether expected values, standard deviations (as well as their confidence intervals) and
#' prediction intervals should be for \eqn{Y} (\code{log = FALSE}) or for \eqn{e^Y} (\code{log = TRUE}).
#' @param interval Character string, specifying the type of interval. Possible values are
#' \itemize{
#' \item "none" No interval
#' \item "none" No interval, this is the default
#' \item "confidence" Confidence intervals for the expected values (if \code{mu = TRUE}) and the standard deviation
#' (if \code{sigma = TRUE})
#' \item "prediction" Prediction intervals for the response vector \eqn{Y} (\code{log = FALSE}) or for \eqn{e^Y} (\code{log = TRUE})
#' }
#' @param level Numeric value between 0 and 1, specifying the confidence level
#' @param ... For compatibility with \code{\link[stats]{fitted}} generic.
Expand All @@ -28,10 +28,12 @@
#' \itemize{
#' \item \code{mu} Estimators for the expected value \eqn{\mu}
#' \item \code{sigma} Estimators for the standard deviation \eqn{\sigma}
#' \item \code{mu_lwr} Lower bound of the interval for \eqn{\mu}
#' \item \code{mu_upr} Upper bound of the interval for \eqn{\mu}
#' \item \code{sigma_lwr} Lower bound of the interval for \eqn{\sigma}
#' \item \code{sigma_upr} Upper bound of the interval for \eqn{\sigma}
#' \item \code{mu_lwr} Lower bound of the confidence interval for \eqn{\mu}
#' \item \code{mu_upr} Upper bound of the confidence interval for \eqn{\mu}
#' \item \code{sigma_lwr} Lower bound of the confidence interval for \eqn{\sigma}
#' \item \code{sigma_upr} Upper bound of the confidence interval for \eqn{\sigma}
#' \item \code{lwr} Lower bound of the prediction interval
#' \item \code{upr} Upper bound of the prediction interval
#' }
#'
#' @export
Expand All @@ -51,11 +53,21 @@
#' @seealso \code{\link{predict.lmvar}} for expected values, standard deviations and intervals for model matrices different from
#' the ones present in \code{object}.
#'
#' \code{\link{coef.lmvar}} and \code{\link[stats]{confint}} for maximum likelihood estimators and confidence intervals for
#' \eqn{\beta_\mu} and \eqn{\beta_\sigma}.
#'
#' @example R/examples/fitted_examples.R
#'

fitted.lmvar <- function( object, mu = TRUE, sigma = TRUE, log = FALSE, interval = c("none", "confidence"), level = 0.95, ...){
fitted.lmvar <- function( object, mu = TRUE, sigma = TRUE, log = FALSE, interval = c("none", "confidence", "prediction"), level = 0.95, ...){

return(predict.lmvar( object, mu = mu, sigma = sigma, log = log, interval = interval, level = level, ...))
# Check interval
if (missing(interval)){
interval = interval[1]
}
else{
interval = match.arg(interval)
}

return(predict.lmvar( object, mu = mu, sigma = sigma, log = log, interval = interval, level = level, ...))
}

0 comments on commit 21113e3

Please sign in to comment.