[rsplus] 1)
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- datamain_set <- read.csv('CTNS2021ectn_p.csv')
- install.packages("magrittr") # package installations are only needed the first time you use it
- install.packages("dplyr") # alternative installation of the %>%
- install.packages("tidyverse")
- library(magrittr) # needs to be run every time you start R and want to use %>%
- library(dplyr)
- library(tidyverse)
- datamain_set
- #TBC_05BR Age First time smoked whole cigarette : How old were you when you first smoked whole cigarette (= 3 or 96)
- #VAP_05BR Tried vaping liftime: How old were you when you first tied vaping (<=2)
- #VAP_60 Perception harm to persons health (Vaping vs Cigarretes)
- datamain <- datamain_set %>%
- select(PUMFID,TBC_40R,
- TBC_05BR,
- VAP_05BR,
- VAP_60,
- AGEGROUP,GENDER)
- datamain <- datamain %>%
- filter(GENDER== c(1,2))
- datamain$GENDER <-factor(datamain$GENDER,
- levels = c(1,2),
- labels = c("Male","Female"))
- #-----Ciggarettes---------
- tab_c1 <- datamain %>%
- filter(AGEGROUP ==3,
- TBC_05BR == c(03,96)) #= 0 - 3; 0 - 19 year old, 96 - Valid Skip.
- tab_c1 <- select(tab_c1,AGEGROUP,TBC_05BR,GENDER)
- tab_c1<- tab_c1 %>%
- mutate(smoke = ifelse(TBC_05BR == 3, 1,0))
- tab_c1$AGEGROUP <-factor(tab_c1$AGEGROUP,
- levels = c(3),
- labels = c("15 to 19 years old"))
- tab_c1$TBC_05BR <-factor(tab_c1$TBC_05BR,
- levels = c(3,96),
- labels = c("Yes","No"))
- #Data filling for tables
- xc <- tibble(filter(tab_c1, GENDER == "Female")) #smoke - Male
- xc <- xc %>%
- select(GENDER,smoke)
- round(sd(xc$smoke),2)
- round(mean(xc$smoke),2)
- nrow(xc)
- yc <- tibble(filter(tab_c1, GENDER == "Male")) #smoke - Male
- yc <- yc %>%
- select(GENDER,smoke)
- round(sd(yc$smoke),2) #sd
- round(mean(yc$smoke),2) #mean
- nrow(yc)
- round(sd(tab_c1$smoke),2)
- round(mean(tab_c1$smoke),2)
- #Final Data for Smoking
- tabc1 <- as.data.frame.matrix(table(tab_c1$AGEGROUP,tab_c1$TBC_05BR)) ## Frequency of 15 to 19 year olds Vs Tried Smoking | Convert to CSV file for easy copy pasting
- tabc1p <- as.data.frame.matrix(prop.table(table(tab_c1$AGEGROUP,tab_c1$TBC_05BR), margin=1)) ## Proportion of 15 to 19 year olds VS Tried smoking | Convert to CSV file for easy copy pasting
- tabc1g <- as.data.frame.matrix(table(tab_c1$GENDER,tab_c1$TBC_05BR)) ## Frequency of Sexes ages 15 to 19 year olds VS Tried smoking | Convert to CSV file for easy copy pasting
- tabc1pg <- as.data.frame.matrix(prop.table(table(tab_c1$GENDER,tab_c1$TBC_05BR), margin=1)) ## Propotion of Sexes ages 15 to 19 year olds VS Tried smoking| Convert to CSV file for easy copy pasting
- chisq.test(tab_c1$GENDER,tab_c1$smoke)$expected
- t<-as.data.frame.matrix(chisq.test(tab_c1$GENDER,tab_c1$smoke)$expected,1) # | Convert to CSV file for easy copy pasting
- chisq.test(tab_c1$smoke,tab_c1$GENDER)
- #------Vaping-------
- tab_v1 <- datamain %>%
- filter(AGEGROUP==03,VAP_05BR == c(03,96)) #= 0 - 3; 0 - 19 year old, 96 - Valid Skip.
- tab_v1 <- select(tab_v1,AGEGROUP,VAP_05BR,GENDER)
- tab_v1<- tab_v1 %>%
- mutate(vape = ifelse(VAP_05BR == 03, 1,0))
- tab_v1$AGEGROUP <-factor(tab_v1$AGEGROUP,
- levels = c(3),
- labels = c("15 to 19 years old"))
- tab_v1$VAP_05BR <-factor(tab_v1$VAP_05BR,
- levels = c(3,96),
- labels = c("Yes","No"))
- # Data filling for Tables
- x <- tibble(filter(tab_v1, GENDER == "Female")) #vape - Fema
- x <- x %>%
- select(GENDER,vape)
- round(sd(x$vape),2)
- round(mean(x$vape),2)
- y <- tibble(filter(tab_v1, GENDER == "Male")) #vape - Male
- y <- y %>%
- select(GENDER,vape)
- round(sd(y$vape),2) #sd
- round(mean(y$vape),2) #mean
- mean(tab_v1$vape)
- #Final Data for Vaping
- tabv1 <- as.data.frame.matrix(table(tab_v1$AGEGROUP,tab_v1$VAP_05BR)) ## Frequency of 15 to 19 year olds Vs Tried Vaping |Convert to CSV file for easy copy pasting
- tabv1p <- as.data.frame.matrix(prop.table(table(tab_v1$AGEGROUP,tab_v1$VAP_05BR), margin=1)) ## Frequency of 15 to 19 year olds Vs Tried Vaping | Convert to CSV file for easy copy pasting
- tabv1g <- as.data.frame.matrix(table(tab_v1$GENDER,tab_v1$VAP_05BR)) ## Frequency of Sexes ages 15 to 19 year olds VS Tried Vaping | Convert to CSV file for easy copy pasting
- tabv1pg <- as.data.frame.matrix(prop.table(table(tab_v1$GENDER,tab_v1$VAP_05BR), margin=1)) ## Proportion of Sexes ages 15 to 19 year olds VS Tried Vaping| Convert to CSV file for easy copy pasting
- t<-as.data.frame.matrix(chisq.test(tab_v1$GENDER,tab_v1$vape)$expected,1) ## Convert to CSV file for easy copy pasting
- chisq.test(tab_v1$vape,tab_v1$GENDER) #CHI SQUARE TEST
Editor
You can edit this paste and save as new: