01.03.2013 Views

Applied Statistics Using SPSS, STATISTICA, MATLAB and R

Applied Statistics Using SPSS, STATISTICA, MATLAB and R

Applied Statistics Using SPSS, STATISTICA, MATLAB and R

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

278 7 Data Regression<br />

Next, we create the X matrix by binding a column of ones, corresponding to the<br />

intercept term in equation 7.1, to the PRT vector:<br />

>> X = [PRT ones(size(PRT,1),1)]<br />

We are now ready to apply the regress function:<br />

>> [b,bint,r,rint,stats] = regress(ART,X,0.05);<br />

The values of b, bint <strong>and</strong> stats are as follows:<br />

>> b<br />

b =<br />

0.5469<br />

-64.4902<br />

>> bint<br />

bint =<br />

0.5294 0.5644<br />

-78.4285 -50.5519<br />

>> stats<br />

stats =<br />

1.0e+003 *<br />

0.0010 3.8135 0<br />

The values of b coincide with those in Figure 7.3. The intercept coefficient is<br />

here the second element of b in correspondence with the (second) column of ones<br />

of X. The values of bint are the 95% confidence intervals of b agreeing with the<br />

values computed in Example 7.2 <strong>and</strong> Example 7.4, respectively. Finally, the first<br />

value of stats is the R-square statistic; the second <strong>and</strong> third values are<br />

respectively the ANOVA F <strong>and</strong> p discussed in section 7.1.4 <strong>and</strong> reported in Table<br />

7.1. The exact value of the R-square statistic (without the four-digit rounding effect<br />

of the above representation) can be obtained by previously issuing the format<br />

long comm<strong>and</strong>.<br />

Let us now illustrate the use of the R lm function for the same problem as in<br />

Example 7.1. We have already used the lm function in Chapter 4 when computing<br />

the ANOVA tests (see Comm<strong>and</strong>s 4.5 <strong>and</strong> 4.6). This function fits a linear model<br />

describing the y data as a function of the X data. In chapter 4 the X data was a<br />

categorical data vector (an R factor). Here, the X data correspond to the real-valued<br />

predictors. <strong>Using</strong> the cork data frame we may run the lm function as follows:<br />

> load(“e:cork”)<br />

> attach(cork)<br />

> summary(lm(ART~PRT))<br />

Call:<br />

lm(formula = ART ~ PRT)<br />

Residuals:<br />

Min 1Q Median 3Q Max<br />

-95.651 -22.727 -1.016 19.012 152.143

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!