diff --git a/docs/GP_Practical_files/figure-html/unnamed-chunk-6-1.png b/docs/GP_Practical_files/figure-html/unnamed-chunk-6-1.png index 33c47a4..a5ec4e6 100644 Binary files a/docs/GP_Practical_files/figure-html/unnamed-chunk-6-1.png and b/docs/GP_Practical_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/Stats_review.html b/docs/Stats_review.html index 3c78bc3..6c23186 100644 --- a/docs/Stats_review.html +++ b/docs/Stats_review.html @@ -353,7 +353,7 @@

Random Variables (RVs)

  • discrete (numbers of items or successes)
  • continuous (heights, times, weights)
  • -

    We usually use capital letters – e.g. X, Y, sometimes with bold or with subscripts – to denote the RVs. In contrast we use lower case letters, e.g. x, y, k, to denote the values that the RV takes. For instance, lets say that the heights of the woman at Virginia Tech are the RV, X, and X has a normal distribution with mean 62 inches and variance 6^2, i.e., X \sim \mathrm{N}(62,6^2) distribution. Say we then observe the heights of 3 individuals drawn from this distribution – we would write this as: x=( 60.3, 66.6, 56.1 ).

    +

    We usually use capital letters – e.g. X, Y, sometimes with bold or with subscripts – to denote the RVs. In contrast we use lower case letters, e.g. x, y, k, to denote the values that the RV takes. For instance, lets say that the heights of the woman at Virginia Tech are the RV, X, and X has a normal distribution with mean 62 inches and variance 6^2, i.e., X \sim \mathrm{N}(62,6^2) distribution. Say we then observe the heights of 3 individuals drawn from this distribution – we would write this as: x=( 68.3, 63.8, 72.4 ).



    @@ -577,7 +577,7 @@

    Probability Distributions in R

    rnorm(3, mean=0, sd=1) ## random draws
    -
    [1]  1.2016687 -0.0771098 -0.1688577
    +
    [1] 0.22654701 1.85129270 0.02351271
    diff --git a/docs/Stats_review_files/figure-html/unnamed-chunk-7-1.png b/docs/Stats_review_files/figure-html/unnamed-chunk-7-1.png index 98b974e..8480706 100644 Binary files a/docs/Stats_review_files/figure-html/unnamed-chunk-7-1.png and b/docs/Stats_review_files/figure-html/unnamed-chunk-7-1.png differ diff --git a/docs/Stats_review_files/figure-html/unnamed-chunk-8-1.png b/docs/Stats_review_files/figure-html/unnamed-chunk-8-1.png index c561de3..492a060 100644 Binary files a/docs/Stats_review_files/figure-html/unnamed-chunk-8-1.png and b/docs/Stats_review_files/figure-html/unnamed-chunk-8-1.png differ diff --git a/docs/Stats_review_files/figure-html/unnamed-chunk-9-1.png b/docs/Stats_review_files/figure-html/unnamed-chunk-9-1.png index 85b850b..7523a26 100644 Binary files a/docs/Stats_review_files/figure-html/unnamed-chunk-9-1.png and b/docs/Stats_review_files/figure-html/unnamed-chunk-9-1.png differ diff --git a/docs/VB_RegDiagTrans_files/figure-revealjs/unnamed-chunk-15-1.png b/docs/VB_RegDiagTrans_files/figure-revealjs/unnamed-chunk-15-1.png index 1ca3a45..608d929 100644 Binary files a/docs/VB_RegDiagTrans_files/figure-revealjs/unnamed-chunk-15-1.png and b/docs/VB_RegDiagTrans_files/figure-revealjs/unnamed-chunk-15-1.png differ diff --git a/docs/VB_RegDiagTrans_files/figure-revealjs/unnamed-chunk-19-1.png b/docs/VB_RegDiagTrans_files/figure-revealjs/unnamed-chunk-19-1.png index 6d6fb87..8b571f5 100644 Binary files a/docs/VB_RegDiagTrans_files/figure-revealjs/unnamed-chunk-19-1.png and b/docs/VB_RegDiagTrans_files/figure-revealjs/unnamed-chunk-19-1.png differ diff --git a/docs/VB_RegDiagTrans_files/figure-revealjs/unnamed-chunk-20-1.png b/docs/VB_RegDiagTrans_files/figure-revealjs/unnamed-chunk-20-1.png index be08848..1794c82 100644 Binary files a/docs/VB_RegDiagTrans_files/figure-revealjs/unnamed-chunk-20-1.png and b/docs/VB_RegDiagTrans_files/figure-revealjs/unnamed-chunk-20-1.png differ diff --git a/docs/VB_RegDiagTrans_files/figure-revealjs/unnamed-chunk-7-1.png b/docs/VB_RegDiagTrans_files/figure-revealjs/unnamed-chunk-7-1.png index d36c052..7ad659e 100644 Binary files a/docs/VB_RegDiagTrans_files/figure-revealjs/unnamed-chunk-7-1.png and b/docs/VB_RegDiagTrans_files/figure-revealjs/unnamed-chunk-7-1.png differ diff --git a/docs/code/df_spline.R b/docs/code/df_spline.R new file mode 100644 index 0000000..48b78c0 --- /dev/null +++ b/docs/code/df_spline.R @@ -0,0 +1,110 @@ +library(tidyverse) +# setup_x1.iso: an alternative setup to x1. Here we take x1 = iso_week +fx1.iso <- function(datetime){ + startdate <- min(datetime) # identify start week + x1 <- as.numeric(stringr::str_sub(ISOweek::ISOweek(datetime),7, 8)) # find iso week # + return(x1) +} + +site_data <- readr::read_csv(paste0("https://raw.githubusercontent.com/eco4cast/neon4cast-targets/", + "main/NEON_Field_Site_Metadata_20220412.csv")) |> + dplyr::filter(ticks == 1) + +site.info <- cbind.data.frame(site_data[,c("field_site_id","field_latitude", "field_longitude", "field_mean_elevation_m")], + site_data[,c("field_avg_grean_increase_doy", "field_avg_green_decrease_doy", + "field_avg_number_of_green_days", "field_avg_green_max_doy", "field_avg_green_min_doy")]) + + +colnames(site.info) <- c("site","lat", "long", "alt", "g.inc", "g.dec", "g.avg", "g.max", "g.min") + + +sites_sum <- site.info +df <- readr::read_csv("https://data.ecoforecast.org/neon4cast-targets/ticks/ticks-targets.csv.gz", guess_max = 1e1) +df <- df[, c("datetime", "site_id", "observation")] +colnames(df) <- c("datetime", "site", "y") + +cutoff <- "2020-12-31" +sites_sum[,5:9] <- apply(sites_sum[,5:9], 2, function(x) as.numeric(unlist(x))/7) +loc <- unique(df$site) +n.site <- length(loc) + +df <- df[df$datetime<=cutoff,] + +X <- sites_sum[,c("g.inc","g.max","g.dec","g.min")] +X <- floor(X) +rownames(X) <- loc + +df$iso <- fx1.iso(df$datetime) + +Y <- matrix(NA,ncol = ncol(X), nrow=nrow(X)) +rownames(Y) <- rownames(X) + +for(i in 1:n.site){ + + df.loc <- subset(df,df$site==loc[i]) + # y1l <- c(df.loc$y[which(df.loc$iso == X[i,1])]) + # y2l <- c(df.loc$y[which(df.loc$iso == X[i,2])]) + # y3l <- c(df.loc$y[which(df.loc$iso == X[i,3])]) + # y4l <- c(df.loc$y[which(df.loc$iso == X[i,4])]) + y1l <- c(df.loc$y[which(df.loc$iso == X[i,1])],df.loc$y[which(df.loc$iso == (X[i,1]+1))]) + y2l <- c(df.loc$y[which(df.loc$iso == X[i,2])],df.loc$y[which(df.loc$iso == (X[i,2]+1))]) + y3l <- c(df.loc$y[which(df.loc$iso == X[i,3])],df.loc$y[which(df.loc$iso == (X[i,3]+1))]) + y4l <- c(df.loc$y[which(df.loc$iso == X[i,4])],df.loc$y[which(df.loc$iso == (X[i,4]+1))]) + + if(length(y1l) == 0) + y1 <- 0 + else + y1 <- mean(y1l) + + if(length(y2l) == 0) + y2 <- 0 + else + y2 <- mean(y2l) + + if(length(y3l) == 0) + y3 <- 0 + else + y3 <- mean(y3l) + + if(length(y4l) == 0) + y4 <- 0 + else + y4 <- mean(y4l) + + Y[i,] <- c(y1,y2,y3,y4) +} + +X1 <- rep(1, 9) +Y1 <- rep(0, 9) +X6 <- rep(53, 9) +Xs <- cbind(X1,X,X6) +Ys <- cbind(Y1,Y,Y1) + +df_sp <- NULL +for(i in 1:n.site){ + + X.site <- as.numeric(Xs[i,]) + Y.site <- as.numeric(Ys[i,]) + + cubic.spline <- spline(X.site,Y.site,n=53, method = "natural") + + if(Y.site[5] == 0) + cubic.spline$y[cubic.spline$x>X.site[5]] = 0 + if(Y.site[2] == 0) + cubic.spline$y[cubic.spline$x left_join(site.info,"site") +df_green <- df_sp[, 1:3] + +# write.csv(df_sp, '../../csv/df_sp.csv') diff --git a/docs/materials_temp.html b/docs/materials_temp.html index 688c5ac..4ed450d 100644 --- a/docs/materials_temp.html +++ b/docs/materials_temp.html @@ -248,6 +248,7 @@

    Lecture Slides
  • Lecture Notes
  • Practical
  • +
  • additional R code – df_spline.R


  • diff --git a/docs/search.json b/docs/search.json index 2b11c1f..69cb678 100644 --- a/docs/search.json +++ b/docs/search.json @@ -200,7 +200,7 @@ "href": "materials_temp.html#gaussian-process-models-gps-for-time-dependent-data", "title": "VectorByte Training Materials 2024", "section": "Gaussian Process models (GPs) for Time Dependent Data", - "text": "Gaussian Process models (GPs) for Time Dependent Data\n\nLecture Slides\nLecture Notes\nPractical" + "text": "Gaussian Process models (GPs) for Time Dependent Data\n\nLecture Slides\nLecture Notes\nPractical\nadditional R code – df_spline.R" }, { "objectID": "index.html", diff --git a/materials_temp.qmd b/materials_temp.qmd index 0c66c24..3a103c3 100644 --- a/materials_temp.qmd +++ b/materials_temp.qmd @@ -81,5 +81,6 @@ We are assuming familiarity with R basics as well as at least introductory stati - [Lecture Slides](GP.qmd) - [Lecture Notes](GP_Notes.qmd) - [Practical](GP_Practical.qmd) +- [additional R code -- df_spline.R](code/df_spline.R)