require(moonBook)
data(acs)
acs$smoking=factor(acs$smoking, levels=c("Never","Ex-smoker","Smoker"))
plot(age~smoking,data=acs,color=c("red","green","blue"))
## Analysis of Variance Table
##
## Response: age
## Df Sum Sq Mean Sq F value Pr(>F)
## smoking 2 12164 6082.2 49.497 < 2.2e-16 ***
## Residuals 854 104939 122.9
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Call:
## lm(formula = age ~ smoking, data = acs)
##
## Residuals:
## Min 1Q Median 3Q Max
## -37.745 -7.458 0.491 8.491 32.542
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 66.5090 0.6084 109.322 <2e-16 ***
## smokingEx-smoker -0.7639 0.9861 -0.775 0.439
## smokingSmoker -8.0511 0.8677 -9.279 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11.09 on 854 degrees of freedom
## Multiple R-squared: 0.1039, Adjusted R-squared: 0.1018
## F-statistic: 49.5 on 2 and 854 DF, p-value: < 2.2e-16
##
## Call:
## lm(formula = age ~ smoking + BMI, data = acs)
##
## Residuals:
## Min 1Q Median 3Q Max
## -41.817 -7.410 0.157 8.165 29.919
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 85.0774 2.9141 29.195 < 2e-16 ***
## smokingEx-smoker -1.1299 1.0352 -1.091 0.275
## smokingSmoker -8.0736 0.8948 -9.023 < 2e-16 ***
## BMI -0.7669 0.1176 -6.521 1.28e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 10.86 on 760 degrees of freedom
## (93 observations deleted due to missingness)
## Multiple R-squared: 0.147, Adjusted R-squared: 0.1436
## F-statistic: 43.65 on 3 and 760 DF, p-value: < 2.2e-16
colors=rainbow(acs$smoking)
colors=colors[c(3,2,1)]
plot(age~BMI, col=colors, data=acs)
legend("topright", legend=levels(acs$smoking), pch=1, col=colors,lty=1)
curve(85.077-0.767*x, col=colors[1],add=TRUE)
curve(85.077-0.767*x-1.130, col=colors[2],add=TRUE)
curve(85.077-0.767*x-8.074, col=colors[3],add=TRUE)
##
## Simultaneous Tests for General Linear Hypotheses
##
## Multiple Comparisons of Means: Tukey Contrasts
##
##
## Fit: lm(formula = age ~ smoking + BMI, data = acs)
##
## Linear Hypotheses:
## Estimate Std. Error t value Pr(>|t|)
## Ex-smoker - Never == 0 -1.1299 1.0352 -1.091 0.518
## Smoker - Never == 0 -8.0736 0.8948 -9.023 <1e-04 ***
## Smoker - Ex-smoker == 0 -6.9437 1.0399 -6.677 <1e-04 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## (Adjusted p values reported -- single-step method)
##
## Call:
## lm(formula = NTAV ~ age, data = radial)
##
## Residuals:
## Min 1Q Median 3Q Max
## -45.231 -14.626 -4.803 9.685 100.961
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 44.3398 14.6251 3.032 0.00302 **
## age 0.3848 0.2271 1.694 0.09302 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 23.94 on 113 degrees of freedom
## Multiple R-squared: 0.02477, Adjusted R-squared: 0.01614
## F-statistic: 2.87 on 1 and 113 DF, p-value: 0.09302
plot(NTAV~age, data=radial, col=ifelse(radial$sex=="M","blue","red"))
abline(out,col="red",lwd=2)
title(expression(italic(NTAV==0.385%*%Age+44.34)),family="Times") - 남자는 파란색, 여자는 빨간으로 구별하여 plot()을 해보면 남자가 여자보다 동맥경화 정도가 심한 것을 알 수 있습니다.
##
## Call:
## lm(formula = NTAV ~ age - 1, data = radial)
##
## Residuals:
## Min 1Q Median 3Q Max
## -40.235 -13.726 -4.613 10.168 98.343
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## age 1.06532 0.03589 29.68 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 24.78 on 114 degrees of freedom
## Multiple R-squared: 0.8854, Adjusted R-squared: 0.8844
## F-statistic: 881 on 1 and 114 DF, p-value: < 2.2e-16
plot(NTAV~age, data=radial, col=ifelse(radial$sex=="M","blue","red"))
abline(out1,col="red",lwd=2)
title(expression(italic(NTAV==1.065%*%Age)),family="Times")
## bcPower Transformation to Normality
## Est Power Rounded Pwr Wald Lwr Bnd Wald Upr Bnd
## radial$NTAV -0.0533 0 -0.4229 0.3164
##
## Likelihood ratio test that transformation parameter is equal to 0
## (log transformation)
## LRT df pval
## LR test, lambda = (0) 0.07953273 1 0.77793
##
## Likelihood ratio test that no transformation is needed
## LRT df pval
## LR test, lambda = (1) 29.48666 1 5.6303e-08
##
## Call:
## lm(formula = log(NTAV) ~ (age - 1) + male, data = radial)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.29896 -0.26180 0.05829 0.42898 1.93835
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## age 0.059381 0.001116 53.19 < 2e-16 ***
## male 0.655927 0.101216 6.48 2.48e-09 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5681 on 113 degrees of freedom
## Multiple R-squared: 0.9819, Adjusted R-squared: 0.9816
## F-statistic: 3072 on 2 and 113 DF, p-value: < 2.2e-16
##
## Shapiro-Wilk normality test
##
## data: resid(out2)
## W = 0.99116, p-value = 0.671
plot(log(NTAV)~age, data=radial, col=ifelse(radial$sex=="M","blue","red"))
curve(0.0594*x, col='red', lty=2, add=TRUE)
curve(0.0594*x+0.656, col='blue', lty=1, add=TRUE)
legend("topleft", legend=c("Male","Female"), col=c("blue","red"),pch=1,lty=1:2)
plot(NTAV~age, data=radial, col=ifelse(radial$sex=="M","blue","red"))
curve(exp(0.0594*x), col='red', lty=2, add=TRUE)
curve(exp(0.0594*x+0.656), col='blue', lty=1, add=TRUE)
title(expression(NTAV==e^(0.0594%*%age+0.656%*%male)), family="Times")
legend("topleft", legend=c("Male","Female"), col=c("blue","red"),pch=1,lty=1:2)
plot(NTAV~age, data=radial, col=ifelse(radial$sex=="M","blue","red"), pch=as.character(sex))
curve(exp(0.0594*x), col='red', lty=2, add=TRUE)
curve(exp(0.0594*x+0.656), col='blue', lty=1, add=TRUE)
title(expression(NTAV==e^(0.0594%*%age+0.656%*%male)), family="Times")
legend("topleft", legend=c("Male","Female"), col=c("blue","red"),pch=1,lty=1:2)