library(boot) library(tidyverse)

FUNCTION: sim_wit

purpose: simulate witness tree data

input: sample size

output: wit data set of length 1000

#——————–

sim_wit <- function(size=1000) {
  wit <- rnorm(n=2000, mean=0.136, sd=0.163)
  wit <- wit[wit >= 0]
  wit <- wit[1:size]
  return(wit)
}

FUNCTION: sim_fia

purpose: simulate FIA data

input: sample size

output: fia data set of length 1000

#——————–

sim_fia <- function(size=1000) {
  fia <- rnorm(n=3000, mean=0.175, sd=0.919)
  fia <- fia[fia >= 0]
  fia <- fia[fia <= 1]
  fia <- fia[1:size]
  return(fia)
}

FUNCTION: plot_sim

purpose: simulate FIA data

input: fia and wit

output: fia data set of length 1000

#——————–

plot_sim <- function() {
par(mfrow=c(1,2))
p1 <- hist(wit)
p2 <- hist(fia)
}

FUNCTION: p_t_test

purpose: paired t test between wit and fia data

input: fia and wit

output: p value

#——————–

p_t_test <- function() {
  test <- t.test(wit, fia, paired = TRUE, alternative = "two.sided")
    return(test$p.value)
}

Global variables

#———————————————-

size <- 1000

#———————————————-

Program body

wit <- sim_wit()
fia <- sim_fia()
plot <- plot_sim()

p_val <- p_t_test()
print(head(wit))
## [1] 0.1690042 0.1141015 0.1948066 0.1396346 0.3567820 0.3261598
print(head(fia))
## [1] 0.6543397 0.1661464 0.8553390 0.5093315 0.4628313 0.5785354
print(p_val)
## [1] 1.535248e-126

Changing std of simulated FIA data to same as Witness data

FUNCTION: sim_wit

purpose: simulate witness tree data

input: sample size

output: wit data set of length 1000

#——————–

sim_wit <- function(size=1000) {
  wit <- rnorm(n=2000, mean=0.136, sd=0.163)
  wit <- wit[wit >= 0]
  wit <- wit[1:size]
  return(wit)
}

FUNCTION: sim_fia

purpose: simulate FIA data

input: sample size

output: fia data set of length 1000

#——————–

sim_fia <- function(size=1000) {
  fia <- rnorm(n=3000, mean=0.175, sd=0.163)
  fia <- fia[fia >= 0]
  fia <- fia[fia <= 1]
  fia <- fia[1:size]
  return(fia)
}

FUNCTION: plot_sim

purpose: simulate FIA data

input: fia and wit

output: fia data set of length 1000

#——————–

plot_sim <- function() {
par(mfrow=c(1,2))
p1 <- hist(wit)
p2 <- hist(fia)
}

FUNCTION: p_t_test

purpose: paired t test between wit and fia data

input: fia and wit

output: p value

#——————–

p_t_test <- function() {
  test <- t.test(wit, fia, paired = TRUE, alternative = "two.sided")
    return(test$p.value)
}

FUNCTION: new_df

purpose: create a new dataframe combining witness and fia data

input: fia and wit

output: wit_fia

#——————–

new_df <- function() {
  wit_fia <- merge(wit,fia)
    return(wit_fia)
}

Global variables

#———————————————-

size <- 1000

#———————————————-

Program body

wit <- sim_wit()
fia <- sim_fia()
plot <- plot_sim()

p_val <- p_t_test()
wit_fia <- new_df()
print(head(wit))
## [1] 0.1470471 0.1673131 0.1675279 0.1462790 0.1526739 0.1990632
print(head(fia))
## [1] 0.1491545 0.3143144 0.2180868 0.3339975 0.1017658 0.2879255
print(head(wit_fia))
##           x         y
## 1 0.1470471 0.1491545
## 2 0.1673131 0.1491545
## 3 0.1675279 0.1491545
## 4 0.1462790 0.1491545
## 5 0.1526739 0.1491545
## 6 0.1990632 0.1491545
print(p_val)
## [1] 8.168173e-08

still significantly different, but less so