Discussion2

.pdf
This is a preview
Want to read all 7 pages? Go Premium today.
View Full Document
Already Premium? Sign in here
STAT 111/202 Discussion 2 library(tidyverse) ## Warning: replacing previous import lifecycle::last_warnings by ## rlang::last_warnings when loading tibble ## Warning: replacing previous import ellipsis::check_dots_unnamed by ## rlang::check_dots_unnamed when loading tibble ## Warning: replacing previous import ellipsis::check_dots_used by ## rlang::check_dots_used when loading tibble ## Warning: replacing previous import ellipsis::check_dots_empty by ## rlang::check_dots_empty when loading tibble ## Warning: replacing previous import lifecycle::last_warnings by ## rlang::last_warnings when loading pillar ## Warning: replacing previous import ellipsis::check_dots_unnamed by ## rlang::check_dots_unnamed when loading pillar ## Warning: replacing previous import ellipsis::check_dots_used by ## rlang::check_dots_used when loading pillar ## Warning: replacing previous import ellipsis::check_dots_empty by ## rlang::check_dots_empty when loading pillar ## -- Attaching packages ------------------------------------------------------------------- tidyverse 1 ## v ggplot2 3.3.2 v purrr 0.3.4 ## v tibble 3.0.3 v dplyr 1.0.2 ## v tidyr 1.1.1 v stringr 1.4.0 ## v readr 1.3.1 v forcats 0.5.0 ## -- Conflicts ---------------------------------------------------------------------- tidyverse_conflic ## x dplyr::filter() masks stats::filter() ## x dplyr::lag() masks stats::lag() library(epitools) # Load function from class R file prop.comp <- function ( x, estimate= "all" , conf.level= . 95 , transpose= FALSE ){ if ( transpose ) x <- t(x) rslt <- vector( "list" , length= 3 ) names( rslt ) <- c( "riskdiff" , "riskratio" , "oddsratio" ) diff.rslt <- suppressWarnings(prop.test( x, conf.level= conf.level )) rslt[[ 1 ]] <- rslt[[ 2 ]] <- rslt[[ 3 ]] <- epitab( x, method= "riskratio" , pvalue= "chi2" , conf.level= conf.l colnames( rslt[[ 1 ]] )[ 5 ] <- "riskdiff" rslt[[ 1 ]][, 5 ] <- c( 0 ,diff(rev(diff.rslt$estimate))) rslt[[ 1 ]][ 2 , 6 : 7 ] <- diff.rslt$conf.int colnames( rslt[[ 3 ]] )[ 5 ] <- "oddsratio" rslt[[ 3 ]][, 5 : 8 ] <- suppressWarnings(epitab( x, method= "oddsratio" , pvalue= "chi2" , conf.level= conf.leve if (is.null(names(dimnames(x)))){ 1
for (i in 1 : 3 ){ colnames(rslt[[i]])[c( 1 , 3 )] <- c( "Outcome=0" , "Outcome=1" ) rownames(rslt[[i]]) <- c( "Group=1" , "Group=2" ) } } if ( is.element( estimate, c( "all" , "oddsratio" ) ) ){ if (is.null(names(dimnames(x)))){ warning( "Estimated probabilities represent Pr[ Outcome | Group ]. For estimates of Pr[ Group | Outcome ], change the value of transpose ." ) } else warning( paste( "Estimated probabilities represent Pr[" , names(dimnames(x))[ 2 ], "|" ,names(dimnames(x))[ 1 ], "]. For estimates of Pr[" , names(dimnames(x))[ 1 ], "|" ,names(dimnames(x))[ 2 ], "], change the value of tr } if ( estimate == "riskdiff" ) return(rslt[[ 1 ]]) else if ( estimate == "riskratio" ) return(rslt[[ 2 ]]) else if ( estimate == "oddsratio" ) return(rslt[[ 3 ]]) else return(rslt) } Question 1 This data comes from a randomized experiment in which servers in a restaurant (a) drew a smiley face on the bill or (b) used a normal bill. The tip value in % was recorded. # Load the data # Base R tips <- read.csv( "happyface.csv" ) # Tidyverse tips_tidy <- read_csv( "happyface.csv" ) ## Parsed with column specification: ## cols( ## Message = col_character(), ## Sex = col_character(), ## TipPct = col_double() ## ) ggplot(tips, aes( x = TipPct)) + geom_histogram() + facet_grid( rows = vars(Message)) ## stat_bin() using bins = 30 . Pick better value with binwidth . 2
HappyFace None 0 20 40 60 0 2 4 6 0 2 4 6 TipPct count ggplot(tips, aes( x = TipPct)) + geom_histogram() + facet_grid( rows = vars(Sex)) ## stat_bin() using bins = 30 . Pick better value with binwidth . 3
Why is this page out of focus?
Because this is a Premium document. Subscribe to unlock this document and more.
Page1of 7
Uploaded by ChefTapirPerson699 on coursehero.com