library(pacman)
p_load("prettydoc", "DT", "xfun", "dplyr", "psych", "GGally", "ggplot2","readr", "gridExtra")
Construya un modelo utilizando la regresión lineal múltiple para estimar la esperanza de vida con datos de estados unidos.
Un estudio quiere generar un modelo que permita predecir la esperanza de vida media de los habitantes de una ciudad en función de diferentes variables. Se dispone de información sobre:
habitantes de una ciudad en función de diferentes variables. Se dispone de información sobre:
state.x77: matrix with 50 rows and 8 columns giving the following statistics in the respective columns.
Population: population estimate as of July 1, 1975
Income: per capita income (1974)
Illiteracy: illiteracy (1970, percent of population)
Life Exp: life expectancy in years (1969–71)
Murder: murder and non-negligent manslaughter rate per 100,000 population (1976)
HS Grad: percent high-school graduates (1970)
Frost: mean number of days with minimum temperature below freezing (1931–1960) in capital or large city
Area: land area in square miles
Source U.S. Department of Commerce, Bureau of the Census (1977) Statistical Abstract of the United States.
U.S. Department of Commerce, Bureau of the Census (1977) County and City Data Book.
References Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
datos <- as.data.frame(state.x77)
head(datos)
## Population Income Illiteracy Life Exp Murder HS Grad Frost Area
## Alabama 3615 3624 2.1 69.05 15.1 41.3 20 50708
## Alaska 365 6315 1.5 69.31 11.3 66.7 152 566432
## Arizona 2212 4530 1.8 70.55 7.8 58.1 15 113417
## Arkansas 2110 3378 1.9 70.66 10.1 39.9 65 51945
## California 21198 5114 1.1 71.71 10.3 62.6 20 156361
## Colorado 2541 4884 0.7 72.06 6.8 63.9 166 103766
datos <- rename(habitantes = Population, analfabetismo = Illiteracy,
ingresos = Income, esp_vida = `Life Exp`, asesinatos = Murder,universitarios = `HS Grad`, heladas = Frost, area = Area,.data = datos)
datos <- mutate(.data=datos, densidad_pobl = habitantes * 1000 / area)
head(datos)
## habitantes ingresos analfabetismo esp_vida asesinatos universitarios
## Alabama 3615 3624 2.1 69.05 15.1 41.3
## Alaska 365 6315 1.5 69.31 11.3 66.7
## Arizona 2212 4530 1.8 70.55 7.8 58.1
## Arkansas 2110 3378 1.9 70.66 10.1 39.9
## California 21198 5114 1.1 71.71 10.3 62.6
## Colorado 2541 4884 0.7 72.06 6.8 63.9
## heladas area densidad_pobl
## Alabama 20 50708 71.2905261
## Alaska 152 566432 0.6443845
## Arizona 15 113417 19.5032491
## Arkansas 65 51945 40.6198864
## California 20 156361 135.5708904
## Colorado 166 103766 24.4877898