TU Wien:Statistik und Wahrscheinlichkeitstheorie UE (Levajkovic)/Übungen 2023W/HW06.3

Aus VoWi
Zur Navigation springen Zur Suche springen
Dataset trees

trees is the R dataset package containing diameter, height and volume for 31 black cherry trees. Denote by h the vector that contains the values of the column Height and by v the vector that contains the values of the column Volume from the dataset trees.

(a) Make the frequency table of the height of black cherry trees. The command table is useful.

(b) Compute the sample means and the sample variances for both vectors.

(c) Compute the covariance and the correlation of these two vectors.

Use qqplot to produce quantile-quantile plot of the two datasets. More info via ?qqplot.

(d) Explain the outputs of the commands fivenum and summary.

Dieses Beispiel ist als solved markiert. Ist dies falsch oder ungenau? Aktualisiere den Lösungsstatus (Details: Vorlage:Beispiel)


Lösungsvorschlag von Lessi[Bearbeiten | Quelltext bearbeiten]

--Lessi 2024-02-07T13:04:11Z

attach(trees)

trees

#a) 

Height
table(Height)
?table

#b)

mean_height = mean(Height)
sd_heigt = var(Height)

mean_volume = mean(Volume)
sd_volume = var(Volume)

#c)

covariance = cov(Height, Volume)
covariance
correlation = cor(Height, Volume)
correlation

qqplot(Height, Volume)

# I think the gist here is to see how the variables are related but its also interesting how each variable is distributed
qqnorm(Height)
qqline(Height)

qqnorm(Volume)
qqline(Volume)

#d) 
# fivenum returns a summary of the samples based on Minimum, Lower-Quartile, Median, Upper-Quartile, Maximum
fivenum(Height)
fivenum(Volume)

# summary returns a summary similar to fivenum, however it also calculates the mean
summary(Height)
summary(Volume)