forked from a-pearson/UFOS-and-Patents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainScript.R
117 lines (90 loc) · 4.09 KB
/
MainScript.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
################################################################################
# ~ MAIN SCRIPT ~ #
################################################################################
#
# This script contains the code to set up the work flow used thorughout the
# rest of the project. It also contains housekeeping code.
#
# Project to use: "UFO Big Data.Rproj"
#
# The Scripts within this project should be run in the following order:
# - MainScript
# - cleaning.ufo.data
# - Patent_cleaner_script *raw files for this script are too
# large to be included in repo and must be downloaded for
# this script to run. All cleaned patent data is located
# in the repo and all other scripts do not rely on the raw
# data to run.*
# - AnalysisScript
#
################################################################################
#
#================== All Libraries and Files that Must be Loaded ================
#---- Libraries ----------------------------------------------------------------
library(openair)
library(tidyverse)
library(ggplot2)
library (ggpubr)
library (patentsview)
library (data.table)
#files that must be loaded:
#------ Patent Data (Cleaned) --------------------------------------------------
# had to reset working directory to retreve file...
setwd("2.Clean.Data")
clean.patent.db<- read.csv( "clean.patent.db.csv")
#------ UFO Data Raw -----------------------------------------------------------
# reset working directory back to original
setwd("~/GitHub/UFOS-and-Patents")
getwd()
ufo <- read.csv ("consolidated_weather_V03.csv")
# Raw UFO data obtained from the link below
# https://www.kaggle.com/emorelli/consolidated-ufo-weather-data?fbclid=IwAR1MXNp9DO_FY1gEuXL9N4R7_Upu-7C3jd3Zr3sfDF5pxdcbHuDMbvAH_8M
#----- UFO Data (Cleaned, used in Analysis script) -----------------------------
setwd("2.Clean.Data")
ufo.freq.table.date.range <- read.csv(paste(path.cd, "UFO.freq.date.range.TV.csv"))
# reset working directory back to original
setwd("~/GitHub/UFOS-and-Patents")
getwd()
#================================ Variables ====================================
# Number of UFO sightings required to make it a date of interest.
ufo.crit.val <- 5 # this was determined in the cleaning.ufo.data script, it is
# based off the mean frequency of UFO sightings during the
# data time period.
# Delay period before sampling of patent frequencies.
delay.period <- 14
# Length of sample period after delay (in days).
sample.period <- 30
# Number of samples the null distribution runs.
null.run.times <- 10000
#============================ WORK FLOW SET UP =================================
work.d <- getwd()
out.put.folders <- c("1.Raw.Data","2.Clean.Data", "3.Analysis", "4.Graphs",
"4.Graphs/Table")
# check if folders exist and make them if they don't.
# This loop checks goes through the given out.put.folders list and checks to see
# if they exisit in the working directory. If they don't they print "does not
# exisit" and creates them, if it does exist it prints "does exist"
for(i in 1:length(out.put.folders)){
if(!file.exists(out.put.folders[i])){
print(paste(i, "does not exist"))
dir.create(out.put.folders[i])
}else{
print(paste(i,"does exist"))
}
}
#---- Pathways---------
#path to 1.RawData folder
path.rd <- paste(work.d,"/",out.put.folders[1], "/", sep="")
#test the pathway...
# x.t <- c(5)
# write.csv(x.t,paste(path.rd, "test.x.csv"), row.names=FALSE)
# to remove row names from saved files ^^^
#Path to 2.Clean.Data
path.cd <- paste(work.d,"/",out.put.folders[2], "/", sep="")
# Path to 3.Analysis
path.a <- paste(work.d,"/",out.put.folders[3], "/", sep="")
# Path to 4.Graphs
path.g <- paste(work.d,"/",out.put.folders[4], "/", sep="")
# Path to Table folder in 4.Graphs folder
path.t <- paste(work.d,"/",out.put.folders[5], "/", sep="")
# write.csv(x.t,paste(path.t, "test.x.csv"), row.names=FALSE)