"Andrea Harnos"
18.08.2020
library(shiny)
shinyUI(fluidPage(
titlePanel("Demonstration of correlation"),
sidebarLayout(
sidebarPanel(
sliderInput("numeric", "How Many Random Numbers Should be generated?",
value = 100, min = 1, max = 1000, step = 1),
sliderInput("corr", "Set correlation", -1, 1, value = 0.5, step=0.1),
h4("The application generates random numbers from bivariate normal distribution (mean = 0, variance = 1). The number of points and the value of correlation can be adjusted. Scatterplot of the generated random numbers are shown.")
),
mainPanel(
plotOutput("plot1")))))
library(shiny)
library(MASS)
shinyServer(function(input, output) {
renderPlot({
number_of_points <-input$numeric
inpcorr <-input$corr
mu <- rep(0,2)
Sigma <- rbind(c(1,inpcorr),c(inpcorr,1))
rawvars <- mvrnorm(n=number_of_points, mu=mu, Sigma=Sigma)
plot(rawvars[,1], rawvars[,2], xlab="X",ylab="Y",
xlim = c(-4, 4), ylim = c(-4, 4), las=1)
text(-3,3.5,paste("Number of points =",number_of_points))
text(2,3.5,paste("Correlation given =",inpcorr))
calc_cor<-round(cor( rawvars[,1], rawvars[,2]),2)
text(2,3,paste("Calculated correlation =",calc_cor))
})