Economics of Money and Banking / Perry G Mehrling / Ders 1

R Studio Statistics II

The correlation and regression:

Firstly, we created random number with the sample() function. The 10 different numbers are selected from 1 to 100.

a=sample(1:100, 10)

b=sample(1:100, 10)


c=sample(1:100, 10)


We created the data.frame with our 3 variables' datasets.

price = data.frame(a,b,c)

Now, we calculate the correlation among the variables

 cor(price$a,price$b)

 -0.1215828

cor(price$a,price$c)

 0.4716212

cor(price$b,price$c)


 0.06092046

It is time to see relationship between two different variables

a is dependent and c is independent variable.

reg=lm(a~c, data = price)

summary(reg)


and other complimentaries

predict(reg)

residuals(reg)

coefficients(reg)

lm(formula = a ~ c + b, data = price)


                  Source:R Programming and Its Applications in Financial Mathematics

Yorumlar