You are on page 1of 24

Package bstats

February 14, 2012


Version 1.0-12-3 Date 2011-10-31 Title Basic statistical functions for R Author Bin Wang <bwang@jaguar1.usouthal.edu>. Maintainer Bin Wang <bwang@jaguar1.usouthal.edu> Description This package collects commonly used procedures or algorithms for general data analysis. In addition, routines for linear regression analysis, statistical computing and graphics, and many others have been implemented in R for some courses taught at the University of South Alabama. License Unlimited Repository CRAN Date/Publication 2011-12-04 09:26:34

R topics documented:
ac . . . . . . birth . . . . . bptest . . . . bstats . . . . dw.test . . . . edf . . . . . . edu75 . . . . inuential.plot ld50.logit . . ld50.logitt . lm.ci . . . . . mediation.test model.check . model.test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 3 3 5 5 7 8 8 10 10 11 12 13 14

2 oddsratio . . predictor.plot residual.plot . river . . . . . scb . . . . . . supervisor . . vif . . . . . . white.test . . wls . . . . . . Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ac 15 17 18 19 19 20 20 22 23 24

ac

Autocorrelation

Description Removal of autocorrelation by transformation. Usage ac(lmobj,type=cochrane, ...) ## S3 method for class lm ac(lmobj,type=cochrane, ...) Arguments lmobj type ... Details iterative: simultaneously estimate the regression coefcients and rho by minimizing the sum squared errors. A grid searching method is used. cochrane: 1. Fit a linear regression model and compute OLS estimates 2. Calculate the residuals to estimate rho from the data. 3. Fit (1) to obtain estimates of the regression coefcients. 4. Check to see whether autocorrelation still exist. If yes, repeat by using the estimated coefcients from step 3 in step 1. Value coefcients, rhohat, dwtest, re-tted model. Author(s) Wang, B. an object that inherits from class lm, such as an lm or glm object. method selection: iterative, cochrane. not used.

bptest References Cochrane and Orcutt (1949) St 335 text Examples


data(edu75) lm = lm(Y~X1+X2+X3, data=edu75) ac.lm(lm ,type=iterative) ac.lm(lm , type=cochrane)

birth

Birth data

Description Birth data for singleton live births with gestational age at least 38 weeks. Usage data(birth) Format A data frame with 400 observations on 9 variables. Sex Gestation Weight Length Head Chest Mother.s.age type region character numeric numeric numeric numeric numeric numeric factor factor male or female Gestational age (in weeks). birth weight. height. head size. chest size. chest size. r = rural or u = urban. region of the birth.

References Wang, CSDA and JSS papers.

bptest

Breusch-Pagan Test

4 Description Performs the Breusch-Pagan test against heteroskedasticity. Usage bptest(formula, varformula = NULL, studentize = TRUE, data = list()) Arguments formula varformula

bptest

a symbolic description for the model to be tested (or a tted "lm" object). a formula describing only the potential explanatory variables for the variance (no dependent variable needed). By default the same explanatory variables are taken as in the main regression model. logical. If set to TRUE Koenkers studentized version of the test statistic will be used. an optional data frame containing the variables in the model. By default the variables are taken from the environment which bptest is called from.

studentize data

Details The Breusch-Pagan test ts a linear regression model to the residuals of a linear regression model (by default the same explanatory variables are taken as in the main regression model) and rejects if too much of the variance is explained by the additional explanatory variables. Under H0 the test statistic of the Breusch-Pagan test follows a chi-squared distribution with parameter (the number of regressors without the constant in the model) degrees of freedom. Value A list with class "htest" containing the following components: statistic p.value parameter method data.name References T.S. Breusch & A.R. Pagan (1979), A Simple Test for Heteroscedasticity and Random Coefcient Variation. Econometrica 47, 12871294 R. Koenker (1981), A Note on Studentizing a Test for Heteroscedasticity. Journal of Econometrics 17, 107112. W. Kramer & H. Sonnberger (1986), The Linear Regression Model under Test. Heidelberg: Physica the value of the test statistic. the p-value of the test. degrees of freedom. a character string indicating what type of test was performed. a character string giving the name(s) of the data.

bstats Examples
## generate a regressor x <- rep(c(-1,1), 5 ) ## generate heteroskedastic and homoskedastic disturbances err1 <- rnorm(1 , sd=rep(c(1,2), 5 )) err2 <- rnorm(1 ) ## generate a linear relationship y1 <- 1 + x + err1 y2 <- 1 + x + err2 ## perform Breusch-Pagan test bptest(y1 ~ x) bptest(y2 ~ x)

bstats

R package: bstats

Description In this paackage, some R functions are written for the convenience of class uses. Especially for my st 315, st 210, st 335, st 475/575 Author(s) B. Wang <bwang@jaguar1.usouthal.edu>

dw.test

Durbin-Watson Test

Description Performs the Durbin-Watson test for autocorrelation of disturbances. Usage dw.test(formula, order.by = NULL, alternative = c("greater", "two.sided", "less"), iterations = 15, exact = NULL, tol = 1e-1 , data = list()) Arguments formula order.by a symbolic description for the model to be tested (or a tted "lm" object). Either a vector z or a formula with a single explanatory variable like ~ z. The observations in the model are ordered by the size of z. If set to NULL (the default) the observations are assumed to be ordered (e.g., a time series). a character string specifying the alternative hypothesis.

alternative

6 iterations exact

dw.test an integer specifying the number of iterations when calculating the p-value with the "pan" algorithm. logical. If set to FALSE a normal approximation will be used to compute the p value, if TRUE the "pan" algorithm is used. The default is to use "pan" if the sample size is < 100. tolerance. Eigenvalues computed have to be greater than tol to be treated as non-zero. an optional data frame containing the variables in the model. By default the variables are taken from the environment which dwtest is called from.

tol data

Details The Durbin-Watson test has the null hypothesis that the autocorrelation of the disturbances is 0. It is possible to test against the alternative that it is greater than, not equal to, or less than 0, respectively. This can be specied by the alternative argument. Under the assumption of normally distributed disturbances, the null distribution of the DurbinWatson statistic is the distribution of a linear combination of chi-squared variables. The p-value is computed using the Fortran version of Applied Statistics Algorithm AS 153 by Farebrother (1980, 1984). This algorithm is called "pan" or "gradsol". For large sample sizes the algorithm might fail to compute the p value; in that case a warning is printed and an approximate p value will be given; this p value is computed using a normal approximation with mean and variance of the Durbin-Watson test statistic. For an overview on R and econometrics see Racine & Hyndman (2002). Value An object of class "htest" containing: statistic p.value method data.name References J. Durbin & G.S. Watson (1950), Testing for Serial Correlation in Least Squares Regression I. Biometrika 37, 409428. J. Durbin & G.S. Watson (1951), Testing for Serial Correlation in Least Squares Regression II. Biometrika 38, 159178. J. Durbin & G.S. Watson (1971), Testing for Serial Correlation in Least Squares Regression III. Biometrika 58, 119. R.W. Farebrother (1980), Pans Procedure for the Tail Probabilities of the Durbin-Watson Statistic (Corr: 81V30 p189; AS R52: 84V33 p363- 366; AS R53: 84V33 p366- 369). Applied Statistics 29, 224227. the test statistic. the corresponding p-value. a character string with the method used. a character string with the data name.

edf

7 R. W. Farebrother (1984), [AS R53] A Remark on Algorithms AS 106 (77V26 p92-98), AS 153 (80V29 p224-227) and AS 155: The Distribution of a Linear Combination of 2 Random Variables (80V29 p323-333) Applied Statistics 33, 366369. W. Krmer & H. Sonnberger (1986), The Linear Regression Model under Test. Heidelberg: Physica. J. Racine & R. Hyndman (2002), Using R To Teach Econometrics. Journal of Applied Econometrics 17, 175189.

See Also lm Examples


## generate two AR(1) error terms with parameter ## rho = (white noise) and rho = .9 respectively err1 <- rnorm(1 ) ## generate regressor and dependent variable x <- rep(c(-1,1), 5 ) y1 <- 1 + x + err1 ## perform Durbin-Watson test dw.test(y1 ~ x) err2 <- filter(err1, y2 <- 1 + x + err2 dw.test(y2 ~ x) .9, method="recursive")

edf

To compute the empirical distribution function.

Description To compute the empirical distribution function. Usage edf(x,y=NULL) Arguments x y Author(s) B. Wang <bwang@jaguar1.usouthal.edu> A sample. NA values will be automatically removed. A grid of points where the edf will be evaluated.

8 See Also scb. Examples


x = rnorm(1 ) (out = edf(x)) plot(out) (out2= scb(out)) lines(out2)

inuential.plot

edu75

Education expenditure data (1975)

Description Education expenditure data for all 50 states in U.S.A in 1975. Usage data(edu75) Format A data frame with 50 observations on 6 variables. States Y X1 X2 X3 Region character numeric numeric numeric numeric character Initial of state names Educational expenditure. X1. X2. X3. region, 1=northwest, 2,3,4.

References Stat 335 text

influential.plot

Draw plots for the inuence measures

Description Draw plots for the inuence measures.

inuential.plot Usage influential.plot(lmobj,type=hadi,ID=FALSE,col=1)

Arguments lmobj type ID col An R object by tting an OLS model to a data set. Plot type. hadi: the Hadis inuence Measures; potential-residual: potentialresidual plot; dts: DFITS plot; hat: leverage plot; cook: Cooks distance. Whether to identify points in the plots. Default: FALSE Color of the plot.

Value Output the inuence measures, including leverage values (Leverage), Hadis measure (Hadi), Welsch and Kuh Measure (DFIT) and Cooks distance (CookD). In addition, the standard residuals are also exported.

Author(s) B. Wang <bwang@jaguar1.usouthal.edu>

See Also residual.plot.

Examples
data(river) lm = lm(Nitrogen~Agr+Forest+Rsdntial+ComIndl, data=river) influential.plot(lm ) influential.plot(lm ,type=hadi) influential.plot(lm ,type=potential) influential.plot(lm ,type=leve) influential.plot(lm ,type=dfit) influential.plot(lm ,type=cook) influential.plot(lm ,type=potential,ID=TRUE)

10

ld50.logitt

ld5 .logit

Predict Doses for Binomial Assay model (using counts)

Description Calibrate binomial assays, generalizing the calculation of LD50 based on a logistic regression model. Usage ld5 .logit(ndead, ntotal, dose, cf = 1:2, p = .5) Arguments ndead ntotal dose cf p References Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Springer. Examples
ldose <- rep( :5, 2) numdead <- c(1, 4, 9, 13, 18, 2 , n=2 ld5 .logit(numdead,n,ldose,p = .5) , 2, 6, 1 , 12, 16)

A vector of number of failures. Total number of trials. A vector of dosages. The terms in the coefcient vector giving the intercept and coefcient of (log)dose Probabilities at which to predict the dose needed.

ld5 .logitfit

Predict Doses for Binomial Assay model (using counts)

Description Calibrate binomial assays, generalizing the calculation of LD50 based on a logistic regression model. Usage ld5 .logitfit(rate, dose, p = .5)

lm.ci Arguments rate dose p References Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Springer. Examples
ldose <- rep( :5, 2) rate <- c(1, 4, 9, 13, 18, 2 , ld5 .logitfit(rate,ldose,p = , 2, 6, 1 , 12, 16)/2 .5)

11

A vector of percentages of successes among all trials. A vector of dosages. Probabilities at which to predict the dose needed.

lm.ci

To compute the condene interval of the regression parameters.

Description To compute the condene interval of the regression parameters. Usage lm.ci(lmobj,level= .95) Arguments lmobj level Author(s) B. Wang <bwang@jaguar1.usouthal.edu> See Also model.test. An R object by tting a linear regression model to a data set. Condence level. Default: 0.95.

12 Examples
data(birth) attach(birth) lm = lm(Head~Weight) lm.ci(lm ) lm1 = lm(Head~Weight+Gestation) lm.ci(lm1, level= .99)

mediation.test

mediation.test

The Sobel mediation test

Description To compute statistics and p-values for the Sobel test. Results for three versions of "Sobel test" are provided: Sobel test, Aroian test and Goodman test.

Usage mediation.test(mv,iv,dv)

Arguments mv iv dv The mediator variable. The independent variable. The dependent variable.

Details To test whether a mediator carries the inuence on an IV to a DV.

Value Missing values are not allowed.

Author(s) B. Wang <bwang@jaguar1.usouthal.edu>

model.check References

13

MacKinnon, D. P., & Dwyer, J. H. (1993). Estimating mediated effects in prevention studies. Evaluation Review, 17, 144-158. MacKinnon, D. P., Warsi, G., & Dwyer, J. H. (1995). A simulation study of mediated effect measures. Multivariate Behavioral Research, 30, 41-62. Preacher, K. J., & Hayes, A. F. (2004). SPSS and SAS procedures for estimating indirect effects in simple mediation models. Behavior Research Methods,Instruments, & Computers, 36, 717-731. Preacher, K. J., & Hayes, A. F. (2008). asymptotic and resampling strategies for assessing and comparing indirect effects in multiple mediator models. Behavior Research Methods, Instruments, & Computers, 40, 879-891. Examples
mv = rnorm(1 ) iv = rnorm(1 ) dv = rnorm(1 ) mediation.test(mv,iv,dv)

model.check

Linear Regression Model Check

Description Performs tests to check the least squares assumptions for a linear regression model. Usage model.check(lmobj) Arguments lmobj Details In this function, we check the normality, independece, and constant variance assmptions of the error terms, and the presence of multicollinearity. Value A list with class "htest" containing the following components: statistic p.value parameter method data.name the value of the test statistic. the p-value of the test. degrees of freedom. a character string indicating what type of test was performed. a character string giving the name(s) of the data. A tted model

14 References To be updated. Examples


data(river) lm = lm(Nitrogen~Agr+Forest+Rsdntial+ComIndl, data=river) model.check(lm )

model.test

model.test

To compare two models and determine which one is adequate.

Description To compare a full model and reduced model to test whether the reduced model is adequate or not. Usage model.test(fmobj,rmobj,alpha= . 5) Arguments fmobj rmobj alpha Details To test a null hypothesis "H0: the RM is adequate" against "H1: the FM is adequate". The values of test statistic, p-value and critical value based on an F test will be given. Value Missing values are not allowed. Author(s) B. Wang <bwang@jaguar1.usouthal.edu> See Also lm.ci. An R object by tting a full linear regression model (FM) to a data set. An R object by tting a reduced linear regression model (RM) to a data set. Signicance level. Default: alpha=0.05.

oddsratio Examples
data(supervisor) attach(supervisor) lm = lm(Y~X1+X3) lm1 = lm(Y~X1+X2+X3+X4+X5+X6) model.test(lm1,lm )

15

oddsratio

Odds Ratio and Relative Risk

Description To compute the odds ratio and relative risk based on a 2 X 2 table. Usage oddsratio(x,alpha= . 5,n,...) Arguments x n alpha ... Details x can be a matrix or a data.frame: the rst columns showing the number of events and the second column showing the sample sizes. Exact condence limits for the odds ratio by using an algorithm based on Thomas (1971). See also Gart (1971). If the sample sizes are too large, the exact condence interval may not work due to overow problem. Asymptotic condence limits are computed according to SAS/STAT(R) 9.2 Users Guide, Second Edition. Score method: code has been published for generating condence intervals by inverting a score test. It is available from http://web.stat.u.edu/~aa/cda/R/two_sample/R2/ See also "riskratio" and "oddsratio" in R package epitools. Value OR RR ORCI RRCI an estimate of odds ratio; an estimate of realtive risk; A table showing various (1-alpha)% condence limits for OR; A table showing various (1-alpha)% condence limits for RR; A vector of length 2 of the number of events from the case and control studies. A vector of length 2 of the sample sizes. The signicance level. Default: 0.05. Controls

16 References Agresti, A. (1990) _Categorical data analysis_. New York: Wiley. Pages 59-66.

oddsratio

Agresti, A. (1992), A Survey of Exact Inference for Contingency Tables Statistical Science, Vol. 7, No. 1. (Feb., 1992), pp. 131-153. Agresti, A. (2002), Categorical Data Analysis, Second Edition, New York: John Wiley \& Sons. Fisher, R. A. (1935) The logic of inductive inference. _Journal of the Royal Statistical Society Series A_ *98*, 39-54. Fisher, R. A. (1962) Condence limits for a cross-product ratio. _Australian Journal of Statistics_ *4*, 41. Fisher, R. A. (1970) _Statistical Methods for Research Workers._ Oliver & Boyd. Mehta, C. R. and Patel, N. R. (1986) Algorithm 643. FEXACT: A Fortran subroutine for Fishers exact test on unordered r*c contingency tables. _ACM Transactions on Mathematical Software_, *12*, 154-161. Clarkson, D. B., Fan, Y. and Joe, H. (1993) A Remark on Algorithm 643: FEXACT: An Algorithm for Performing Fishers Exact Test in r x c Contingency Tables. _ACM Transactions on Mathematical Software_, *19*, 484-488. Pateeld, W. M. (1981) Algorithm AS159. An efcient method of generating r x c tables with given row and column totals. _Applied Statistics_ *30*, 91-97. Stokes, M. E., Davis, C. S., and Koch, G. G. (2000), Categorical Data Analysis Using the SAS System, Second Edition, Cary, NC: SAS Institute Inc. See Also fisher.test, chisq.test Examples
# library(bstats) x = c(1, ) n = c(7237 ,73 58) oddsratio(x,n=n) Convictions <matrix(c(2, 1 , 15, 3), nrow = 2, dimnames = list(c("Dizygotic", "Monozygotic"), c("Convicted", "Not convicted"))) Convictions fisher.test(Convictions, conf.level = .95)$conf.int x = matrix(c(2,1 ,17,13), ncol=2) oddsratio(x) Convictions <matrix(c(8, 492,

, 5

), nrow = 2, byrow=TRUE)

predictor.plot
fisher.test(Convictions, conf.level = x = c(8, ) n = c(5 ,5 ) oddsratio(x,n=n) .95)$conf.int

17

predictor.plot

Draw plots for predictor impacts on the dependent variable

Description Draw added-variable plot (av) or redidual plus component (rc) plot. Usage predictor.plot(lmobj,type=av,ID=FALSE, col=1) Arguments lmobj type ID col Value Missing value not allowed. Author(s) B. Wang <bwang@jaguar1.usouthal.edu> See Also residual.plot. Examples
data(river) lm = lm(Nitrogen~Agr+Forest+Rsdntial+ComIndl, data=river) predictor.plot(lm ) predictor.plot(lm ,type=rc)

An R object by tting an OLS model to a data set. Plot type. av: added variable plot; rc: residual plus component plot. Whether to identify points in the plots. Default: FALSE Color of the plot.

18

residual.plot

residual.plot

Draw residual plots for an ordinary regression model.

Description Draw residual plots for an ordinary regression model. Usage residual.plot(lmobj,type=fitted,col=1) Arguments lmobj type An R object by tting an OLS model to a data set. Type of residual plot(s): tted, residuals against tted values; index, residuals against index; predictor, residuals against each of the predictors in the tted model; qqplot, qq-plot of the standardized residuals to check the normality assumption. Color of the plot.

col Value

Missing values are not allowed. Author(s) B. Wang <bwang@jaguar1.usouthal.edu> See Also influential.plot. Examples
data(river) lm = lm(Nitrogen~Agr+Forest+Rsdntial+ComIndl, data=river) residual.plot(lm ) residual.plot(lm ,type=index) residual.plot(lm ,type=predictor)

scb

19

river

New York river data

Description This is a data set selected from book "Regression by examples" by Samprit Chatterjee and Ali S. Hadi. Usage data(river) Format In a 1976 study exploring the relationship between water quality and land use, Haith (1976) obtained the measurements on 20 river basins in New York State. A question of interest here is how the land use around a river basin contributes to the water pollution as measured by the mean nitrogen concentration (mg/liter). River Agr Forest Rsdntial ComIndl Nitrogen character numeric numeric numeric numeric numeric River names percentage of land area currently in agricultural use percentage of forest land percentage of land area in residential use percentage of land area either in commercial or industrial use mean nitrogen concentration

References "Regression analysis by example" by Samprit Chatterjee and Ali S. Hadi, Wiley. ISBN: 978-0-47174696-6.

scb

To compute the simultaneous condence bands.

Description To compute the simultaneous condence bands. Usage scb(x,alpha= . 5) Arguments x alpha An R object. Currently, only edf objects are supported. Signicance level. Default 0.05 for a 95 percent condence level.

20 Author(s) B. Wang <bwang@jaguar1.usouthal.edu> See Also edf. Examples


x = rnorm(1 ) (out = edf(x)) plot(out) (out2= scb(out)) lines(out2)

vif

supervisor

Supervisor performance data

Description This is a data set selected from book "Regression by examples" by Samprit Chatterjee and Ali S. Hadi. Usage data(supervisor) Format A data frame with 28829 observations on 8 variables. Y X1--X6 numeric numeric overall rating of jon being done by supervisor average score for six different aspects

References "Regression analysis by example" by Samprit Chatterjee and Ali S. Hadi, Wiley. ISBN: 978-0-47174696-6.

vif

Variance Ination Factors

vif Description

21

Calculates variance-ination and generalized variance-ination factors for linear and generalized linear models. Usage vif(object, ...) ## S3 method for class lm vif(object, ...) Arguments object ... Details If all terms in an unweighted linear model have 1 df, then the usual variance-ination factors are calculated. If any terms in an unweighted linear model have more than 1 df, then generalized variance-ination factors (Fox and Monette, 1992) are calculated. These are interpretable as the ination in size of the condence ellipse or ellipsoid for the coefcients of the term in comparison with what would be obtained for orthogonal data. The generalized vifs are invariant with respect to the coding of the terms in the model (as long as the subspace of the columns of the model matrix pertaining to each term is invariant). To adjust for the dimension of the condence ellipsoid, the function also prints GV IF 1/(2df ) where df is the degrees of freedom associated with the term. Through a further generalization, the implementation here is applicable as well to other sorts of models, in particular weighted linear models and generalized linear models, that inherit from class lm. Value A vector of vifs, or a matrix containing one row for each term in the model, and columns for the GVIF, df, and GV IF 1/(2df ) . Author(s) Henric Nilsson and John Fox <jfox@mcmaster.ca> References Fox, J. and Monette, G. (1992) Generalized collinearity diagnostics. JASA, 87, 178183. Fox, J. (2008) Applied Regression Analysis and Generalized Linear Models, Second Edition. Sage. Fox, J. and Weisberg, S. (2011) An R Companion to Applied Regression, Second Edition, Sage. an object that inherits from class lm, such as an lm or glm object. not used.

22 Examples
data(edu75) lm = lm(Y~X1+X2+X3, data=edu75) vif(lm )

white.test

white.test

White test of constant variance

Description Perform a test to check the common variance assumption for a linear regression model. Usage white.test(lmobj) Arguments lmobj Details In this function, we check constant variance assmptions of the error terms. Value A list with class "htest" containing the following components: statistic p.value parameter method data.name References White test, From Wikipedia, the free encyclopedia. Examples
data(river) lm = lm(Nitrogen~Agr+Forest+Rsdntial+ComIndl, data=river) white.test(lm )

A tted model

the value of the test statistic. the p-value of the test. degrees of freedom. a character string indicating what type of test was performed. a character string giving the name(s) of the data.

wls

23

wls

Weighted least squares estimate by groups

Description Weighted least squares estimate by groups. Usage wls(lmobj,group) Arguments lmobj group Value output the updated regressionn model with WLS. Author(s) B. Wang <bwang@jaguar1.usouthal.edu> See Also residual.plot. Examples
data(edu75) lm = lm(Y~X1+X2+X3, data=edu75) wls(lm ,group=edu75$Region)

An R object by tting an OLS model to a data set. used to cluster the data. Can be a factor or a numerical vector.

Index
Topic datasets birth, 3 edu75, 8 river, 19 supervisor, 20 Topic htest bptest, 3 dw.test, 5 model.check, 13 oddsratio, 15 white.test, 22 Topic models ld5 .logit, 10 ld5 .logitfit, 10 Topic regression ac, 2 ld5 .logit, 10 ld5 .logitfit, 10 vif, 20 Topic stats bstats, 5 edf, 7 influential.plot, 8 lm.ci, 11 model.test, 14 predictor.plot, 17 residual.plot, 18 scb, 19 wls, 23 Topic test mediation.test, 12 ac, 2 birth, 3 bptest, 3 bstats, 5 chisq.test, 16 dw.test, 5 24 edf, 7, 20 edu75, 8 fisher.test, 16 influential.plot, 8, 18 ld5 .logit, 10 ld5 .logitfit, 10 lines.glm.dose (ld5 .logit), 10 lines.scb (scb), 19 lm, 7 lm.ci, 11, 14 mediation.test, 12 model.check, 13 model.test, 11, 14 oddsratio, 15 plot.edf (edf), 7 plot.glm.dose (ld5 .logit), 10 plot.scb (scb), 19 predictor.plot, 17 print.edf (edf), 7 print.glm.dose (ld5 .logit), 10 print.odds (oddsratio), 15 print.scb (scb), 19 residual.plot, 9, 17, 18, 23 river, 19 scb, 8, 19 supervisor, 20 vif, 20 white.test, 22 wls, 23

You might also like