Librerias

library(readxl)
library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(olsrr)
## 
## Attaching package: 'olsrr'
## The following object is masked from 'package:datasets':
## 
##     rivers
library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
library(gvlma)

DESARROLLO

Modelo

datos <- read_excel('datos20221_2.xlsx')
attach(datos)
modelo <-lm(PMF~MS)
modelo
## 
## Call:
## lm(formula = PMF ~ MS)
## 
## Coefficients:
## (Intercept)           MS  
##     -210.00        25.11

Modelo

n=length(PMF)
summary(modelo)$sigma -> sigma
sqrt(sigma**2*(1/n+mean(MS)**2/sum((MS-mean(MS))^2)))
## [1] 11.96696

varianza

sigma**2/sum((MS-mean(MS))^2)
## [1] 0.6330865

cov

sPMF=sd(PMF)
sMS=sd(MS)
covar= cor(PMF,MS)*sPMF*sMS
covar
## [1] 141.6135
cov(PMF,MS)
## [1] 141.6135
modelo |> confint(level = 0.98)
##                    1 %       99 %
## (Intercept) -238.46432 -181.53696
## MS            23.21514   27.00016
modelo |> summary()
## 
## Call:
## lm(formula = PMF ~ MS)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -37.266 -12.665   2.789  12.669  30.254 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -210.0006    11.9670  -17.55   <2e-16 ***
## MS            25.1077     0.7957   31.55   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 16.26 on 73 degrees of freedom
## Multiple R-squared:  0.9317, Adjusted R-squared:  0.9308 
## F-statistic: 995.7 on 1 and 73 DF,  p-value: < 2.2e-16
r2 = cor(PMF,MS)* cor(PMF,MS)
r2 
## [1] 0.9316957
modelo |> AIC()
## [1] 635.0771

El nuevo modelo tiene modelo cuyo AIC = 635 ligeramente menor, por los decimales, según los números se tiene que optar por el menor AIC, aunque ambos modelos podrían usarse

Normalidad

library(normtest)
modelo |> residuals() -> residuales
residuales |> skewness.norm.test()
## 
##  Skewness test for normality
## 
## data:  residuales
## T = -0.44243, p-value = 0.1035
modelo |> dwtest(alternative = "two.sided")
## 
##  Durbin-Watson test
## 
## data:  modelo
## DW = 2.1617, p-value = 0.4884
## alternative hypothesis: true autocorrelation is not 0