R Markdown

library(readxl)
library(ggplot2)
## Warning in as.POSIXlt.POSIXct(Sys.time()): unable to identify current timezone 'H':
## please set environment variable 'TZ'
library(CGPfunctions)

caso = read_excel("D:/Maestria/Metodos estadisticos/Regresion/caso.xlsx")

Punto A) Grafico

attach(caso)
plot(desempleo,homicidios,pch=16)

Punto B) Coeficiente de correlación

cor(desempleo,homicidios)
## [1] 0.9608183

Punto C) modelo de regresión y se aplica una transformación

mod=lm(log(homicidios)~desempleo)
summary(mod)
## 
## Call:
## lm(formula = log(homicidios) ~ desempleo)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.08538 -0.02273  0.00001  0.02223  0.09549 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.027556   0.075235  -13.66 3.08e-16 ***
## desempleo    0.486124   0.006262   77.64  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.03791 on 38 degrees of freedom
## Multiple R-squared:  0.9937, Adjusted R-squared:  0.9936 
## F-statistic:  6027 on 1 and 38 DF,  p-value: < 2.2e-16

Punto D) SUpuestos

par(mfrow=c(2,2))
plot(mod)

Punto E) Predicción

predict(mod,newdata = list(desempleo=11))
##        1 
## 4.319804
# por aplicar el logaritmo
exp(predict(mod,newdata = list(desempleo=11)))
##        1 
## 75.17389