library(stats)
library( psych )
## Warning: package 'psych' was built under R version 3.6.1
library(readxl)
## Warning: package 'readxl' was built under R version 3.6.1
library(MASS)
## Warning: package 'MASS' was built under R version 3.6.1
library(ISLR)
## Warning: package 'ISLR' was built under R version 3.6.1
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.6.1
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
base=read_xlsx("examr.xlsx")
describe(base)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## y 1 48 0.21 0.41 0.00 0.15 0.00 0.00 1.00 1.00 1.39 -0.06 0.06
## z 2 48 0.51 0.96 0.54 0.57 0.92 -2.17 2.22 4.39 -0.63 0.01 0.14
modelo_logistico <- glm(y ~ z, data = base, family = "binomial")
summary(modelo_logistico)
##
## Call:
## glm(formula = y ~ z, family = "binomial", data = base)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.4838 -0.5707 -0.3912 -0.2412 1.8094
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -1.0285 0.4104 -2.506 0.01220 *
## z -1.3492 0.4776 -2.825 0.00473 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 49.127 on 47 degrees of freedom
## Residual deviance: 38.208 on 46 degrees of freedom
## AIC: 42.208
##
## Number of Fisher Scoring iterations: 5
solicitud=data.frame(z=1.5)
predict(modelo_logistico, solicitud, "response")
## 1
## 0.04512001
-1.3492*.04512001
## [1] -0.06087592
ggplot(data = base, aes(x =z, y = y)) +
geom_point(aes(color = as.factor(y)), shape = 1) +
geom_smooth(method = "glm",
method.args = list(family = "binomial"),
color = "gray20",
se = FALSE) +
theme_bw() +
theme(legend.position = "none")
