Alden Felix
  • Home
  • Resume
  • Projects
    • Predicting Interstate Affinity using Machine Learning/Database Building
    • Effect of Road Classification on Alcohol Related Crash Severity
    • Exploring Human Mobility Patterns Using Twitter Data
    • Natural Language Processing of Tweets to Explore Mental Health
  • Fall 2022
    • EPPS 6302 Data Collection & Production
    • Assignment 2
    • Assignment 3
    • Assignment 4
    • EPPS 6356 Data Visualization
    • Assignment 1
    • Assignment 2
    • Assignment 3
    • Assignment 4
    • Assignment 6
    • Assignment 7
    • Assignment 9
  • Spring 2023
    • EPPS 6323 Knowledge Mining
    • EPPS 6323 Assignment 2
    • EPPS 6323 Assignment 3
    • EPPS 6323 Assignment 4
    • EPPS 6323 Assignment 5
    • EPPS 6323 Assignment 6
    • EPPS 6323 Assignment 7
    • EPPS 6323 Assignment 8
    • EPPS 6354 Information Management
    • Assignments
  • About

On this page

  • R Programming (EDA)
  • Regression object

EPPS 6323 Assignment 3

R Programming (EDA)

(Adapted from Stackoverflow examples) (Objectives: Use plotly, reshape packages, interactive visualization)

library(tidyverse)
library(plotly)
data(iris)
attach(iris)
# Generate plot on three quantitative variables
iris_plot <- plot_ly(iris,
                     x = Sepal.Length,
                     y = Sepal.Width,
                     z = Petal.Length,
                     type = "scatter3d",
                     mode = "markers",
                     size = 0.02)
iris_plot
# Regression object

petal_lm <- lm(Petal.Length ~ 0 + Sepal.Length + Sepal.Width,
               data = iris)
library(reshape2)

#load data

petal_lm <- lm(Petal.Length ~ 0 + Sepal.Length + Sepal.Width,data = iris)

# Setting resolution parameter
graph_reso <- 0.05

#Setup Axis
axis_x <- seq(min(iris$Sepal.Length), max(iris$Sepal.Length), by = graph_reso)
axis_y <- seq(min(iris$Sepal.Width), max(iris$Sepal.Width), by = graph_reso)

# Regression surface
# Rearranging data for plotting
petal_lm_surface <- expand.grid(Sepal.Length = axis_x,Sepal.Width = axis_y,KEEP.OUT.ATTRS = F)
petal_lm_surface$Petal.Length <- predict.lm(petal_lm, newdata = petal_lm_surface)
petal_lm_surface <- acast(petal_lm_surface, Sepal.Width ~ Sepal.Length, value.var = "Petal.Length")
hcolors=c("orange","blue","green")[iris$Species]
iris_plot <- plot_ly(iris,
                     x = ~Sepal.Length,
                     y = ~Sepal.Width,
                     z = ~Petal.Length,
                     text = Species,
                     type = "scatter3d",
                     mode = "markers",
                     marker = list(color = hcolors),
                     size=0.02)
# Add surface
iris_plot <- add_trace(p = iris_plot,
                       z = petal_lm_surface,
                       x = axis_x,
                       y = axis_y,
                       type = "surface",mode = "markers",
                       marker = list(color = hcolors))
iris_plot

Regression object

petal_lm <- lm(Petal.Length ~ 0 + Sepal.Length + Sepal.Width, 
               data = iris)