Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Demonstrating bi-variate correlations using simulation.
# Script to demonstrate distributions
library(eeptools)
library(shiny)
library(ggplot2)
rnormcor <- function(x,rho) rnorm(1,rho*x,sqrt(1-rho^2))
shinyServer(function(input,output){
output$distPlot<-reactivePlot(function(){
a<-rnorm(input$obs)
b<-sapply(a,rnormcor,rho=input$rho)
p<-qplot(a,b,alpha=0.85)+geom_smooth(method="lm",se=FALSE,size=1.1)+theme_dpi()
p<-p+labs(x="",y="",title="Demonstrating Correlations")
p<-p+geom_text(aes(x=-2.5,y=3,label=paste("Corr. =",input$rho,sep=" ")),size=8)
print(p)
})
})
# Script to demonstrate distributions
library(eeptools)
library(shiny)
library(ggplot2)
shinyUI(pageWithSidebar(
# Title
headerPanel("Simulating Data with Correlation"),
sidebarPanel(
sliderInput("obs","Number of observations:",
min=200,max=5000,value=500,step=250),
sliderInput("rho","Correlation Coefficient",
min=-1,max=1,value=0,step=0.1)
),
# GGPLOT
mainPanel(
plotOutput("distPlot")
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.