knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(jeksterslabRdatarepo) library(knitr) library(DT) library(GGally) library(plotly) library(psych)
data( quartet, package = "jeksterslabRdatarepo" )
datatable( data = quartet, options = list( pageLength = 11, dom = "t" ) )
pair <- 1:4 x <- paste0("x", pair) y <- paste0("y", pair) muhat_x <- sigmahat_x <- muhat_y <- sigmahat_y <- rhohat <- rep(x = NA, times = length(pairs)) fit <- vector(mode = "list", length = length(pair)) for (i in seq_along(pair)) { fit[[i]] <- lm( quartet[, y[i]] ~ quartet[, x[i]] ) muhat_x[i] <- mean(quartet[, x[i]]) sigmahat_x[i] <- sd(quartet[, x[i]]) muhat_y[i] <- mean(quartet[, y[i]]) sigmahat_y[i] <- sd(quartet[, y[i]]) rhohat[i] <- cor(quartet[, x[i]], quartet[, y[i]]) }
plot_ly( data = quartet, type = "scatter", mode = "markers", x = ~x1, y = ~y1 ) %>% add_markers( y = ~y1 ) %>% add_trace( x = ~x1, y = fitted(fit[[1]]), mode = "lines" ) %>% layout( showlegend = F )
plot_ly( data = quartet, type = "scatter", mode = "markers", x = ~x2, y = ~y2 ) %>% add_markers( y = ~y2 ) %>% add_trace( x = ~x2, y = fitted(fit[[2]]), mode = "lines" ) %>% layout( showlegend = F )
plot_ly( data = quartet, type = "scatter", mode = "markers", x = ~x3, y = ~y3 ) %>% add_markers( y = ~y3 ) %>% add_trace( x = ~x3, y = fitted(fit[[3]]), mode = "lines" ) %>% layout( showlegend = F )
plot_ly( data = quartet, type = "scatter", mode = "markers", x = ~x4, y = ~y4 ) %>% add_markers( y = ~y4 ) %>% add_trace( x = ~x4, y = fitted(fit[[4]]), mode = "lines" ) %>% layout( showlegend = F )
kable( x = data.frame( pair, muhat_x, sigmahat_x, muhat_y, sigmahat_y, rhohat ), col.names = c( "Pair", "Mean (x)", "Standard Deviation (x)", "Mean (y)", "Standard Deviation (y)", "Correlation (x, y)" ) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.