############################NONPARAMETRIC TESTS ####################### ####################################################################### data<-read.table("http://user.mendelu.cz/drapela/Forest_Biometry/data/plots.txt",sep='\t',header=TRUE) sprd13<-(data[data$species=='SPRUCE',]$d13) oakd13<-(data[data$species=='OAK',]$d13) summary(sprd13) summary(oakd13) length(sprd13) length(oakd13) ######################### 1-S WILXOCON TEST FOR POPULATION MEAN ########################################### #EDA FOR D13 OF OAK par(mfrow=c(1,2)) hist(oakd13, col="lightblue", main="Histogram DBH - oak", probability=TRUE, ylab="density", xlab=substitute(paste(d[13], "[cm]", sep=' '))) lines(density(oakd13), col="red", lty="dashed") tmp<-oakd13 lines(seq(min(tmp, na.rm=TRUE)-50, max(tmp, na.rm=TRUE)+50,1), dnorm(seq(min(tmp, na.rm=TRUE)-50, max(tmp, na.rm=TRUE)+50,1), mean(tmp, na.rm=TRUE), sd(tmp, na.rm=TRUE) ), col="black") #rankitovy graf d13 pro dub qqnorm(oakd13, main="QQ plot - DBH of oak") qqline(oakd13,col="red") shapiro.test(oakd13) #we test whether population parameter of location of DBH of oak is equal to 280 mm and 260 mm or not wilcox.test(oakd13, mu=280, alternative="two.sided") t.test(oakd13,mu = 280, alternative="two.sided") wilcox.test(oakd13, mu=260, alternative="two.sided") t.test(oakd13,mu = 260, alternative="two.sided") wilcox.test(oakd13, mu=280, alternative="greater") t.test(oakd13, mu=280, alternative="greater") wilcox.test(oakd13, mu=280, alternative="less") t.test(oakd13, mu=280, alternative="less") ######################### 2-S MANN-WHITNEY TEST FOR COMPARING OF TWO MEANS ########################################### # we test whether location shift is equal to 0 or not wilcox.test(sprd13,oakd13, alternative="two.sided") wilcox.test(sprd13,oakd13, alternative="greater") wilcox.test(sprd13,oakd13, alternative="less") ######################### PAIRED WILCOXON TEST ########################################### datacomp<-read.table("http://user.mendelu.cz/drapela/Forest_Biometry/data/data_comp.txt",sep='\t',quote='',header=TRUE) head(datacomp) # add id of place of measurement datacomp$id_pl<-seq(1, length(datacomp$id_tree), 1) #add new variables to dataframe datacomp - delta_foto (difference between diameters measured by caliper and #photo) and delta_crit (difference between diameters measured by caliper and Criterion) datacomp$delta_foto<-datacomp$da_calip-datacomp$da_foto datacomp$delta_crit<-datacomp$da_calip-datacomp$da_crit attach(datacomp) par(mfrow=c(1,1)) boxplot(delta_crit, notch=TRUE, names=c("delta_crit"), main="Box plot of differences\n caliper - criterion") abline(0,0,col="red") text(1, delta_crit[abs(delta_crit)>150], labels=id_pl[abs(delta_crit)>150], pos=4) par(mfrow=c(1,2)) #histogram tmp<-delta_crit[abs(delta_crit)<= 150] hist(tmp, col="lightblue", main="Histogram of differences\n caliper - criterion", probability=TRUE,ylab="density", xlab="difference [mm]") lines(density(tmp), col="red", lty="dashed") lines(seq(min(tmp, na.rm=TRUE)-50, max(tmp, na.rm=TRUE)+50,1), dnorm(seq(min(tmp, na.rm=TRUE)-50, max(tmp, na.rm=TRUE)+50,1), mean(tmp, na.rm=TRUE), sd(tmp, na.rm=TRUE) ), col="black") qqnorm(tmp, main="QQ plot of differences\n caliper - criterion"") qqline(tmp,col="red") shapiro.test(delta_crit[abs(delta_crit) <= 150]) wilcox.test(da_calip[abs(delta_crit) <= 150],da_crit[abs(delta_crit) <= 150], paired=TRUE, alternative="two.sided") wilcox.test(da_calip[abs(delta_crit) <= 150],da_crit[abs(delta_crit) <= 150], paired=TRUE, alternative="less") wilcox.test(da_calip[abs(delta_crit) <= 150],da_crit[abs(delta_crit) <= 150], paired=TRUE, alternative="greater") detach(datacomp)