Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- graphics.off() # This closes all of R's graphics windows.
- rm(list=ls()) # Careful! This clears all of R's memory!
- library(ggplot2)
- library(ggpubr)
- library(ks)
- library(rjags)
- library(runjags)
- # Set working directory if necessary
- # setwd(" ")
- #na.omit for cleanup, there were some empty cells
- myData = na.omit(read.csv("camera_dataset.csv"))
- colnames(myData) = c("Model", "Release.date", "Max.resolution", "Low.resolution", "Effective.pixels",
- "Zoom.wide", "Zoom.tele", "Normal.focus.range", "Macro.focus.range",
- "Storage.included", "Weight.w.batteries", "Dimensions", "Price")
- yName = "Price" ; xName = c("Release.date", "Max.resolution", "Low.resolution", "Effective.pixels",
- "Zoom.wide", "Zoom.tele", "Normal.focus.range", "Macro.focus.range",
- "Storage.included", "Weight.w.batteries", "Dimensions")
- fileNameRoot = "Task9"
- library(ggplot2)
- head(myData)
- summary(myData)
- #graphics.off() # added to open plots in a new window. When plots are shown in the plots tab
- windows( width=480 , height=480) #they have low quality
- hist(myData$Price)
- #graphics.off() # added to open plots in a new window. When plots are shown in the plots tab
- windows( width=480 , height=480) #they have low quality
- plot(kde(myData$Price))
- # Scatter plots
- p1 <- ggplot(myData, aes(x=Release.date, y=Price)) +
- geom_point()
- p2 <- ggplot(myData, aes(x=Max.resolution, y=Price)) +
- geom_point()
- p3 <- ggplot(myData, aes(x=Low.resolution, y=Price)) +
- geom_point()
- p4 <- ggplot(myData, aes(x=Effective.pixels, y=Price)) +
- geom_point()
- p5 <- ggplot(myData, aes(x=Zoom.wide, y=Price)) +
- geom_point()
- p6 <- ggplot(myData, aes(x=Zoom.tele, y=Price)) +
- geom_point()
- p7 <- ggplot(myData, aes(x=Normal.focus.range, y=Price)) +
- geom_point()
- p8 <- ggplot(myData, aes(x=Macro.focus.range, y=Price)) +
- geom_point()
- p9 <- ggplot(myData, aes(x=Storage.included, y=Price)) +
- geom_point()
- p10 <- ggplot(myData, aes(x=Weight.w.batteries, y=Price)) +
- geom_point()
- p11 <- ggplot(myData, aes(x=Dimensions, y=Price)) +
- geom_point()
- figure <- ggarrange(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, nrow = 4, ncol = 3)
- #graphics.off() # added to open plots in a new window. When plots are shown in the plots tab
- windows( width=480 , height=480) #they have low quality
- figure
- numSavedSteps = 3500
- thinSteps = 10
- nChains = 4
- graphFileType = "eps"
- #-------------------------------------------------------------------------------
- # Load the relevant model into R's working memory:
- source("Jags-Ymet-XmetMulti-Mrobust-Task9.R")
- #-------------------------------------------------------------------------------
- # Generate the MCMC chain:
- startTime = proc.time()
- xPred = c( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 )
- mcmcCoda = genMCMC( data=myData , xName=xName , yName=yName ,
- numSavedSteps=numSavedSteps , thinSteps=thinSteps ,
- saveName=fileNameRoot , nChains = nChains , xPred = xPred )
- stopTime = proc.time()
- duration = stopTime - startTime
- show(duration)
- # save.image(file='Task6Chains.RData')
- # load('Task6Chains.RData')
- #-------------------------------------------------------------------------------
- # Display diagnostics of chain, for specified parameters:
- parameterNames = varnames(mcmcCoda) # get all parameter names
- for ( parName in parameterNames ) {
- diagMCMC( codaObject=mcmcCoda , parName=parName ,
- saveName=fileNameRoot , saveType=graphFileType )
- }
- #graphics.off()
- #-------------------------------------------------------------------------------
- # Get summary statistics of chain:
- summaryInfo = smryMCMC( mcmcCoda ,
- saveName=fileNameRoot )
- show(summaryInfo)
- # Display posterior information:
- plotMCMC( mcmcCoda , data=myData , xName=xName , yName=yName ,
- pairsPlot=TRUE , showCurve=FALSE ,
- saveName=fileNameRoot , saveType=graphFileType )
- #-------------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment