Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ export(interactive_matrix_inverse)
export(interactive_pca)
export(interactive_regression)
export(interactive_sampling)
export(interactive_similarity)
export(interactive_t_test)
export(machine_precision)
export(plot_logit)
export(plot_matrix_inverse)
export(plot_regr)
export(plot_sampling)
export(plot_sim)
export(plot_t_test)
24 changes: 24 additions & 0 deletions R/similarity_interactive.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#' compstatslib interactive_similarity() function
#'
#' @return
#' @export
#'
#' @examples
interactive_similarity <- function(points=data.frame(), ...) {
cat("Click on the plot to create data points; hit [esc] to stop")
repeat {
plot_sim(points, ...)

click_loc <- locator(1)
if (is.null(click_loc)) break

if(nrow(points) == 0 ) {
points <- data.frame(x=click_loc$x, y=click_loc$y)
} else {
points <- rbind(points, c(click_loc$x, click_loc$y))
}
}

return(points)

}
37 changes: 37 additions & 0 deletions R/similarity_plot.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' compstatslib plot_sim() function
#'
#' @param points
#'
#' @return
#' @export
#'
#' @examples
plot_sim <- function(points) {
max_x <- 5
if (nrow(points) == 0) {
plot(NA, xlim=c(0,max_x), ylim=c(0,max_x), xlab="ac1", ylab="ac2")
return()
}
plot(points, xlim=c(0,max_x), ylim=c(0,max_x), pch=19, cex=2, col="gray")
arrows(x0 = 0, y0 = 0, x1 = points[, 1], y1 = points[, 2], col = "cornflowerblue")

if (nrow(points) < 2) return()

data_matrix <- as.matrix(points)

recommend(data_matrix)
}

recommend <- function(data_matrix) {
cosines <- cosine(data_matrix)

data_transpose <- t(data_matrix)

data_means <- apply(data_transpose, 2, mean)
data_means_matrix <- t(replicate(nrow(data_matrix), data_means))
data_means_matrix_mc <- data_transpose - data_means_matrix

cors <- cosine(data_means_matrix_mc)

c(cosines, cors)
}
11 changes: 11 additions & 0 deletions man/interactive_similarity.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/plot_sim.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.