> # read in data, extract rows for douglas fir > trees <- read.csv('http://www.ms.unimelb.edu.au/%7Es620374/sampling/ufc.csv') > summary(trees) Plot Tree Species Dbh Min. : 1.00 Min. : 1.000 WC :251 Min. : 100.0 1st Qu.: 30.00 1st Qu.: 2.000 GF :185 1st Qu.: 222.5 Median : 58.00 Median : 3.000 DF : 77 Median : 329.0 Mean : 63.23 Mean : 3.465 WP : 44 Mean : 356.6 3rd Qu.: 97.00 3rd Qu.: 5.000 WL : 34 3rd Qu.: 457.0 Max. :144.00 Max. :13.000 SF : 14 Max. :1120.0 (Other): 32 NA's : 10.0 Height Min. : 0.0 1st Qu.:190.0 Median :240.0 Mean :240.7 3rd Qu.:290.0 Max. :480.0 NA's :248.0 > trees.df <- trees[trees$Species=="DF",] > > # plot Dbh against Height for all trees and douglas fir > par(mfrow=c(1,2)) > max(trees$Height, na.rm=T) [1] 480 > max(trees$Dbh, na.rm=T) [1] 1120 > plot(c(0, 1120), c(0, 480), type='n', xlab='Dbh', ylab='Height', main='All trees') > points(trees$Dbh, trees$Height) > max(trees.df$Height, na.rm=T) [1] 420 > max(trees.df$Dbh, na.rm=T) [1] 998 > plot(c(0, 998), c(0, 420), type='n', xlab='Dbh', ylab='Height', main='Douglas Firs') > points(trees.df$Dbh, trees.df$Height) > > # extract sample observations > trees.sample <- trees.df[!is.na(trees.df$Height),] > N <- length(trees.df[[1]]) > n <- length(trees.sample[[1]]) > > # SRS estimate of average Height > mu.srs <- mean(trees.sample$Height) > var.srs <- var(trees.sample$Height)*(1-n/N)/n > cat('SRS: mean', mu.srs, 'std dev', sqrt(var.srs), '\n') SRS: mean 254.3036 std dev 4.619371 > > # Ratio estimate > r <- mean(trees.sample$Height)/mean(trees.sample$Dbh) > mu.ratio <- r*mean(trees.df$Dbh) > var.ratio <- (var(trees.sample$Height) - + 2*r*cov(trees.sample$Height, trees.sample$Dbh) + r^2*var(trees.sample$Dbh))*(1-n/N)/n > cat('Ratio: mean', mu.ratio, 'std dev', sqrt(var.ratio), '\n') Ratio: mean 246.203 std dev 5.000876 > > # Linear Regression estimate > b <- cov(trees.sample$Height, trees.sample$Dbh)/var(trees.sample$Dbh) > mu.lr <- mean(trees.sample$Height) + b*(mean(trees.df$Dbh) - mean(trees.sample$Dbh)) > var.lr <- (var(trees.sample$Height) - cov(trees.sample$Height, trees.sample$Dbh)^2/ + var(trees.sample$Dbh))*(n-1)/(n-2)*(1-n/N)/n > cat('LR: mean', mu.lr, 'std dev', sqrt(var.lr), '\n') LR: mean 250.5279 std dev 3.123521 >