energy <- read.table("C:/Rexamples/energydata.txt", header=T) View(energy) summary(energy) #part 1: houses of either design type energy_either <- subset(energy, design == 'either') View(energy_either) summary(energy_either) attach(energy_either) by(gas, type, function(x) summary(x)) by(gas, type, function(x) sd(x)) boxplot(gas~type) by(gas, type, function(x) stem(x)) qqnorm(gas[type=='extra'], main="Normal Q-Q Plot, extra insul") qqline(gas[type=='extra']) shapiro.test(gas[type=='extra']) qqnorm(gas[type=='standard'], main="Normal Q-Q Plot, standard insul") qqline(gas[type=='standard']) shapiro.test(gas[type=='standard']) t.test(gas~type) t.test(gas~type, var.equal=TRUE) detach(energy_either) #part 2: houses of solar design energy_solar <- subset(energy, design == 'solar') View(energy_solar) summary(energy_solar) attach(energy_solar) by(gas, type, function(x) summary(x)) by(gas, type, function(x) sd(x)) boxplot(gas~type) by(gas, type, function(x) stem(x)) qqnorm(gas[type=='extra'], main="Normal Q-Q Plot, extra insul") qqline(gas[type=='extra']) shapiro.test(gas[type=='extra']) qqnorm(gas[type=='standard'], main="Normal Q-Q Plot, standard insul") qqline(gas[type=='standard']) shapiro.test(gas[type=='standard']) t.test(gas~type) t.test(gas~type, var.equal=TRUE) --------------------- NOTE ------------------------ The first line above which reads the data from the file "energydata.txt" assumes that this file is in the directory "C:/Rexamples". Obey this convention or modify the command. -------------------------- results ---------------------------------- The boxplots and normal probability plots (qqplots) requested in this program will appear in the plot window of RStudio. They can be saved as pdfs or images. I have not posted them here. These plots are somewhat crude since I did not specify titles, labels, or such. The remainder of this file is copied and pasted from the RStudio command window. -------------------------------------------------------- > energy <- read.table("C:/Rexamples/energydata.txt", header=T) > View(energy) > summary(energy) gas type design Min. : 8.30 extra :25 either:26 1st Qu.:13.60 standard:28 solar :27 Median :15.30 Mean :15.28 3rd Qu.:17.60 Max. :21.70 > energy_either <- subset(energy, design == 'either') > View(energy_either) > summary(energy_either) gas type design Min. : 8.30 extra :14 either:26 1st Qu.:13.62 standard:12 solar : 0 Median :14.30 Mean :15.21 3rd Qu.:18.00 Max. :21.70 > attach(energy_either) > by(gas, type, function(x) summary(x)) type: extra Min. 1st Qu. Median Mean 3rd Qu. Max. 8.30 13.10 13.70 13.87 15.13 18.80 ----------------------------------------------- type: standard Min. 1st Qu. Median Mean 3rd Qu. Max. 11.40 13.98 18.00 16.77 18.92 21.70 > by(gas, type, function(x) sd(x)) type: extra [1] 2.363644 ----------------------------------------------- type: standard [1] 2.995856 > boxplot(gas~type) > the boxplots appear in the plot window of RStudio ***************** > by(gas, type, function(x) stem(x)) The decimal point is 1 digit(s) to the right of the | 0 | 8 1 | 23334444 1 | 55669 The decimal point is 1 digit(s) to the right of the | 1 | 1444 1 | 5888999 2 | 2 type: extra NULL ----------------------------------------------- type: standard NULL > qqnorm(gas[type=='extra'], main="Normal Q-Q Plot, extra insul") > qqline(gas[type=='extra']) > shapiro.test(gas[type=='extra']) Shapiro-Wilk normality test data: gas[type == "extra"] W = 0.9328, p-value = 0.3335 > the normal probability plot appears in the plot window of RStudio ***************** > qqnorm(gas[type=='standard'], main="Normal Q-Q Plot, standard insul") > qqline(gas[type=='standard']) > shapiro.test(gas[type=='standard']) Shapiro-Wilk normality test data: gas[type == "standard"] W = 0.9273, p-value = 0.3522 > the normal probability plot appears in the plot window of RStudio ***************** > t.test(gas~type) Welch Two Sample t-test data: gas by type t = -2.7034, df = 20.848, p-value = 0.01336 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -5.1234433 -0.6670329 sample estimates: mean in group extra mean in group standard 13.87143 16.76667 > t.test(gas~type, var.equal=TRUE) Two Sample t-test data: gas by type t = -2.7543, df = 24, p-value = 0.01104 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -5.0647571 -0.7257191 sample estimates: mean in group extra mean in group standard 13.87143 16.76667 > detach(energy_either) > energy_solar <- subset(energy, design == 'solar') > View(energy_solar) > summary(energy_solar) gas type design Min. :10.50 extra :11 either: 0 1st Qu.:13.50 standard:16 solar :27 Median :15.70 Mean :15.36 3rd Qu.:17.55 Max. :19.90 > attach(energy_solar) > by(gas, type, function(x) summary(x)) type: extra Min. 1st Qu. Median Mean 3rd Qu. Max. 10.50 12.00 14.50 14.23 15.70 19.00 ----------------------------------------------- type: standard Min. 1st Qu. Median Mean 3rd Qu. Max. 12.30 14.62 16.40 16.14 17.65 19.90 > by(gas, type, function(x) sd(x)) type: extra [1] 2.722532 ----------------------------------------------- type: standard [1] 2.079062 > boxplot(gas~type) > the boxplots appear in the plot window of RStudio ***************** > by(gas, type, function(x) stem(x)) The decimal point is at the | 10 | 534 12 | 60 14 | 5277 16 | 6 18 | 0 The decimal point is at the | 12 | 3378 14 | 969 16 | 3525689 18 | 09 type: extra NULL ----------------------------------------------- type: standard NULL > qqnorm(gas[type=='extra'], main="Normal Q-Q Plot, extra insul") > qqline(gas[type=='extra']) > shapiro.test(gas[type=='extra']) Shapiro-Wilk normality test data: gas[type == "extra"] W = 0.9561, p-value = 0.7219 > the normal probability plot appears in the plot window of RStudio ***************** > qqnorm(gas[type=='standard'], main="Normal Q-Q Plot, standard insul") > qqline(gas[type=='standard']) > shapiro.test(gas[type=='standard']) Shapiro-Wilk normality test data: gas[type == "standard"] W = 0.9591, p-value = 0.6463 > the normal probability plot appears in the plot window of RStudio ***************** > t.test(gas~type) Welch Two Sample t-test data: gas by type t = -1.9661, df = 17.726, p-value = 0.06515 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -3.953728 0.133273 sample estimates: mean in group extra mean in group standard 14.22727 16.13750 > t.test(gas~type, var.equal=TRUE) Two Sample t-test data: gas by type t = -2.0686, df = 25, p-value = 0.04907 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -3.812046821 -0.008407724 sample estimates: mean in group extra mean in group standard 14.22727 16.13750 > >