Читать книгу Statistics and Probability with Applications for Engineers and Scientists Using MINITAB, R and JMP - Bhisham C. Gupta, Irwin Guttman - Страница 104

MINITAB:

Оглавление

1 Enter the pairs of data in columns C1 and C2. Label the columns X and Y.

2 From the Menu bar select Graph Scatterplot. This prompts a dialog box to appear on the screen. In this dialog box, select scatterplot With Regression and click OK. This prompts the following dialog box to appear:In this dialog box, under the X and Y variables, enter the columns in which you have placed the data. Use the desired options and click OK. The Scatter plot shown in Figure 2.9.1 appears in the Session window.

3 For calculating the correlation coefficient, select from the Menu bar Stat Basic Statistics Correlation. Then, enter the variables C1 and C2 in the dialog box.

USING R

We can use a built in ‘plot()’ function in R to generate scatter plots. Extra arguments such as ‘pch’ and ‘cex’ can be used to specify the plotting symbol and size of the symbol, respectively. Finally, the function ‘abline()’ can be used to embed the trend line to the scatter plot as follows. The function ‘cor()’ can be used to calculate the Pearson correlation coefficient. The whole task can be completed by running the following R code in the R Console window.

x = c(195,180,220,160,200,220,200,183,139,155) y = c(130,128,138,122,140,148,142,127,116,123) #To plot the data in a scatter plot plot(x, y, pch = 20, cex = 2, main = ‘Scatterplot for Cholesterol Level and Systolic Blood Pressure Data’, xlab = ‘Cholesterol Level’, ylab = ‘Systolic Blood Pressure’) #To add a trend line abline(lm(y x), col = ‘red’) #To calculate the Pearson correlation coefficient cor(x, y) 0.9242063

The resulting R scatter plot for the data in Table 2.9.1 looks exactly the same as in the MINTAB printout in Figure 2.9.1.

Statistics and Probability with Applications for Engineers and Scientists Using MINITAB, R and JMP

Подняться наверх