# 303 piracy project results getwd() setwd("C:/Users/Ben/Desktop/Spring 2012 Courses/Survey, Sampling & Society/Homework") data = read.csv("piracy_results.csv") summary(data) colnames(data)[1]<-"time" colnames(data)[2]<-"policy_support" colnames(data)[3]<-"bill_awareness" colnames(data)[4]<-"policy_changes" colnames(data)[5]<-"downloaded" colnames(data)[6]<-"streamed" colnames(data)[7]<-"download_freq" colnames(data)[8]<-"stream_freq" colnames(data)[9]<-"attitude_change" colnames(data)[10]<-"site_types" colnames(data)[11]<-"origin_awareness" colnames(data)[12]<-"download_consider" colnames(data)[13]<-"stream_consider" colnames(data)[14]<-"youtube_consider" colnames(data)[16]<-"dtella_scenario" colnames(data)[17]<-"youtube_scenario" colnames(data)[18]<-"upload_scenario" colnames(data)[19]<-"convenient_methods" colnames(data)[20]<-"comments" colnames(data)[21]<-"experiences" colnames(data)[22]<-"gender" colnames(data)[23]<-"ethnicity" colnames(data)[24]<-"class" colnames(data)[25]<-"residence" colnames(data)[26]<-"political" colnames(data)[27]<-"school" colnames(data)[28]<-"USregion" colnames(data)[29]<-"andrewid" attach(data) USregion #### RECODING VARIABLES #### barplot(table(policy_support)) par(mfrow=c(1,2)) barplot(table(youtube_consider)) barplot(table(youtube_scenario)) summary(data) head(data) colnames(data) table(school) par(mfrow=c(2,1)) barplot(table(dtella_scenario[school=="HSS"]),main="HSS",ylim=c(0,50)) barplot(table(dtella_scenario[school=="CIT"]),main="CIT",ylim=c(0,50)) par(mfrow=c(2,1)) pie(table(dtella_scenario[school=="HSS"]),main="HSS: Dtella") pie(table(dtella_scenario[school=="CIT"]),main="CIT: Dtella") pie(table(dtella_scenario[school=="HSS"]),main="HSS: Dtella") pie(table(dtella_scenario[school=="CIT"]),main="CIT: Dtella") #CIT for(i in 1:ncol(data)){ for(i in 1:nrow(data)){ if(colname[i]=="(BLANK)") apply(data,2,ifelse, data.vec = as.vector(data) length(data.vec) data.vec table(eth junk$nm[junk$nm %in% "B"] <- "b" ############################################################################################### ############################################################################################### table(class,school,ethnicity) table(class,school) table(ethnicity,school) table(class,school) table(ethnicity,class) ############################################################################################### ############################################################################################### #Class Year Weighting frosh = 1559.0;soph = 1560.8;jr = 1475.0;sr = 1371.0;fifthyr = 148.7;ug = 6114.5 sum(frosh,soph,jr,sr,fifthyr) by.year = c(frosh/ug,soph/ug,jr/ug,sr/ug,fifthyr/ug);by.year which(gender=="(BLANK)") which(gender=="") "time" "policy_support" "bill_awareness" [4] "policy_changes" "downloaded" "streamed" [7] "download_freq" "stream_freq" "attitude_change" [10] "site_types" "origin_awareness" "download_consider" [13] "stream_consider" "youtube_consider" "Attitudes..." [16] "dtella_scenario" "youtube_scenario" "upload_scenario" [19] "convenient_methods" "comments" "experiences" [22] "gender" "ethnicity" "class" [25] "residence" "political" "school" [28] "USregion" "andrewid" table(policy_support) as.numeric(policy_support) pc = as.numeric(policy_support) table(ethnicity) data = cbind(data,pc) mean(pc[ethnicity=="African-American"]) mean(pc[ethnicity=="Asian/Pacific Islander"]) mean(pc[ethnicity=="Hispanic/Lation"]) mean(pc[ethnicity=="Caucasian"]) which(policy_support=="") which(bill_awareness=="") which(download_freq=="") which(stream_freq=="") which(attitude_change=="") which(stream_consider=="") which(youtube_consider=="") which(Attitudes...===="") which(dtella_scenario=="") which(youtube_scenario=="") which(upload_scenario=="") which(convenient_methods=="") which(comments=="") which(experiences=="") which(gender=="") which(ethnicity=="") which(class=="") which(residence=="") which(political=="") which(school=="") which(USregion=="") which(andrewid=="") length(which(stream_freq==""))/240 length(which(comments==""))/240 length(which(experiences==""))/240 table(class) 5th-year senior Freshman Junior Senior Sophomore 2 6 66 47 64 55 tot1 = 2+6+66+47+64+55 s.nr = 2; s.fifth = 6; s.frosh = 66; s.jr=47;s.sr=64;s.soph=55 sum(s.nr, s.fifth, s.frosh = 66, s.jr=47, s.sr=64, s.soph=55) 2+6+66+47+64+55 sam = 238 sam.by.year = c(s.frosh/sam,s.soph/sam,s.jr/sam,s.sr/sam,s.fifth/sam);sam.by.year ############################################################################################### ############################################################################################### ##Ethnicity Weighting #13, 12 which(ethnicity=="African") which(ethnicity=="African American") which(ethnicity=="White/Caucasian, Native American") #Student Population: #13% African-American, Hispanic/Latino-American, and Native American #20% Asian-American #14% international t1 = table(ethnicity) pct = round(t1/sum(t1)*100); pct; sum(pct) table(ethnicity)round(typess/sum(typess)*100);pct; sum(pct) eth.pct = t1/sum(t1)*100 eth.pct which(ethnicity=="White/Caucasian, African American, Hispanic/Latino, Asian/Pacific Islander, Native American" ) ############################################################################################### ############################################################################################### ##Male Female Weighting #Male Undergrads: 3,533, #Female Undergrads: 2,560 ugpop = sum(3533,2560); males=3533; females=2560 malepct = males/ugpop; femalepct = females/ugpop;malepct;femalepct table(gender) sample = 104+136 104/sample; 136/sample; 101/sample; 136/sample; 101/(sample-3); 136/(sample-3) ### tot = 6178 fem = 2596 fem/tot ############################################################################################### ############################################################################################### ##School Weighting cfa = 979; cit = 1756; dc = 1175; mcs = 726; scs = 582; tsb = 359; school.tot = 6178 - 266 table(school) pop.school = c(cfa/school.tot, cit/school.tot, dc/school.tot, mcs/school.tot, scs/school.tot, tsb/school.tot); signif(pop.school*100,3) t2=table(school) school.pct = signif(t2/sum(t2)*100,3);school.pct ############################################################################################### ############################################################################################### barplot(table(upload_scenario_acceptable,youtube_scenario_acceptable), beside=TRUE) barplot(table(upload_scenario_acceptable)) barplot(table(youtube_scenario_acceptable)) table(upload_scenario_acceptable,youtube_scenario_acceptable) par(mfrow=c(1,3)) pie(table(dtella_scenario_acceptable),main="Dtella Scenario") pie(table(youtube_scenario_acceptable),main="Youtube Scenario") pie(table(upload_scenario_acceptable),main="Upload Scenario") par(mfrow=c(1,2)) pie(table(youtube_scenario_acceptable[youtube_acceptable==1]),main="Generally Acceptable") pie(table(youtube_scenario_acceptable[youtube_acceptable==0]),main="Not Generally Acceptable") colnames(data) #### RECODING VARIABLES #### # fixing the vars that include "Acceptable", "Illegal" etc. splitAttitudes<-function(attitude){ acceptable<-rep(0,length(attitude)) illegal<-rep(0,length(attitude)) unethical<-rep(0,length(attitude)) no.opin<-rep(0,length(attitude)) for(i in 1:length(attitude)){ things<-strsplit(as.character(attitude[i]),split=", ")[[1]] if(length(which(things=="Acceptable"))!=0){acceptable[i]=1} if(length(which(things=="Unethical"))!=0){unethical[i]=1} if(length(which(things=="Illegal"))!=0){illegal[i]=1} if(length(which(things=="No opinion on the ethics or legality of this action"))!=0){no.opin[i]=1} } return(list("Acceptable"=acceptable,"Unethical"=unethical,"Illegal"=illegal,"Noopinion"=no.opin)) } download_acceptable<-splitAttitudes(download_consider)[[1]] download_unethical<-splitAttitudes(download_consider)[[2]] download_illegal<-splitAttitudes(download_consider)[[3]] download_noopin<-splitAttitudes(download_consider)[[4]] stream_acceptable<-splitAttitudes(stream_consider)[[1]] stream_unethical<-splitAttitudes(stream_consider)[[2]] stream_illegal<-splitAttitudes(stream_consider)[[3]] stream_noopin<-splitAttitudes(stream_consider)[[4]] youtube_acceptable<-splitAttitudes(youtube_consider)[[1]] youtube_unethical<-splitAttitudes(youtube_consider)[[2]] youtube_illegal<-splitAttitudes(youtube_consider)[[3]] youtube_noopin<-splitAttitudes(youtube_consider)[[4]] ###################################### #"dtella_scenario" "youtube_scenario" "upload_scenario" dtella_scenario_acceptable<-splitAttitudes(dtella_scenario)[[1]] dtella_scenario_unethical<-splitAttitudes(dtella_scenario)[[2]] dtella_scenario_illegal<-splitAttitudes(dtella_scenario)[[3]] dtella_scenario_noopin<-splitAttitudes(dtella_scenario)[[4]] youtube_scenario_acceptable<-splitAttitudes(youtube_scenario)[[1]] youtube_scenario_unethical<-splitAttitudes(youtube_scenario)[[2]] youtube_scenario_illegal<-splitAttitudes(youtube_scenario)[[2]] youtube_scenario_noopin<-splitAttitudes(youtube_scenario)[[4]] upload_scenario_acceptable<-splitAttitudes(upload_scenario)[[1]] upload_scenario_unethical<-splitAttitudes(upload_scenario)[[2]] upload_scenario_illegal<-splitAttitudes(upload_scenario)[[3]] upload_scenario_noopin<-splitAttitudes(upload_scenario)[[4]] ########### data = cbind(data,download_acceptable,download_unethical,download_illegal,download_noopin, stream_acceptable,stream_unethical,stream_illegal,stream_noopin,youtube_acceptable, youtube_unethical,youtube_illegal,youtube_noopin) ########### data = cbind(data,dtella_scenario_acceptable,dtella_scenario_unethical, dtella_scenario_illegal,dtella_scenario_noopin,youtube_scenario_acceptable, youtube_scenario_unethical,youtube_scenario_illegal,youtube_scenario_noopin, upload_scenario_acceptable,upload_scenario_unethical,upload_scenario_illegal, upload_scenario_noopin) colnames(data) ########## head(data) table(attitude_change) table(attitude_change)/sum(table(attitude_change)) sum(table(attitude_change)/sum(table(attitude_change))) signif(table(attitude_change)/sum(table(attitude_change)),2) sum(signif(table(attitude_change)/sum(table(attitude_change)),2)) colnames(data) library(MASS) mosaic(table(bill_awareness,streamed), T) table(dtella_scenario_illegal) table(download_scenario_illegal) comments[attitude_change=="A lot"] #4/12 commented table(comments) length(comments[attitude_change=="Not at all"])####72/105 comments[attitude_change=="Somewhat"] comments[attitude_change=="Unsure"] #####72 comments 72-3;240-12 69/228 levels(comments) ##67 real responses 66/240 73/240 levels( colnames(data) levels(experiences) levels(comments)[1:28] levels(experience) table(comments) table(comments) 43-12#31 43/240 31/240 ################################################################ ################################################################ ################################################################ ################################################################ full.weights<-rep(0,238) for(i in 1:length(stream.data[,1])){ if(stream.data[,1][i]==3){full.weights[i]=weights[1]} if(stream.data[,1][i]==6){full.weights[i]=weights[2]} if(stream.data[,1][i]==4){full.weights[i]=weights[3]} if(stream.data[,1][i]==5){full.weights[i]=weights[4]} if(stream.data[,1][i]==2){full.weights[i]=weights[5]} } mean.stream<-sum(full.weights*stream.data[,2])/sum(full.weights) ########## jackknife: frosh = 1559.0;soph = 1560.8;jr = 1475.0;sr = 1371.0;fifthyr = 148.7;ug = 6114.5 by.year = c(frosh/ug,soph/ug,jr/ug,sr/ug,fifthyr/ug) jackknife<-function(studs){ y.w.r<-rep(0,length(studs[,1])) for(i in 1:length(studs[,1])){ #recalculate weights temps.samp.prop<-rep(0,5) temps.samp.prop[1]<-length(which(studs[-i,1]==3))/length(studs[-i,1]) temps.samp.prop[2]<-length(which(studs[-i,1]==6))/length(studs[-i,1]) temps.samp.prop[3]<-length(which(studs[-i,1]==4))/length(studs[-i,1]) temps.samp.prop[4]<-length(which(studs[-i,1]==5))/length(studs[-i,1]) temps.samp.prop[5]<-length(which(studs[-i,1]==2))/length(studs[-i,1]) cur.weights<-by.year/temps.samp.prop full.weights<-rep(0,length(studs[-i,1])) for(j in 1:length(studs[-i,1])){ if(studs[-i,1][j]==3){full.weights[j]=cur.weights[1]} if(studs[-i,1][j]==6){full.weights[j]=cur.weights[2]} if(studs[-i,1][j]==4){full.weights[j]=cur.weights[3]} if(studs[-i,1][j]==5){full.weights[j]=cur.weights[4]} if(studs[-i,1][j]==2){full.weights[j]=cur.weights[5]} } y.w.r[i]<-sum(full.weights*studs[-i,2])/sum(full.weights) } y.bar.jk<-mean(y.w.r) var.jk<-((length(studs[,1])-1)/length(studs[,1]))*sum((y.w.r-y.bar.jk)^2) return(list("jackknife mean"=y.bar.jk,"jackknife variance"=var.jk)) } jk.mean+-sqrt(fpc*jk var) fpc=240/6114.5 ###################################################################################### ###################################################################################### ###################################################################################### length(bill_awareness.data) full.weights<-rep(0,238) for(i in 1:length(bill_awareness.data[,1])){ if(bill_awareness.data[,1][i]==3){full.weights[i]=weights[1]} if(bill_awareness.data[,1][i]==6){full.weights[i]=weights[2]} if(bill_awareness.data[,1][i]==4){full.weights[i]=weights[3]} if(bill_awareness.data[,1][i]==5){full.weights[i]=weights[4]} if(bill_awareness.data[,1][i]==2){full.weights[i]=weights[5]} } mean.bill_awareness<-sum(full.weights*bill_awareness.data[,2])/sum(full.weights) mean.bill_awareness#.9292048 jackknife(bill_awareness.data) ##jackknife mean = .9292048 ##jk variance = .0002883918 #CIs: #jk.mean+-sqrt(fpc*jk var) fpc=240/6114.5 .9292048+sqrt(fpc*.0002883918) .9292048-sqrt(fpc*.0002883918) #CI = (.9258403,.9325693) ###################################### table(policy_support) table(policy_support)/sum(table(policy_support)) 38+44 length(policy_support.data) #####Already exists length(policy.data) full.weights<-rep(0,240) for(i in 1:length(policy.data[,1])){ if(policy.data[,1][i]==3){full.weights[i]=weights[1]} if(policy.data[,1][i]==6){full.weights[i]=weights[2]} if(policy.data[,1][i]==4){full.weights[i]=weights[3]} if(policy.data[,1][i]==5){full.weights[i]=weights[4]} if(policy.data[,1][i]==2){full.weights[i]=weights[5]} } mean.policy.data<-sum(full.weights*policy.data[,2])/sum(full.weights) mean.policy.data# .8207955 jackknife(policy.data) ##jackknife mean = 1.807895 ##jk variance = .003594684 #CIs: #jk.mean+-sqrt(fpc*jk var) fpc=240/6114.5 .8207955+sqrt(fpc*.0006514916) .8207955-sqrt(fpc*.0006514916) #CI = (.8157387,.8258523) ############################################# table(policy_support) table(policy_support)/sum(table(policy_support)) 38+44 length(policy_changes.data) full.weights<-rep(0,238) for(i in 1:length(policy_changes.data[,1])){ if(policy_support.data[,1][i]==3){full.weights[i]=weights[1]} if(policy_changes.data[,1][i]==6){full.weights[i]=weights[2]} if(policy_changes.data[,1][i]==4){full.weights[i]=weights[3]} if(policy_changes.data[,1][i]==5){full.weights[i]=weights[4]} if(policy_changes.data[,1][i]==2){full.weights[i]=weights[5]} } mean.policy_changes<-sum(full.weights*policy_changes.data[,2])/sum(full.weights) mean.policy_changes#.6737738 jackknife(policy_changes.data) ##jackknife mean = .6737738 ##jk variance = .0009452676 #CIs: #jk.mean+-sqrt(fpc*jk var) fpc=240/6114.5 .6737738+sqrt(fpc*.0009452676) .6737738-sqrt(fpc*.0009452676) #CI = (.6676826,.679865) ######################################################################### ######################################################################### ######################################################################### ######################################################################### ######################################################################### ######################################################################### colnames(data) table(download_acceptable) table(USregion) library(MASS) ?sunflowerplot sunflowerplot(dtella_scenario,upload_scenario, main="Upload Scenario vs. Dtella Scenario",xlab="Dtella Scenario", ylab="Upload Scenario") xaxt( table(upload_scenario) table(dtella_scenario) ######################################################################### ######################################################################### ######################################################################### jk.variance <- function(y,sti,P.Tot) { # # given # * individual observations y # * stratum identifiers sti # * stratum population totals P.Tot # # compute # # * weighted ybar # * jackknifed ybar # * jackknifed variance # # Nb., the "sti" can be any unique set of stratum indicators # (1 = stratum 1, 2 = stratum 2, etc.), and should be of # the same length as y. The "P.Tot" should be a vector of # population totals, one for each stratum. H <- length(unique(sti)) if (length(P.Tot)!=H) { stop("Need 'P.Tot' to contain the population sizes of the strata.") } P.Prop <- P.Tot/sum(P.Tot) n <- length(y) if (length(sti)!=n) { stop("Need 'sti' to contain stratum indicators for each y.") } weights <- function(sti,P.Prop) { S.Tot <- table(sti) S.Prop <- S.Tot/length(sti) S.Wgts <- P.Prop[order(unique(sti))]/S.Prop w <- rep(0,length(sti)) for (h in 1:length(S.Wgts)) { stn <- names(S.Wgts)[h] w[sti==stn] <- S.Wgts[stn] } return(w) } w <- weights(sti,P.Prop) ybar.weighted <- sum(y*w)/sum(w) ybar.r <- NULL for (r in 1:n) { y.r <- y[-r] sti.r <- sti[-r] w.r <- weights(sti.r,P.Prop) ybar.r <- c(ybar.r,sum(w.r*y.r)/sum(w.r)) } ybar.reps <- mean(ybar.r) s2.reps <- var(ybar.r) jkvar <- (n-1)/n * (n-1) * s2.reps return(list(ybar.weighted=ybar.weighted,ybar.reps=ybar.reps, var.jk=jkvar)) } ######################################################################### ######################################################################### ######################################################################### new.streamed<-as.numeric(streamed[-which(streamed=="")])-2 new.streamed<-as.numeric(streamed)-2 num.class<-rep(0,length(class)) num.class<-ifelse(class=="Freshman",1,num.class) num.class<-ifelse(class=="Sophomore",2,num.class) num.class<-ifelse(class=="Junior",3,num.class) num.class<-ifelse(class=="Senior",4,num.class) num.class<-ifelse(class=="5th-year senior",5,num.class) stream.d<-cbind(num.class,new.streamed) stream.d<-stream.d[-which(streamed==""),] stream.d<-stream.d[-which(stream.d[,1]==0),] frosh = 1559.0;soph = 1560.8;jr = 1475.0;sr = 1371.0;fifthyr = 148.7;ug = 6114.5 p.tot<-c(frosh,soph,jr,sr,fifthyr) jk.variance(stream.d[,2],stream.d[,1],p.tot) ######################################################################### ######################################################################### ######################################################################### colnames(data) table(downloaded) new.downloaded<-as.numeric(downloaded[-which(downloaded=="")])-2 new.downloaded<-as.numeric(downloaded)-2 download.d<-cbind(num.class,new.downloaded) download.d<-download.d[-which(downloaded==""),] download.d<-download.d[-which(download.d[,1]==0),] jk.variance(download.d[,2],download.d[,1],p.tot) #.740427 = mean, .002874212 = variance new.downloaded<-as.numeric(downloaded[-which(downloaded=="")])-2 new.downloaded<-as.numeric(downloaded)-2 var(downloaded) #################################################################### #################################################################### table(origin_awareness) new.awareness<-as.numeric(origin_awareness[-which(origin_awareness=="")])-2 new.awareness<-as.numeric(origin_awareness)-2 colnames(data) awareness.d<-cbind(num.class,new.awareness) awareness.d<-awareness.d[-which(origin_awareness==""),] awareness.d<-awareness.d[-which(awareness.d[,1]==0),] jk.variance(awareness.d[,2],awareness.d[,1],p.tot) #.72748 = mean, (.27252) .001356648 = variance #################################################################### #################################################################### table(streamed) new.stream<-as.numeric(streamed[-which(streamed=="")])-2 new.stream<-as.numeric(streamed)-2 streamed.d<-cbind(num.class,new.stream) streamed.d<-streamed.d[-which(streamed==""),] streamed.d<-streamed.d[-which(streamed.d[,1]==0),] jk.variance(streamed.d[,2],streamed.d[,1],p.tot) #.72748 = mean, (.27252) .001356648 = variance mean(new.stream) colnames(data) table(downloaded) table(streamed) par(mfrow=c(2,3)) pie(table(download_unethical[downloaded=="No"])) pie(table(download_illegal[downloaded=="No"])) pie(table(download_noopin[downloaded=="No"])) pie(table(download_unethical[downloaded=="Yes"])) pie(table(download_illegal[downloaded=="Yes"])) pie(table(youtube_noopin[downloaded=="Yes"])) table(download_acceptable[downloaded=="No"])/sum(table(download_acceptable[downloaded=="No"])) table(download_unethical[downloaded=="No"])/sum(table(download_unethical[downloaded=="No"])) table(download_illegal[downloaded=="No"])/sum(table(download_illegal[downloaded=="No"])) table(download_noopin[downloaded=="No"])/sum(table(download_noopin[downloaded=="No"])) table(download_acceptable[downloaded=="Yes"])/sum(table(download_acceptable[downloaded=="Yes"])) table(download_unethical[downloaded=="Yes"])/sum(table(download_unethical[downloaded=="Yes"])) table(download_illegal[downloaded=="Yes"])/sum(table(download_illegal[downloaded=="Yes"])) table(download_noopin[downloaded=="Yes"])/sum(table(download_noopin[downloaded=="Yes"])) ############################################################## ############################################################## ##################################################################################### ##################################################################################### dev.off() par(mfrow=c(2,4),mar=c(0,0,0,.008)) pie(table(download_acceptable[downloaded=="No"]), labels=c("No 83%","Yes 17%"),col=c("lightgreen",4)) mtext("Downloading Acceptable", side = 3, line = -4, outer = FALSE) pie(table(download_unethical[downloaded=="No"]), labels=c("No 49%","Yes 51%"),col=c("lightgreen",4)) mtext(" Download Pirated Content: No \n\n Downloading Unethical", side = 3, line = -4, outer = FALSE) pie(table(download_illegal[downloaded=="No"]), labels=c("No 51%", "Yes 49%"),col=c("lightgreen",4)) mtext("Downloading Illegal", side = 3, line = -4, outer = FALSE) pie(table(download_noopin[downloaded=="No"]) , labels=c("No 77%", "Yes 23%"),col=c("lightgreen",4)) mtext("No Opinion", side = 3, line = -4, outer = FALSE) pie(table(download_acceptable[downloaded=="Yes"]), labels=c("No 38%","Yes 62%"),col=c("lightgreen",4)) mtext("Downloading Acceptable", side = 3, line = -4, outer = FALSE) pie(table(download_unethical[downloaded=="Yes"]), labels=c("No 72%", "Yes 28%"),col=c("lightgreen",4)) mtext(" Download Pirated Content: Yes \n\n Downloading Unethical", side = 3, line = -4, outer = FALSE) pie(table(download_illegal[downloaded=="Yes"]), labels=c("No 54%", "Yes 46%"),col=c("lightgreen",4)) mtext("Downloading Illegal", side = 3, line = -4, outer = FALSE) mtext("Opinions on Downloading Content \n by User's Downloading Behavior",side=1, line= -1, outer=TRUE) pie(table(download_noopin[downloaded=="Yes"]), labels=c("No 86%", "Yes 14%"),col=c("lightgreen",4)) mtext("No Opinion", side = 3, line = -4, outer = FALSE) ##################################################################################### ##################################################################################### table(stream_acceptable[streamed=="No"])/sum(table(stream_acceptable[streamed=="No"])) table(stream_unethical[streamed=="No"])/sum(table(stream_unethical[streamed=="No"])) table(stream_illegal[streamed=="No"])/sum(table(stream_illegal[streamed=="No"])) table(stream_noopin[streamed=="No"])/sum(table(stream_noopin[streamed=="No"])) table(stream_acceptable[streamed=="Yes"])/sum(table(stream_acceptable[streamed=="Yes"])) table(stream_unethical[streamed=="Yes"])/sum(table(stream_unethical[streamed=="Yes"])) table(stream_illegal[streamed=="Yes"])/sum(table(stream_illegal[streamed=="Yes"])) table(stream_noopin[streamed=="Yes"])/sum(table(stream_noopin[streamed=="Yes"])) dev.off() par(mfrow=c(2,4),mar=c(0,0,0,.008)) pie(table(stream_acceptable[streamed=="No"]), labels=c("No 50%","Yes 50%"),col=c("lightgreen",4)) mtext("Streaming Acceptable", side = 3, line = -4, outer = FALSE) pie(table(stream_unethical[streamed=="No"]), labels=c("No 73%","Yes 27%"),col=c("lightgreen",4)) mtext(" Streamed Pirated Content: No \n\n Downloading Unethical", side = 3, line = -4, outer = FALSE) pie(table(stream_illegal[streamed=="No"]), labels=c("No 69%", "Yes 31%"),col=c("lightgreen",4)) mtext("Streaming Illegal", side = 3, line = -4, outer = FALSE) pie(table(stream_noopin[streamed=="No"]) , labels=c("No 79%", "Yes 21%"),col=c("lightgreen",4)) mtext("No Opinion", side = 3, line = -4, outer = FALSE) pie(table(stream_acceptable[streamed=="Yes"]), labels=c("No 24%","Yes 76%"),col=c("lightgreen",4)) mtext("Streaming Acceptable", side = 3, line = -4, outer = FALSE) pie(table(stream_unethical[streamed=="Yes"]), labels=c("No 82%", "Yes 18%"),col=c("lightgreen",4)) mtext(" Streamed Pirated Content: Yes \n\n Downloading Unethical", side = 3, line = -4, outer = FALSE) pie(table(stream_illegal[streamed=="Yes"]), labels=c("No 74%", "Yes 26%"),col=c("lightgreen",4)) mtext("Streaming Illegal", side = 3, line = -4, outer = FALSE) mtext("Opinions on Streaming Content \n by User's Streaming Behavior",side=1, line= -1, outer=TRUE) pie(table(stream_noopin[streamed=="Yes"]), labels=c("No 87%", "Yes 13%"),col=c("lightgreen",4)) mtext("No Opinion", side = 3, line = -4, outer = FALSE) ##################################################################################### ##################################################################################### ##################################################################################### ##################################################################################### colnames(data) table(policy_support) dev.off() par(mfrow=c(2,2)) barplot(table(policy_support[streamed=="No"]),main="Policy Support: Non-Streamers",col=seq(3:7),ylim=c(0,100)) barplot(table(policy_support[downloaded=="No"]),main="Policy Support: Non-Downloaders",col=seq(3:7),ylim=c(0,100)) barplot(table(policy_support[streamed=="Yes"]),main="Policy Support: Streamers", col=seq(3:7),ylim=c(0,100)) barplot(table(policy_support[downloaded=="Yes"]), main="Policy Support: Downloaders",col=seq(3:7),ylim=c(0,100)) ############ ############ TABLE TABLE TABLE TABLE TABLE TABLE TABLE TABLE par(mfrow=c(2,2)) pie(table(policy_support[streamed=="No"]),main="Policy Support: Non-Streamers",col=seq(3:7)) pie(table(policy_support[downloaded=="No"]),main="Policy Support: Non-Downloaders",col=seq(3:7)) pie(table(policy_support[streamed=="Yes"]),main="Policy Support: Streamers", col=seq(3:7)) pie(table(policy_support[downloaded=="Yes"]), main="Policy Support: Downloaders",col=seq(3:7)) ############ (table(policy_support[downloaded=="Yes"]))/sum(table(policy_support[downloaded=="Yes"])) TABLE TABLE TABLE TABLE TABLE TABLE TABLE TABLE ############ ##################################################################################### ##################################################################################### ##################################################################################### ##################################################################################### table(download_acceptable[downloaded=="No"]) table(download_unethical[downloaded=="No"]) table(download_illegal[downloaded=="No"]) table(download_noopin[downloaded=="No"]) table(stream_acceptable[downloaded=="No"]) table(stream_unethical[downloaded=="No"]) table(stream_illegal[downloaded=="No"]) table(stream_noopin[downloaded=="No"]) table(youtube_acceptable[downloaded=="No"]) table(youtube_unethical[downloaded=="No"]) table(youtube_illegal[downloaded=="No"]) table(youtube_noopin[downloaded=="No"]) table(dtella_scenario_acceptable[downloaded=="No"]) table(dtella_scenario_unethical[downloaded=="No"]) table(dtella_scenario_illegal[downloaded=="No"]) table(dtella_scenario_noopin[downloaded=="No"]) table(youtube_scenario_acceptable[downloaded=="No"]) table(youtube_scenario_unethical[downloaded=="No"]) table(youtube_scenario_illegal[downloaded=="No"]) table(youtube_scenario_noopin[downloaded=="No"]) table(upload_scenario_acceptable[downloaded=="No"]) table(upload_scenario_unethical[downloaded=="No"]) table(upload_scenario_illegal[downloaded=="No"]) table(upload_scenario_noopin[downloaded=="No"]) table(download_acceptable[downloaded=="Yes"]) table(download_unethical[downloaded=="Yes"]) table(download_illegal[downloaded=="Yes"]) table(download_noopin[downloaded=="Yes"]) table(stream_acceptable[downloaded=="Yes"]) table(stream_unethical[downloaded=="Yes"]) table(stream_illegal[downloaded=="Yes"]) table(stream_noopin[downloaded=="Yes"]) table(youtube_acceptable[downloaded=="Yes"]) table(youtube_unethical[downloaded=="Yes"]) table(youtube_illegal[downloaded=="Yes"]) table(youtube_noopin[downloaded=="Yes"]) table(dtella_scenario_acceptable[downloaded=="Yes"]) table(dtella_scenario_unethical[downloaded=="Yes"]) table(dtella_scenario_illegal[downloaded=="Yes"]) table(dtella_scenario_noopin[downloaded=="Yes"]) table(youtube_scenario_acceptable[downloaded=="Yes"]) table(youtube_scenario_unethical[downloaded=="Yes"]) table(youtube_scenario_illegal[downloaded=="Yes"]) table(youtube_scenario_noopin[downloaded=="Yes"]) table(upload_scenario_acceptable[downloaded=="Yes"]) table(upload_scenario_unethical[downloaded=="Yes"]) table(upload_scenario_illegal[downloaded=="Yes"]) table(upload_scenario_noopin[downloaded=="Yes"]) #################################################################### #################################################################### jk.variance <- function(y,sti,P.Tot) { # # given # * individual observations y # * stratum identifiers sti # * stratum population totals P.Tot # # compute # # * weighted ybar # * jackknifed ybar # * jackknifed variance # # Nb., the "sti" can be any unique set of stratum indicators # (1 = stratum 1, 2 = stratum 2, etc.), and should be of # the same length as y. The "P.Tot" should be a vector of # population totals, one for each stratum. H <- length(unique(sti)) if (length(P.Tot)!=H) { stop("Need 'P.Tot' to contain the population sizes of the strata.") } P.Prop <- P.Tot/sum(P.Tot) n <- length(y) if (length(sti)!=n) { stop("Need 'sti' to contain stratum indicators for each y.") } weights <- function(sti,P.Prop) { S.Tot <- table(sti) S.Prop <- S.Tot/length(sti) S.Wgts <- P.Prop/S.Prop w <- rep(0,length(sti)) for (h in 1:length(S.Wgts)) { stn <- names(S.Wgts)[h] w[sti==stn] <- S.Wgts[stn] } return(w) } w <- weights(sti,P.Prop) ybar.weighted <- sum(y*w)/sum(w) ybar.r <- NULL for (r in 1:n) { y.r <- y[-r] sti.r <- sti[-r] w.r <- weights(sti.r,P.Prop) ybar.r <- c(ybar.r,sum(w.r*y.r)/sum(w.r)) } ybar.reps <- mean(ybar.r) s2.reps <- var(ybar.r) jkvar <- (n-1)/n * (n-1) * s2.reps return(list(ybar.weighted=ybar.weighted,ybar.reps=ybar.reps, var.jk=jkvar)) } jk.variance(streamed)