############################################################################################################################################################ > ####### Upload data from Excel########################################################################################################################### > nhanes5 <- D_S_Data %>% mutate_if(is.character,as.factor) > class(nhanes5) [1] "tbl_df" "tbl" "data.frame" > print(nhanes5) # A tibble: 561 x 9 SEQN Gender Age SDMVPSU SDMVSTRA WTSA2YR Zinc_S Zinc_D Fasting 1 83741 1 22 2 128 31201. 80.6 8.44 9 2 83742 2 32 1 125 56483. 80.7 8 3 3 83751 2 16 1 128 77496. 57.3 4.3 1 4 83752 2 30 1 124 38172. 87.9 9.73 1 5 83753 1 15 1 119 60525. 81.4 11.4 10 6 83756 1 16 1 122 44825. 81.4 15.2 5 7 83759 2 19 2 121 175767. 139. 15.0 2 8 83762 2 27 1 132 48873. 122. 9.26 6 9 83768 2 15 2 120 195690. 80.4 5.58 13 10 83770 1 15 2 132 50926. 70 7.98 10 # ... with 551 more rows > > ######### Summary of Data################ > summary(nhanes5) SEQN Gender Age SDMVPSU SDMVSTRA WTSA2YR Min. :83741 Min. :1.000 Min. :13.00 Min. :1.000 Min. :119.0 Min. : 18595 1st Qu.:84405 1st Qu.:1.000 1st Qu.:16.00 1st Qu.:1.000 1st Qu.:122.0 1st Qu.: 48558 Median :85052 Median :2.000 Median :22.00 Median :1.000 Median :126.0 Median : 69262 Mean :85060 Mean :1.528 Mean :22.74 Mean :1.467 Mean :126.1 Mean :104401 3rd Qu.:85682 3rd Qu.:2.000 3rd Qu.:29.00 3rd Qu.:2.000 3rd Qu.:130.0 3rd Qu.:116485 Max. :86421 Max. :2.000 Max. :35.00 Max. :2.000 Max. :133.0 Max. :708844 Zinc_S Zinc_D Fasting Min. : 44.00 Min. : 1.640 Min. : 0.000 1st Qu.: 71.00 1st Qu.: 6.715 1st Qu.: 1.000 Median : 81.20 Median : 9.130 Median : 4.000 Mean : 81.41 Mean :10.163 Mean : 5.934 3rd Qu.: 90.40 3rd Qu.:12.490 3rd Qu.:11.000 Max. :139.10 Max. :38.560 Max. :29.000 > > ###########Structure of the Data############ > str(nhanes5) tibble [561 x 9] (S3: tbl_df/tbl/data.frame) $ SEQN : num [1:561] 83741 83742 83751 83752 83753 ... $ Gender : num [1:561] 1 2 2 2 1 1 2 2 2 1 ... $ Age : num [1:561] 22 32 16 30 15 16 19 27 15 15 ... $ SDMVPSU : num [1:561] 2 1 1 1 1 1 2 1 2 2 ... $ SDMVSTRA: num [1:561] 128 125 128 124 119 122 121 132 120 132 ... $ WTSA2YR : num [1:561] 31201 56483 77496 38172 60525 ... $ Zinc_S : num [1:561] 80.6 80.7 57.3 87.9 81.4 ... $ Zinc_D : num [1:561] 8.44 8 4.3 9.73 11.39 ... $ Fasting : num [1:561] 9 3 1 1 10 5 2 6 13 10 ... > > ######## Head of structure################ > head(nhanes5) # A tibble: 6 x 9 SEQN Gender Age SDMVPSU SDMVSTRA WTSA2YR Zinc_S Zinc_D Fasting 1 83741 1 22 2 128 31201. 80.6 8.44 9 2 83742 2 32 1 125 56483. 80.7 8 3 3 83751 2 16 1 128 77496. 57.3 4.3 1 4 83752 2 30 1 124 38172. 87.9 9.73 1 5 83753 1 15 1 119 60525. 81.4 11.4 10 6 83756 1 16 1 122 44825. 81.4 15.2 5 > > ############Tail of structure############ > tail(nhanes5) # A tibble: 6 x 9 SEQN Gender Age SDMVPSU SDMVSTRA WTSA2YR Zinc_S Zinc_D Fasting 1 86399 2 35 2 130 77879. 84.4 11.7 10 2 86402 1 19 2 122 158043. 91.7 14.6 0 3 86409 2 21 1 124 64143. 89.6 30.8 14 4 86410 1 16 2 131 59296. 97.1 7.69 6 5 86415 2 21 2 123 47978. 64.3 7.36 0 6 86421 2 15 2 126 37929. 83.3 9.07 0 > > ######Determine Column Names############### > > colnames(nhanes5) [1] "SEQN" "Gender" "Age" "SDMVPSU" "SDMVSTRA" "WTSA2YR" "Zinc_S" "Zinc_D" "Fasting" > > ########################## Create Survey Weight Equation ############################################################################################################## > library("survey") > > nhc5 <- svydesign(id=~SDMVPSU, weights=~WTSA2YR, strata=~SDMVSTRA, nest=TRUE, survey.lonely.psu = "adjust", data= nhanes5) > summary(nhc5) Stratified 1 - level Cluster Sampling design (with replacement) With (30) clusters. svydesign(id = ~SDMVPSU, weights = ~WTSA2YR, strata = ~SDMVSTRA, nest = TRUE, survey.lonely.psu = "adjust", data = nhanes5) Probabilities: Min. 1st Qu. Median Mean 3rd Qu. Max. 1.411e-06 8.585e-06 1.444e-05 1.601e-05 2.059e-05 5.378e-05 Stratum Sizes: 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 obs 31 48 48 37 25 39 33 38 34 28 29 39 46 52 34 design.PSU 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 actual.PSU 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 Data variables: [1] "SEQN" "Gender" "Age" "SDMVPSU" "SDMVSTRA" "WTSA2YR" "Zinc_S" "Zinc_D" "Fasting" > str(nhc5) List of 9 $ cluster :'data.frame': 561 obs. of 1 variable: ..$ SDMVPSU: Factor w/ 30 levels "119.1","119.2",..: 20 13 19 11 1 7 6 27 4 28 ... ..- attr(*, "terms")=Classes 'terms', 'formula' language ~SDMVPSU .. .. ..- attr(*, "variables")= language list(SDMVPSU) .. .. ..- attr(*, "factors")= int [1, 1] 1 .. .. .. ..- attr(*, "dimnames")=List of 2 .. .. .. .. ..$ : chr "SDMVPSU" .. .. .. .. ..$ : chr "SDMVPSU" .. .. ..- attr(*, "term.labels")= chr "SDMVPSU" .. .. ..- attr(*, "order")= int 1 .. .. ..- attr(*, "intercept")= int 1 .. .. ..- attr(*, "response")= int 0 .. .. ..- attr(*, ".Environment")= .. .. ..- attr(*, "predvars")= language list(SDMVPSU) .. .. ..- attr(*, "dataClasses")= Named chr "numeric" .. .. .. ..- attr(*, "names")= chr "SDMVPSU" $ strata :'data.frame': 561 obs. of 1 variable: ..$ SDMVSTRA: num [1:561] 128 125 128 124 119 122 121 132 120 132 ... ..- attr(*, "terms")=Classes 'terms', 'formula' language ~SDMVSTRA .. .. ..- attr(*, "variables")= language list(SDMVSTRA) .. .. ..- attr(*, "factors")= int [1, 1] 1 .. .. .. ..- attr(*, "dimnames")=List of 2 .. .. .. .. ..$ : chr "SDMVSTRA" .. .. .. .. ..$ : chr "SDMVSTRA" .. .. ..- attr(*, "term.labels")= chr "SDMVSTRA" .. .. ..- attr(*, "order")= int 1 .. .. ..- attr(*, "intercept")= int 1 .. .. ..- attr(*, "response")= int 0 .. .. ..- attr(*, ".Environment")= .. .. ..- attr(*, "predvars")= language list(SDMVSTRA) .. .. ..- attr(*, "dataClasses")= Named chr "numeric" .. .. .. ..- attr(*, "names")= chr "SDMVSTRA" $ has.strata: logi TRUE $ prob : Named num [1:561] 3.21e-05 1.77e-05 1.29e-05 2.62e-05 1.65e-05 ... ..- attr(*, "names")= chr [1:561] "1" "2" "3" "4" ... $ allprob :'data.frame': 561 obs. of 1 variable: ..$ WTSA2YR: num [1:561] 3.21e-05 1.77e-05 1.29e-05 2.62e-05 1.65e-05 ... $ call : language svydesign(id = ~SDMVPSU, weights = ~WTSA2YR, strata = ~SDMVSTRA, nest = TRUE, survey.lonely.psu = "adjust", data = nhanes5) $ variables :'data.frame': 561 obs. of 9 variables: ..$ SEQN : num [1:561] 83741 83742 83751 83752 83753 ... ..$ Gender : num [1:561] 1 2 2 2 1 1 2 2 2 1 ... ..$ Age : num [1:561] 22 32 16 30 15 16 19 27 15 15 ... ..$ SDMVPSU : num [1:561] 2 1 1 1 1 1 2 1 2 2 ... ..$ SDMVSTRA: num [1:561] 128 125 128 124 119 122 121 132 120 132 ... ..$ WTSA2YR : num [1:561] 31201 56483 77496 38172 60525 ... ..$ Zinc_S : num [1:561] 80.6 80.7 57.3 87.9 81.4 ... ..$ Zinc_D : num [1:561] 8.44 8 4.3 9.73 11.39 ... ..$ Fasting : num [1:561] 9 3 1 1 10 5 2 6 13 10 ... $ fpc :List of 2 ..$ popsize : NULL ..$ sampsize: int [1:561, 1] 2 2 2 2 2 2 2 2 2 2 ... ..- attr(*, "class")= chr "survey_fpc" $ pps : logi FALSE - attr(*, "class")= chr [1:2] "survey.design2" "survey.design" > ################################################################################################################################################################################### > ### Subset 13-35 > > svycor(~Zinc_S + Zinc_D, design = nhc5) Zinc_S Zinc_D Zinc_S 1.00 0.04 Zinc_D 0.04 1.00 > > out1 <- svycor(~Zinc_S + Zinc_D, design = nhc5) > out1$cors Zinc_S Zinc_D Zinc_S 1.00000000 0.04171053 Zinc_D 0.04171053 1.00000000 > v <- svyvar(~Zinc_S + Zinc_D, design = nhc5) > > as.matrix(v) Zinc_S Zinc_D Zinc_S 235.815646 3.098878 Zinc_D 3.098878 23.406959 attr(,"var") Zinc_S Zinc_S Zinc_D Zinc_D Zinc_S 94.576779 2.623090 2.623090 -1.934811 Zinc_S 2.623090 6.057128 6.057128 -1.815434 Zinc_D 2.623090 6.057128 6.057128 -1.815434 Zinc_D -1.934811 -1.815434 -1.815434 6.908094 attr(,"statistic") [1] "variance" > cov2cor(as.matrix(v)) Zinc_S Zinc_D Zinc_S 1.00000000 0.04171053 Zinc_D 0.04171053 1.00000000 attr(,"var") Zinc_S Zinc_S Zinc_D Zinc_D Zinc_S 94.576779 2.623090 2.623090 -1.934811 Zinc_S 2.623090 6.057128 6.057128 -1.815434 Zinc_D 2.623090 6.057128 6.057128 -1.815434 Zinc_D -1.934811 -1.815434 -1.815434 6.908094 attr(,"statistic") [1] "variance" > > svyplot(Zinc_S ~ Zinc_D, design=nhc5, style="bubble" ,ylab=" Serum Zinc (µg/dL)", + xlab="Dietary Zinc (mg)", main="Figure 3:Relationship between Serum & Dietary Zn (13-35-Year-Olds)") > > smoother <- svysmooth(Zinc_S ~ Zinc_D, + design=nhc5, bandwidth=10) > lines(smoother, col="blue", lwd=4) > > #### 66+ > ####### Upload data from Excel########################################################################################################################### > nhanes5 <- D_S_Data %>% mutate_if(is.character,as.factor) > class(nhanes5) [1] "tbl_df" "tbl" "data.frame" > print(nhanes5) # A tibble: 285 x 9 SEQN Gender Age SDMVPSU SDMVSTRA WTSA2YR Zinc_S Zinc_D Fasting 1 83734 1 78 1 131 38741. 98.7 15.4 10 2 83737 2 72 1 128 62801. 88.9 5.67 12 3 83755 1 67 1 126 340775. 91.3 10.5 13 4 83758 1 80 2 133 27993. 79.7 14.2 4 5 83773 2 80 1 131 23769. 94.4 5.72 2 6 83775 2 69 2 119 36344. 89.4 11.2 10 7 83787 2 68 1 128 108273. 57.4 18.7 1 8 83788 2 69 2 120 104229. 68.9 4.43 15 9 83789 1 66 1 132 57369. 72.8 4.98 0 10 83812 2 68 1 124 346820. 91.8 13.2 0 # ... with 275 more rows > > ######### Summary of Data################ > summary(nhanes5) SEQN Gender Age SDMVPSU SDMVSTRA WTSA2YR Min. :83734 Min. :1.000 Min. :66.00 Min. :1.000 Min. :119.0 Min. : 22693 1st Qu.:84471 1st Qu.:1.000 1st Qu.:69.00 1st Qu.:1.000 1st Qu.:123.0 1st Qu.: 47959 Median :85262 Median :2.000 Median :74.00 Median :2.000 Median :127.0 Median : 68757 Mean :85144 Mean :1.519 Mean :73.64 Mean :1.502 Mean :126.4 Mean :116780 3rd Qu.:85792 3rd Qu.:2.000 3rd Qu.:80.00 3rd Qu.:2.000 3rd Qu.:130.0 3rd Qu.:120987 Max. :86420 Max. :2.000 Max. :80.00 Max. :2.000 Max. :133.0 Max. :657426 Zinc_S Zinc_D Fasting Min. : 45.80 Min. : 0.880 Min. : 0.000 1st Qu.: 69.20 1st Qu.: 6.080 1st Qu.: 1.000 Median : 79.20 Median : 8.640 Median : 4.000 Mean : 79.05 Mean : 9.537 Mean : 5.754 3rd Qu.: 89.10 3rd Qu.:12.145 3rd Qu.:11.000 Max. :120.70 Max. :30.220 Max. :17.000 > > ###########Structure of the Data############ > str(nhanes5) tibble [285 x 9] (S3: tbl_df/tbl/data.frame) $ SEQN : num [1:285] 83734 83737 83755 83758 83773 ... $ Gender : num [1:285] 1 2 1 1 2 2 2 2 1 2 ... $ Age : num [1:285] 78 72 67 80 80 69 68 69 66 68 ... $ SDMVPSU : num [1:285] 1 1 1 2 1 2 1 2 1 1 ... $ SDMVSTRA: num [1:285] 131 128 126 133 131 119 128 120 132 124 ... $ WTSA2YR : num [1:285] 38741 62801 340775 27993 23769 ... $ Zinc_S : num [1:285] 98.7 88.9 91.3 79.7 94.4 89.4 57.4 68.9 72.8 91.8 ... $ Zinc_D : num [1:285] 15.37 5.67 10.52 14.18 5.71 ... $ Fasting : num [1:285] 10 12 13 4 2 10 1 15 0 0 ... > > ######## Head of structure################ > head(nhanes5) # A tibble: 6 x 9 SEQN Gender Age SDMVPSU SDMVSTRA WTSA2YR Zinc_S Zinc_D Fasting 1 83734 1 78 1 131 38741. 98.7 15.4 10 2 83737 2 72 1 128 62801. 88.9 5.67 12 3 83755 1 67 1 126 340775. 91.3 10.5 13 4 83758 1 80 2 133 27993. 79.7 14.2 4 5 83773 2 80 1 131 23769. 94.4 5.72 2 6 83775 2 69 2 119 36344. 89.4 11.2 10 > > ############Tail of structure############ > tail(nhanes5) # A tibble: 6 x 9 SEQN Gender Age SDMVPSU SDMVSTRA WTSA2YR Zinc_S Zinc_D Fasting 1 86365 1 68 1 121 275449. 56.7 7.90 14 2 86377 2 76 2 120 39650. 80.7 10.0 14 3 86383 2 78 1 133 96171. 100 16.1 0 4 86386 1 72 1 124 63286. 89.1 3.62 1 5 86406 1 80 1 119 85123. 86.5 9.85 1 6 86420 1 80 1 130 104832. 83 3.66 12 > > ######Determine Column Names############### > > colnames(nhanes5) [1] "SEQN" "Gender" "Age" "SDMVPSU" "SDMVSTRA" "WTSA2YR" "Zinc_S" "Zinc_D" "Fasting" > > ########################## Create Survey Weight Equation ############################################################################################################## > library("survey") > > nhc5 <- svydesign(id=~SDMVPSU, weights=~WTSA2YR, strata=~SDMVSTRA, nest=TRUE, survey.lonely.psu = "adjust", data= nhanes5) > summary(nhc5) Stratified 1 - level Cluster Sampling design (with replacement) With (30) clusters. svydesign(id = ~SDMVPSU, weights = ~WTSA2YR, strata = ~SDMVSTRA, nest = TRUE, survey.lonely.psu = "adjust", data = nhanes5) Probabilities: Min. 1st Qu. Median Mean 3rd Qu. Max. 1.521e-06 8.265e-06 1.454e-05 1.591e-05 2.085e-05 4.407e-05 Stratum Sizes: 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 obs 17 11 18 12 17 15 30 19 28 25 13 20 19 26 15 design.PSU 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 actual.PSU 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 Data variables: [1] "SEQN" "Gender" "Age" "SDMVPSU" "SDMVSTRA" "WTSA2YR" "Zinc_S" "Zinc_D" "Fasting" > str(nhc5) List of 9 $ cluster :'data.frame': 285 obs. of 1 variable: ..$ SDMVPSU: Factor w/ 30 levels "119.1","119.2",..: 25 19 15 30 25 2 19 4 27 11 ... ..- attr(*, "terms")=Classes 'terms', 'formula' language ~SDMVPSU .. .. ..- attr(*, "variables")= language list(SDMVPSU) .. .. ..- attr(*, "factors")= int [1, 1] 1 .. .. .. ..- attr(*, "dimnames")=List of 2 .. .. .. .. ..$ : chr "SDMVPSU" .. .. .. .. ..$ : chr "SDMVPSU" .. .. ..- attr(*, "term.labels")= chr "SDMVPSU" .. .. ..- attr(*, "order")= int 1 .. .. ..- attr(*, "intercept")= int 1 .. .. ..- attr(*, "response")= int 0 .. .. ..- attr(*, ".Environment")= .. .. ..- attr(*, "predvars")= language list(SDMVPSU) .. .. ..- attr(*, "dataClasses")= Named chr "numeric" .. .. .. ..- attr(*, "names")= chr "SDMVPSU" $ strata :'data.frame': 285 obs. of 1 variable: ..$ SDMVSTRA: num [1:285] 131 128 126 133 131 119 128 120 132 124 ... ..- attr(*, "terms")=Classes 'terms', 'formula' language ~SDMVSTRA .. .. ..- attr(*, "variables")= language list(SDMVSTRA) .. .. ..- attr(*, "factors")= int [1, 1] 1 .. .. .. ..- attr(*, "dimnames")=List of 2 .. .. .. .. ..$ : chr "SDMVSTRA" .. .. .. .. ..$ : chr "SDMVSTRA" .. .. ..- attr(*, "term.labels")= chr "SDMVSTRA" .. .. ..- attr(*, "order")= int 1 .. .. ..- attr(*, "intercept")= int 1 .. .. ..- attr(*, "response")= int 0 .. .. ..- attr(*, ".Environment")= .. .. ..- attr(*, "predvars")= language list(SDMVSTRA) .. .. ..- attr(*, "dataClasses")= Named chr "numeric" .. .. .. ..- attr(*, "names")= chr "SDMVSTRA" $ has.strata: logi TRUE $ prob : Named num [1:285] 2.58e-05 1.59e-05 2.93e-06 3.57e-05 4.21e-05 ... ..- attr(*, "names")= chr [1:285] "1" "2" "3" "4" ... $ allprob :'data.frame': 285 obs. of 1 variable: ..$ WTSA2YR: num [1:285] 2.58e-05 1.59e-05 2.93e-06 3.57e-05 4.21e-05 ... $ call : language svydesign(id = ~SDMVPSU, weights = ~WTSA2YR, strata = ~SDMVSTRA, nest = TRUE, survey.lonely.psu = "adjust", data = nhanes5) $ variables :'data.frame': 285 obs. of 9 variables: ..$ SEQN : num [1:285] 83734 83737 83755 83758 83773 ... ..$ Gender : num [1:285] 1 2 1 1 2 2 2 2 1 2 ... ..$ Age : num [1:285] 78 72 67 80 80 69 68 69 66 68 ... ..$ SDMVPSU : num [1:285] 1 1 1 2 1 2 1 2 1 1 ... ..$ SDMVSTRA: num [1:285] 131 128 126 133 131 119 128 120 132 124 ... ..$ WTSA2YR : num [1:285] 38741 62801 340775 27993 23769 ... ..$ Zinc_S : num [1:285] 98.7 88.9 91.3 79.7 94.4 89.4 57.4 68.9 72.8 91.8 ... ..$ Zinc_D : num [1:285] 15.37 5.67 10.52 14.18 5.71 ... ..$ Fasting : num [1:285] 10 12 13 4 2 10 1 15 0 0 ... $ fpc :List of 2 ..$ popsize : NULL ..$ sampsize: int [1:285, 1] 2 2 2 2 2 2 2 2 2 2 ... ..- attr(*, "class")= chr "survey_fpc" $ pps : logi FALSE - attr(*, "class")= chr [1:2] "survey.design2" "survey.design" > ############# > > svycor(~ Zinc_S + Zinc_D, design = nhc5) Zinc_S Zinc_D Zinc_S 1.00 0.04 Zinc_D 0.04 1.00 > > out2 <- svycor(~Zinc_S + Zinc_D, design = nhc5) > out2$cors Zinc_S Zinc_D Zinc_S 1.00000000 0.03504753 Zinc_D 0.03504753 1.00000000 > > > > svyplot(Zinc_S ~ Zinc_D, design=nhc5, style="bubble" ,ylab=" Serum Zinc (µg/dL)", + xlab="Dietary Zinc (mg)", main="Figure 3:Relationship between Serum & Dietary Zn (66+)") > > smoother <- svysmooth(Zinc_S ~ Zinc_D, + design=nhc5, bandwidth=10) > lines(smoother, col="blue", lwd=4)