‘’’{r} library(alr4) ‘’’

data(UN11)
## Warning in data(UN11): data set 'UN11' not found
help("UN11")
## No documentation for 'UN11' in specified packages and libraries:
## you could try '??UN11'

Dependence of fertility on Per person Gross domestic product

The predictor is ppgdp and the response is fertility (or the birth rate per 1,000)

library(alr4)
## Loading required package: car
## Loading required package: effects
## 
## Attaching package: 'effects'
## The following object is masked from 'package:car':
## 
##     Prestige
data("UN11")
plot(fertility ~ ppgdp, data = UN11)

Summarize the Information in this graph.

The graph demonstrates that there is a negative correlation between Per person GDP and fertility The data demonstrates an exponential relationship, making a logarithmic fit more appropriate. Although the straight-line mean function will demonstrate the negative relationship, It will be a biased line due to the ends of the data points.

Plot the log for the variables. ‘’’{r} plot(log(fertility) ~ log(ppgdp), data = UN11) ‘’’ Simple Linear Regression does seem appropriate for this graph, since the negative calculation clearly follows a linear path.

‘’’{r} data(“Rateprof”) head(Rateprof) help(“Rateprof”)

pairs(~quality+helpfulness+clarity+easiness+raterInterest, data = Rateprof) ‘’’

The strongest correlations between the variables are quality, helpfulness, and clarity all of which demonstrate a strong linear correlation. The variables easiness and raterInterest; however, do not show a strong correlation between the variables helpfulness, quality, and clarity, and even less correlation between themselves.

‘’’{r} data(Htwt) head(Htwt) ‘’’

‘’’{r} plot(Htwt\(ht,Htwt\)wt) ‘’’ A simple linear regression does not make sense in this case because its correlation, although present, is very weak and dispersed.

‘’’{r} dim(Htwt) n=10

(xbar = mean(Htwt\(ht)) (ybar = mean(Htwt\)wt))

(sxx = sum((Htwt$ht-xbar)^2))

(syy = sum((Htwt$wt-ybar)^2))

(sxy = sum((Htwt\(ht-xbar)*(Htwt\)wt-ybar)))

(reg.line = lm(wt~ht, data = Htwt))

abline(reg.line, col = “red”) ‘’’

Obtain the estimate of the variance and find the estimated standard errors of B0 and B1. Find Estimated Covariance between B0 and B1 Compute T-Tests for the hypotheses that Bo=0 and B1=0 Find the Appropriate P-Values using the appropriate test ‘’’{r} (B0 = -36.8759) (B1 = 0.5821)

(RSS = sum(((Htwt\(wt) - (B0 + (B1 * Htwt\)ht)))^2))

(evarht = (RSS/(n-2))) ‘’’

The estimated variance (evarht) for the graph is 71.50171

Estimate standard errors of B0 and B1 (demarcated by eB1 and EB0) ‘’’{r} (eB1 = sum((Htwt$ht-xbar)/(sxx))) ‘’’

‘’’{r} data(“UBSprices”) head(UBSprices) help(“UBSprices”) ‘’’

The points above the line indiccate that the price of Rice in 2009 is greater than the price of rice in 2003 The points below the y=x line indicate that the price of rice in said locations is greater in 2003 than in 2009

Mumbai had the largest decrease in price, dropping from over 90 to less than 40 Vilnius had the largest increase in price, increasing from ~20 to ~80

eB1<1 does suggest that prices of rice in 2003 were greater than the prices of rice in 2009. This is because for every 1 unit increase in Price of Rice 2003, there is a less than one unit increase in the price of rice 2009, at least according to eB1

  1. the data observed is better fitted with a logarithmic line, as all of the data follows that trend with only a few outliers.
  2. The other reason is that the data is more likely to be skewed by the points Nairobi and mumbai.

‘’’{r} head(UBSprices)

plot(bigmac2009 ~ bigmac2003, data = UBSprices) ‘’’ Draw the fitted OLS line ‘’’{r} (reg.line = lm(bigmac2009 ~ bigmac2003, data = UBSprices)) abline(reg.line, col = “blue”) ‘’’ Draw the line y=x ‘’’{r} abline(0,1)

install.packages(“calibrate”) library(calibrate) ‘’’ Identify the most unusual Cases

One unusual point is the one over 150+ in both cases, because its price in obscenely higher than the other data points

This is not appropriate for the data because the data follows a logrithmic trend on either side of y=x, skewing the fitted line in the linear regression.

‘’’{r} plot(log(bigmac2009) ~ log(bigmac2003), data = UBSprices)

(reg.line = lm(log(bigmac2009 ~ bigmac2003, data = UBSprices))) abline(reg.line, col = “blue”) ‘’’ this graph is nore sensible because the data follows a linear trend.

‘’’{r} library(alr4) data(“Heights”) dim(Heights) n = 1375

model = lm(dheight ~ mheight, data= Heights) ‘’’ # bhat1 - qt(.005, lower = F, df = n-2)se(bhat1), # bhat1 + qt(.005, lower = F, df= n-2) se(bhat1) ‘’’{r} confint(model, level = 0.99)

predict(model, data.frame(mheight = 64), interval = “prediction”, level = .99)

help(qt) ‘’’