UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SPLUS Textbook Examples
Computer-Aided Multivariate Analysis by Afifi and Clark
Chapter 6: Simple Linear Regression and Correlation

SPLUS program
R program

Creating the variable ffev1a = ffev1/100.

lung$ffev1a <- lung$ffev1/100

Fitting the regression for ffev1a regressed on fheight.

lm1 <- lm(ffev1a ~ fheight, lung, na.action=na.exclude)
print(lm1)

Coefficients:
 (Intercept)   fheight 
   -4.086702 0.1181052

Degrees of freedom: 150 total; 148 residual
Residual standard error: 0.5638018 

Predicting the fitted values for the regression.

lung$p <- predict(lm1)

Fig. 6.1, p. 87
Scatter diagram and regression line of fev1 versus height for fathers in lung function data.
Note: We are using the built in plots function for the regression objects. To interactively see all the plots use the following code. The which.plot option in the code for the scatter plot lets us see just one specific plot.

plot(lm1, which.plot=3)

The descriptive statistics at the top of the page, p. 88.

mean(lung$fheight)
mean(lung$ffev1a)
stdev(lung$fheight) 
stdev(lung$ffev1a)

> mean(lung$fheight)
[1] 69.26
> mean(lung$ffev1a)
[1] 4.093267
> stdev(lung$fheight)
[1] 2.779189
> stdev(lung$ffev1a)
[1] 0.6507523
print( c(mean(lung$fheight), mean(lung$ffev1a), stdev(lung$fheight), 
stdev(lung$ffev1a) ) )

[1] 69.2600000  4.0932667  2.7791892  0.6507523

The correlation in the middle of the page, p. 99

cor.test(lung$fheight, lung$ffev1a)

	Pearson's product-moment correlation 

data:  lung$fheight and lung$ffev1a 
t = 7.1065, df = 148, p-value = 0 
alternative hypothesis: true coef is not equal to 0 
sample estimates:
      cor 
 0.504396

Table 6.2, p. 101
ANOVA table for regression model in fig. 6.2.

aov1 <- aov(ffev1a~fheight, lung)
summary(aov1)

           Df Sum of Sq  Mean Sq  F Value         Pr(F) 
  fheight   1  16.05317 16.05317 50.50192 4.677037e-011
Residuals 148  47.04513  0.31787

Fig. 6.11, p. 116
Normal probability plot of the residuals of the regression of FEV1 on height for fathers in the lung function data.

plot(lm1, which.plot=4)


How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California