Skip to content
Snippets Groups Projects
Commit f59ee092 authored by Dhanush Kumar Reddy Narayana Reddy's avatar Dhanush Kumar Reddy Narayana Reddy
Browse files

adding vignettes

parent 68cdb62c
No related branches found
No related tags found
No related merge requests found
......@@ -2,3 +2,4 @@
.Rhistory
.RData
.Ruserdata
inst/doc
......@@ -15,5 +15,8 @@ Imports:
RoxygenNote: 7.3.2
Encoding: UTF-8
Suggests:
knitr,
rmarkdown,
testthat (>= 3.0.0)
Config/testthat/edition: 3
VignetteBuilder: knitr
......@@ -8,29 +8,23 @@
#' @import dplyr
#' @import ggplot2
#' @import nycflights13
#' @param dep_delay' dep_delay
#' @param origin origin
#' @param lon lon
#' @param lat lat
#' @param mean_delay mean_dealy
#' @examples
#' # Run the function to visualize mean delays by airport:
#' visualize_airport_delays()
#' @name visualize_airport_delays
#' @export
library(dplyr)
visualize_airport_delays <- function() {
# Join flights and airports datasets to include latitude and longitude
airport_delays <- nycflights13::flights %>%
dplyr::filter(!is.na(dep_delay)) %>% # Exclude rows where departure delay is NA
dplyr::group_by(origin) %>% # Group by airport
dplyr::summarize(mean_delay = mean(dep_delay, na.rm = TRUE)) %>%
dplyr::left_join(nycflights13::airports, by = c("origin" = "faa")) # Join with airports for lat/lon data
dplyr::filter(!is.na(.data$dep_delay)) %>%
dplyr::group_by(.data$origin) %>%
dplyr::summarize(mean_delay = mean(.data$dep_delay, na.rm = TRUE)) %>%
dplyr::left_join(nycflights13::airports, by = c("origin" = "faa"))
# Create the ggplot2 plot
ggplot2::ggplot(airport_delays, ggplot2::aes(x = lon, y = lat)) +
ggplot2::geom_point(ggplot2::aes(size = mean_delay, color = mean_delay), alpha = 0.9) +
ggplot2::ggplot(airport_delays, ggplot2::aes(x = .data$lon, y = .data$lat)) +
ggplot2::geom_point(ggplot2::aes(size = .data$mean_delay, color = .data$mean_delay), alpha = 0.9) +
ggplot2::scale_color_gradient(low = "blue", high = "red") +
ggplot2::labs(
title = "Mean Flight Delay by Airport",
......@@ -42,6 +36,4 @@ visualize_airport_delays <- function() {
ggplot2::theme_minimal()
}
# Call the function
visualize_airport_delays()
# visualize_airport_delays()
......@@ -35,8 +35,10 @@ For more information, see \url{https://en.wikipedia.org/wiki/Ridge_regression}
}
\examples{
%% for ridge model
data(iris)
model <- ridgereg$new(Sepal.Length ~ Sepal.Width + Petal.Length, data = iris,lambda = 0.1)
%% for visualze of deplays
visualize_airport_delays()
%% ~~ Optional simple examples of the most important functions ~~
}
......@@ -3,16 +3,8 @@
\name{visualize_airport_delays}
\alias{visualize_airport_delays}
\title{Visualize Mean Flight Delay by Airport}
\arguments{
\item{dep_delay'}{dep_delay}
\item{origin}{origin}
\item{lon}{lon}
\item{lat}{lat}
\item{mean_delay}{mean_dealy}
\usage{
visualize_airport_delays()
}
\value{
A ggplot2 object representing the visualization of mean flight delays by airport.
......
*.html
*.R
---
title: "group5labbonus"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{group5labbonus}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
```{r setup}
library(group5labbonus)
```
## Introduction
This vignette illustrates how to use lab4 package to perform linear and ridge progression models and to perform various special functions like print(), plot(), resid(), pred(),coef() and summary().
## DataSet
For testing purpose, here we are using iris dataset, containing measurements of features of flower iris. To load data use the following:
```{r}
data(iris)
```
## Invoking linreg function
This Function will take two parameters namely formula and data. Type of formula is an expression specifying the relationship between dependent and independent variables, whereas data is the dataset(iris in this case).
```{r}
linreg_mod <- linreg$new(Petal.Length~Sepal.Width+Sepal.Length, data=iris)
```
## Print Function
Printing the coefficients and coefficients name of the model generated using linreg function.This can be invoked by the following
```{r}
linreg_mod$print()
```
## Plot Function
Plotting for residuals against Fitted Values and for Scale-Locations against sqaure root of standardized residuals.
```{r}
plots <- linreg_mod$plot()
print(plots[[1]])
print(plots[[2]])
```
## Resid Function
Resid Function is to display the residuals of the model as a vector.
```{r}
# Get residuals
residuals <- linreg_mod$resid()
print(residuals)
```
## pred Function
pred Function is to display the predicted values of the model.
```{r}
# Get predicted values
predictions <- linreg_mod$pred()
print(predictions)
```
## Summary Function
Summary function is to display coefficients along with standard error, t-values, p-values with significance.
```{r}
linreg_mod$summary()
```
## Invoking Ridge function
To create a ridge regression model, specify a formula, a data frame, and a lambda value. In this case, we’ll set lambda to 0.1.
```{r}
data(iris)
# Create a ridge regression model with lambda = 0.1
mod <- ridgereg$new(formula = Sepal.Length ~ Sepal.Width + Petal.Length, data = iris, lambda = 0.1)
```
## Display the Model Coefficients
To view the model coefficients, use the show() method.
```{r}
mod$show()
```
## Extract model coefficients
```{r}
coefficients <- mod$coef()
print(coefficients)
```
## visualize airport delays
This function visualizes the mean flight delay at each origin airport in the nycflights13 dataset.It calculates the mean departure delay for each airport, joins this data with airport locations,and creates a scatter plot showing mean delay as point size and color on a map of airport locations.
```{r}
visualize_airport_delays()
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment