plot(circumference~age, data=Orange)
lm.fit=lm(circumference~age, data=Orange)
summary(lm.fit)
##
## Call:
## lm(formula = circumference ~ age, data = Orange)
##
## Residuals:
## Min 1Q Median 3Q Max
## -46.310 -14.946 -0.076 19.697 45.111
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 17.399650 8.622660 2.018 0.0518 .
## age 0.106770 0.008277 12.900 1.93e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 23.74 on 33 degrees of freedom
## Multiple R-squared: 0.8345, Adjusted R-squared: 0.8295
## F-statistic: 166.4 on 1 and 33 DF, p-value: 1.931e-14
plot(circumference~age, data=Orange)
abline(17.399650,0.106770,col='blue')
Predecir 5 valores
lm.fit=lm(circumference~age, data=Orange)
lm.fit
##
## Call:
## lm(formula = circumference ~ age, data = Orange)
##
## Coefficients:
## (Intercept) age
## 17.3997 0.1068
predict.lm(lm.fit,data.frame(age= c(90,200,500,700,900)))
## 1 2 3 4 5
## 27.00898 38.75372 70.78481 92.13888 113.49294
lm.fit=lm(c(27.0089, 38.75372, 70.78481, 92.13888, 113.49294 ,circumference)~c(90,200,500,700,900,age), data=Orange)
summary(lm.fit)
##
## Call:
## lm(formula = c(27.0089, 38.75372, 70.78481, 92.13888, 113.49294,
## circumference) ~ c(90, 200, 500, 700, 900, age), data = Orange)
##
## Residuals:
## Min 1Q Median 3Q Max
## -46.31 -11.63 0.00 11.76 45.11
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 17.39964 7.12312 2.443 0.0193 *
## c(90, 200, 500, 700, 900, age) 0.10677 0.00716 14.911 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 22.12 on 38 degrees of freedom
## Multiple R-squared: 0.854, Adjusted R-squared: 0.8502
## F-statistic: 222.4 on 1 and 38 DF, p-value: < 2.2e-16
circunferencia = c(27.0089, 38.75372, 70.78481, 92.13888, 113.49294 ,Orange$circumference)
edad = c(90,200,500,700,900,Orange$age)
plot(circunferencia~edad, data=Orange)
abline(17.399650,0.106770,col='blue')
Los nuevos coeficientes son 0.10677 para la pendiente y 17.39964 para la
intercepción, comparandolos con los coeficientes antes de añadir estos
nuevos datos, los cuales eran 0.106770 para la pendiente y 17.399650
para la intercepción, no hay un cambio significativos en éstos.
Ahora multiplicando cualquier punto por 100 se obtiene
lm.fit=lm(c(circumference[1]*100,circumference[2: 35] )~c(age[1]*100, age[2:35]), data=Orange)
summary(lm.fit)
##
## Call:
## lm(formula = c(circumference[1] * 100, circumference[2:35]) ~
## c(age[1] * 100, age[2:35]), data = Orange)
##
## Residuals:
## Min 1Q Median 3Q Max
## -144.08 -63.23 -11.31 56.62 123.19
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.204e+02 1.575e+01 -7.642 8.5e-09 ***
## c(age[1] * 100, age[2:35]) 2.556e-01 6.999e-03 36.527 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 77.31 on 33 degrees of freedom
## Multiple R-squared: 0.9759, Adjusted R-squared: 0.9751
## F-statistic: 1334 on 1 and 33 DF, p-value: < 2.2e-16
circunferencia = c(Orange$circumference[1]*100,Orange$circumference[2: 35])
edad = c(Orange$age[1]*100, Orange$age[2:35])
plot(circunferencia~edad, data=Orange)
abline(-1.204e+02,2.556e-01,col='blue')
Se puede notar una gran diferencia en los valores de los coeficientes, pero esto como se puede ver en el gráfico se debe principalmente en la “lejania” del punto multiplicado por 100 con los demás datos.