blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
2
327
content_id
stringlengths
40
40
detected_licenses
listlengths
0
91
license_type
stringclasses
2 values
repo_name
stringlengths
5
134
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringclasses
46 values
visit_date
timestamp[us]date
2016-08-02 22:44:29
2023-09-06 08:39:28
revision_date
timestamp[us]date
1977-08-08 00:00:00
2023-09-05 12:13:49
committer_date
timestamp[us]date
1977-08-08 00:00:00
2023-09-05 12:13:49
github_id
int64
19.4k
671M
star_events_count
int64
0
40k
fork_events_count
int64
0
32.4k
gha_license_id
stringclasses
14 values
gha_event_created_at
timestamp[us]date
2012-06-21 16:39:19
2023-09-14 21:52:42
gha_created_at
timestamp[us]date
2008-05-25 01:21:32
2023-06-28 13:19:12
gha_language
stringclasses
60 values
src_encoding
stringclasses
24 values
language
stringclasses
1 value
is_vendor
bool
2 classes
is_generated
bool
2 classes
length_bytes
int64
7
9.18M
extension
stringclasses
20 values
filename
stringlengths
1
141
content
stringlengths
7
9.18M
20bafcc58f8f787bb18c74366b6a43b514938a7f
ace889efe2683b178c4195f8209b955e78392f88
/3.1- POPULARITY OF MUSIC RECORDS.R
aef6c78301f4b0feb98f9b51ffb14a9d1bdd56fa
[]
no_license
lucaslrolim/MITx-15.071x
7517bc79fb6a51a6189e9d90e333afcca29f3dbe
3cbbc08ce90d1744b90745390628f8b2be8c7862
refs/heads/master
2016-09-13T13:06:51.777416
2016-06-04T05:00:08
2016-06-04T05:00:08
57,808,487
0
0
null
null
null
null
UTF-8
R
false
false
2,044
r
3.1- POPULARITY OF MUSIC RECORDS.R
songs <- read.csv("./data/songs.csv") # How many observations (songs) are from the year 2010? length(songs$year[songs$year == 2010]) # How many songs does the dataset include for which the artist name is "Michael Jackson"? length(songs$artistname[songs$artistname == "Michael Jackson"]) # Which of these songs by Michael Jackson made it to the Top 10? Select all that apply. songs$songtitle[songs$artistname == "Michael Jackson" & songs$Top10 == 1] # The variable corresponding to the estimated time signature (timesignature) is discrete, meaning that it only takes # integer values (0, 1, 2, 3, . . . ). What are the values of this variable that occur in our dataset? Select all that apply. unique(songs$timesignature) # Which timesignature value is the most frequent among songs in our dataset? table(songs$timesignature) # Out of all of the songs in our dataset, the song with the highest tempo is one of the following songs. Which one is it? songs$songtitle[which.max(songs$tempo)] # Creating Our Prediction Model SongsTrain = subset(songs, songs$year <= 2009) SongsTest = subset(songs, songs$year > 2009) nrow(SongsTrain) nonvars = c("year", "songtitle", "artistname", "songID", "artistID") SongsTrain = SongsTrain[ , !(names(SongsTrain) %in% nonvars) ] SongsTest = SongsTest[ , !(names(SongsTest) %in% nonvars) ] SongsLog1 = glm(Top10 ~ ., data=SongsTrain, family=binomial) # What is the correlation between the variables "loudness" and "energy" in the training set? cor(SongsTrain$energy,SongsTrain$loudness) SongsLog2 = glm(Top10 ~ . - loudness, data=SongsTrain, family=binomial) SongsLog3 = glm(Top10 ~ . - energy, data=SongsTrain, family=binomial) # Make predictions on the test set using Model 3. What is the accuracy of # Model 3 on the test set, using a threshold of 0.45? predictTest = predict(SongsLog3,type = "response", newdata = SongsTest) table(SongsTest$Top10,predictTest > 0.45) # What would the accuracy of the baseline model be on the test set? length(SongsTest$Top10[SongsTest$Top10 != 1]) / nrow(SongsTest)
ea0e39a852f2a8fa6c6360b25168ba305240078c
b59142edc6f40f965bdb9ff4bda1cdc54c2ddb60
/man/zinb_regulated.Rd
2b1701334276257624a2b2c633f18671ab6bccae
[]
no_license
SkadiEye/RZiMM
8de9b45f116ebf1cda8c474897bfd7f6eebddba8
c846b2e61c404a073e65b5121372d88fcaf6b5b1
refs/heads/master
2022-09-29T05:06:50.478481
2022-09-24T06:01:21
2022-09-24T06:01:21
248,108,047
3
0
null
null
null
null
UTF-8
R
false
true
1,840
rd
zinb_regulated.Rd
% Generated by roxygen2: do not edit by hand % Please edit documentation in R/2-1-c-RZiMM-Count.R \name{zinb_regulated} \alias{zinb_regulated} \title{A Zero-Inflated Negative Binomial Model - for RZiMM-Count Model} \usage{ zinb_regulated( y, g_ind, m_ind = NULL, g_list = NULL, m_list = NULL, gm_list = NULL, lambda1 = 1, lambda2 = 0, n_iter = 10, epsilon = 10^-6, output = "vec", epsilon0 = 10^-6, plot = FALSE, max_l_alpha = 10, min_l_alpha = -10, max_est = 100, min_est = -100, max_logit_pi = 100, min_logit_pi = -100 ) } \arguments{ \item{y}{A vector of expression levels} \item{g_ind}{A vector of cell-type clusters} \item{m_ind}{Sample index, for adjusting within-sample correlation; if set to be NULL, the within-sample correlation will not be adjusted.} \item{g_list}{A list for cell-type cluster indices} \item{m_list}{A list for batch indices} \item{gm_list}{A two-way list for cell-type cluster and batch indices} \item{lambda1}{Weight of regularization for group effects.} \item{lambda2}{Weight of regularization for sample effects.} \item{n_iter}{Maximum number of total iteration.} \item{epsilon}{Iteration stops when the change from last iteration is smaller than this value.} \item{output}{Whether export a vector or a list} \item{epsilon0}{A small number for calculating the number of parameters.} \item{plot}{Whether plotting the trajectories for the loss and log-likelihood} \item{max_l_alpha}{Upper threshold for l} \item{min_l_alpha}{Lower threshold for l} \item{max_est}{Upper threshold for estimate} \item{min_est}{Lower threshold for estimate} \item{max_logit_pi}{Upper threshold for pi} \item{min_logit_pi}{Lower threshold for pi} } \value{ Returns a vector of parameters. } \description{ A Zero-Inflated Negative Binomial Model - for RZiMM-Count Model }
849ae287dc98892aebfa196d42dfe8d817a66811
4dadd6709aef1a3da646f1b7f8fc23b3c017d88f
/sna_um_cleanup.R
71b24e0d1c5d8928da783618ff9e2c6dfa769ba7
[]
no_license
katerinabc/sna_at_um
eefc97aa9e9b158e53bfb2e5447861fc57c3faac
d09a13928f368f440aadb5a1216d7b0e8f52dfdb
refs/heads/master
2021-01-10T09:39:54.059691
2016-04-11T00:55:26
2016-04-11T00:55:26
55,929,876
0
0
null
null
null
null
UTF-8
R
false
false
9,803
r
sna_um_cleanup.R
#Script to analyze SNA at UM dataset. #Created on XX November 2015 #Updated March 6th 2016 #next step: combine answers for project 2 # analysis ---------------------------------------------------------------- #do logistic regression #calculate network characteristics for its members. #indegree, outdegree, density for each group #beweenness #structural equivalence #if part of triad.... #argument: inverted U curve RS between ties and performance. #if collaboration judged good = center in network, many links # Questions ------------------------------------------------------ # what is answer 0 in att3? missing values? # preface ------------------------------------------------------ # start with a clean working space rm(list=ls()) # load previous data # set the working directory setwd("~/Dropbox/Network Analysis Innovation at UM/paper") # load packages # library(statnet) library(statnet) # load data ------------------------------------------------------ # att1.raw<-read.csv("attribute.csv", sep=";", header=T, stringsAsFactors=F) #project info (name, position, performance) # #check last 4 rows are empty # tail(att1.raw) # att1.raw<-att1.raw[1:129,] # att2.raw<-read.csv("attribute_Final.csv", header=T, na.strings=c(999999, "#N/A")) #indi info (gener, faculty) # att3.raw<-read.csv("attribute_kwsharingFINAL.csv", header=T, na.strings=("#N/A"), stringsAsFactors=F) #kw sharing info att.raw<-read.csv("SnaUmAttributes.csv", header=T) att.all.raw<-read.csv("SnaUmAttributesAll.csv", header=T) net.raw<-read.table("edgearray_maastricht.csv", header=T, sep=";", stringsAsFactors=F, na.strings=c("Not in list","MV")) #take out empty rows. problem with excel net.raw<-net.raw[!net.raw$Ego == "",1:29] str(net.raw) #something is weird here. column 7 imported as character vector net.raw[,c(7)]<-as.numeric(net.raw[,c(7)]) # Data preparation: Attributes ------------------------------------------------ # this section is only needed when cleaning up and combining the different # attributes file. This is not needed anymore. Thus commented out. # #recode answers from text to numbers, only need to do once # att3 <- att3.raw # att3 <- apply(att3, 2, function(x){replace(x, x == "strong disagreement",1)}) # att3 <- as.data.frame(apply(att3, 2, function(x){replace(x, x == "disagreement",2)})) # att3 <- as.data.frame(apply(att3, 2, function(x){replace(x, x == "neutral",3)})) # att3 <- as.data.frame(apply(att3, 2, function(x){replace(x, x == "agreement",4)})) # att3 <- as.data.frame(apply(att3, 2, function(x){replace(x, x == "strong agreement",5)})) # att3<-apply(att3, 2, as.numeric) #the code above changes the character vector into factor because it is a mix of numbers and characters. factor is the smalled common type that allows numbers and characters. this line of code transforms it back to numbers # rownames(att3)<-att3.raw[,1] # #hist(att3)# plot answers # # #find people with no faculty number # # names(att1.raw) # att1.raw[which(is.na(att1.raw[,2])),] # att1.raw[68,2]<-6 #6 = sbe # att1.raw[93,2]<-6 # att1.raw[122,2]<-2 #FHML = 2 # # names(att2.raw) # att2.raw[which(is.na(att2.raw[,6])),] # att2.raw[c(61, 63, 81),6]<-2 # att2.raw[c(67, 72, 82),6]<-6 # # #Fix the names # att1.raw[1,1]<- "A. Duijvestijn" # att1.raw[27,1]<-"Eleonore Kuhler" # att1.raw[64,1]<- "Karen Konings" # att1.raw[73,1]<-"M van Zandvoort" # att1.raw[88,1]<-"Mirko Reithler" # att1.raw[101,1]<-"Peter Wilms van Kersbergen" # # att2.raw[,1] <- as.character(att2.raw[,1]) # att2.raw[1,1] <- "A. Duijvestijn" # att2.raw[27,1] <-"Eleonore Kuhler" # att2.raw[64,1] <- "Karen Konings" # att2.raw[73,1] <-"M van Zandvoort" # att2.raw[87,1]<-"Mirko Reithler" # att2.raw[99,1]<-"Peter Wilms van Kersbergen" # # rownames(att3)[24]<-att1.raw[64,1] # rownames(att3)[35] <- att1.raw[112,1] # rownames(att3)[51]<-att1.raw[64,1] # # #att 3 has some people filling out the questionnaire several times # #take out NA's # idx<-which(is.na(att3[,2])) # att3<-att3[-idx,] # #take out duplicates # att3<-att3[!duplicated(rownames(att3)),] # att3<-att3[order(rownames(att3)),] # rownames(att3)[5] <- att1.raw[10,1] # rownames(att3)[13] <- "Eleonore Kuhler" # rownames(att3)[16] <- att1.raw[35,1] # rownames(att3)[25] <- att1.raw[67,1] # rownames(att3)[26] <- att1.raw[70,1] # rownames(att3)[49] <- att1.raw[126,1] # # # #combine all the attribute datasets # # #matching rows to att1 # att2<-att2.raw[match(att1.raw[,1], att2.raw[,1]),] # att3.mod<-att3[match(att1.raw[,1], rownames(att3)),] # # #combine att1 and att2 with background variables # att.12<-cbind(att1.raw, att2) # write.csv(att.12, "SnaUmAttributes.csv") # # att.all<-cbind(att1.raw, att2, rownames(att3.mod), att3.mod) #combine att1, att2, att3 # att.all<-att.all[,c(1,4,13,14,2:3,5:12,15:44)] # idx<-which(is.na(att.all[,3])) #att 3 had the smallest data, could take NA's out # att.all<-att.all[-idx,] # att.all<-att.all[,c(1,5:ncol(att.all))] # write.csv(att, "SnaUmAttributesAll.csv") # Data preparation: Networks ---------------------------------------------- #create get info network by averaging getinfo and give info #give info needs to be transposed(columbs become rows and rows colums) #project 1 getinfo.raw<-net.raw[,c(1:2, 9)] getinfo.raw$dyad<-paste(getinfo.raw[,1], getinfo.raw[,2], sep="_") length(unique(getinfo.raw[,4])) #671 unique dyads giveinfo.raw<-net.raw[,c(2,1,12)] #transposed of giveinfo giveinfo.raw$dyad<-paste(giveinfo.raw[,1], giveinfo.raw[,2], sep="_") length(unique(giveinfo.raw[,4])) #671 unique dyads #sort give info.raw so that col1 and col2 match the colum names in getinfo.raw #if I sort both alpahebetically it should work getinfo.raw<-getinfo.raw[order(getinfo.raw[,4]),] giveinfo.raw<-giveinfo.raw[order(giveinfo.raw[,4]),] lapply(list(getinfo.raw, giveinfo.raw), dim) #returns dimension of both objects #check if both data frames have the same dyads table(getinfo.raw[,4] == giveinfo.raw[,4]) #true only 37 times #find the matches idx.gt<-which(getinfo.raw[,4] %in% giveinfo.raw[,4]) #563 dyads are in both data frames idx.gv<-which(giveinfo.raw[,4] %in% getinfo.raw[,4]) #subset for the dyads that are in both dataframes getinfo.raw2<-getinfo.raw[idx,] #do the same for giveinfo giveinfo.raw2<-giveinfo.raw[which(giveinfo.raw[,4] %in% getinfo.raw[,4]),] #dim: 563 - 4 #sort both alphabetically getinfo.raw2<-getinfo.raw2[order(getinfo.raw2[,4]),] giveinfo.raw2<-giveinfo.raw2[order(giveinfo.raw2[,4]),] #inspet giveinfo.raw2 manually match(giveinfo.raw2[,4], getinfo.raw2[,4]) #row 35 is twice (Anita van Gils_Jeannette Hommes) #remove 1 instance giveinfo.raw2<-giveinfo.raw2[-35,] #again subset for same dyads getinfo.raw3<-getinfo.raw2[which(getinfo.raw2[,4] %in% giveinfo.raw2[,4]),] giveinfo.raw3<-getinfo.raw2[which(giveinfo.raw2[,4] %in% giveinfo.raw2[,4]),] lapply(list(getinfo.raw3, giveinfo.raw3), dim) getinfo.raw3<-getinfo.raw3[match(getinfo.raw3[,4], giveinfo.raw3[,4]),] getinfo.raw3<-getinfo.raw3[-nrow(getinfo.raw3),] #check if dyads in same order table(getinfo.raw3[,4] == giveinfo.raw3[,4]) #finally ok #create information seeking for project 1 #composed of the average of getinfo.raw2 and giveinfo.raw2 #added to it the dyads than don't have a match. these numbers could be biased. ie1.raw<-cbind(getinfo.raw3, giveinfo.raw3) table(ie1.raw[, 4] == ie1.raw[,8])#check again if same dyads #calculate row mean and ie1<-cbind(ie1.raw[,1:2], ie1 = rowMeans(ie1.raw[,c(3,7)], na.rm=T)) #add the dyads for which I only have one sided information ie1<-rbind(ie1, setNames(getinfo.raw[-idx.gt,1:3], names(ie1)), setNames(giveinfo.raw[-idx.gv,1:3], names(ie1))) #take out those who have NA has value ie1<-ie1[!is.na(ie1[,3]),] #check for duplicates ie1$dyad<-paste(ie1[,1], ie1[,2], sep="-") table(duplicated(ie1$dyad)) #8 dubbles. inspect them idx.du<-which(duplicated(ie1$dyad)) dyad.dub<-ie1[idx.du,4] View(ie1[ie1$dyad %in% dyad.dub, ]) View(ie1[ie1[,4] == dyad.dub,]) #no difference in ie1 frequency #exception: dyad: Paul Adriaas - Wim G: 4 and 2.5. -> Take the 2.5, that is based on the average. ie1<-ie1[-idx.du,] table(duplicated(ie1$dyad)) #no duplicates. #Project 2 save.image("snaatum.RData") net.raw<-cbind(net.raw, ie_pr1, ie_pr2, ie_pr3) #RUN LOOP ON SERVER # this loops creates a valued network for every column in the network file for (i in 3:ncol(net.raw)){ # subset the netwwork file. i selects the column #mat<-as.matrix(subset(net.raw, select=c(1:2,i))) # create a network object nv<-as.network(subset(net.raw, select=c(1:2,i)), directed=T, matrix.type="edgelist",ignore.eval=F, names.eval="value") # assign edge value to the network objects nv%e%"value" <- net.raw[,i] # assign an name (identifier) for the network object nv assign(paste(colnames(net.raw)[i], "val", sep= "."),nv) } # this loops creates a binary network for every column in the network file. # The standard ERGM procedure only takes binary data for the dependent netwokr. for (i in 3:ncol(net.raw)){ # subset the netwwork file. i selects the column df<-subset(net.raw, select=c(1:2,i)) df[which(df[,3] < 4),3 ]<-0 df[which(df[,3] > 3),3 ]<-1 # dichotomize the network # in the object df, take the rows for which the 3rd column has a value above 3 # and then replace the value that is in column 3 with 0 # create a network object #does something funny n<-network(df, directed=T, matrix.type="edgelist") # assign an name (identifier) for the network object assign(colnames(net.raw)[i],n) } # # prepare mega matrix for ERGM -------------------------------------------- # # # take information sharing network # # turn ties that exists to 0 and ties that can NOT exists to 1 # net.mega_pr1<-as.sociomatrix(ie_pr1) # # convert into # net.mega_pr1[net.mega_pr1[,3] ,] <-0
7551217c4f04af5e1900964e92f33a60cae0cf71
d2de2f3709fb5a8fb0a7cd468f28a960452f170c
/includes/bernoulli.R
058b2e2bb395b4f1d854e582e61ace19870120d9
[]
no_license
spolischook/probability-theory
8c1eaef6874e76b1f5108527065ce9d83a010658
d0537c92a323923feaefcf0701a347710196403a
refs/heads/master
2020-03-29T01:04:11.710925
2018-11-12T08:08:38
2018-11-12T08:08:38
149,369,743
0
0
null
null
null
null
UTF-8
R
false
false
275
r
bernoulli.R
# Title : Formula Bernoulli # Objective : Authomate probability computitions # Created by: spolischook # Created on: 9/19/18 source("combinatorics.R") fBernoulli <- function(p, m, n) { q = 1 - p omega <- combinations(m, n) return (omega * p^m * q^(n-m)) }
7e8cdf2a9ef5d6dce980728dfd38bfd8949b6f2d
5d598bd59b2b566fd49bc1c6bd8fe0c803df32d1
/scripts/loadDataHomePower.R
6ff0c4b201626ebf59037e62466b58510af432cb
[]
no_license
caritosteph/exdata-plotting1-proyect1
846c822eb0b55d8775b2b678dd2442367c9bed34
759f8d65d2e27ff8580fdbf67c9cfa5e3c6fc20f
refs/heads/master
2021-05-29T16:25:34.742054
2015-07-12T22:12:52
2015-07-12T22:12:52
null
0
0
null
null
null
null
UTF-8
R
false
false
1,118
r
loadDataHomePower.R
#Lubridate makes it easier to work with dates #and times by providing functions to identify and parse #date-time data library(lubridate) # Save it to an new file for easy access later. if (!file.exists('houseHoldPower.rds')) { download.file(paste0('https://d396qusza40orc.cloudfront.net/', 'exdata%2Fdata%2Fhousehold_power_consumption.zip'), method='curl', destfile='raw-power-data.zip') unzip('raw-power-data.zip') # Read data into a table homePower.df <- read.table('household_power_consumption.txt', header=TRUE, sep=';', na.strings='?', colClasses=c(rep('character', 2), rep('numeric', 7))) # Convert dates and times homePower.df$Date <- dmy(homePower.df$Date) homePower.df$Time <- hms(homePower.df$Time) # Combine date and time homePower.df$date.time <-homePower.df$Date + homePower.df$Time # Save file saveRDS(homePower.df, file='houseHoldPower.rds.rds') } else { homePower.df <- readRDS('houseHoldPower.rds') }
bcfe0543fbade0c4f5736b00aa9be79da3de7be0
ad92f7dc6023fc05c51a175f93782229ef36e062
/R/internal.R
9073f874eab5282dab97f768ecf67f464b604f8f
[]
no_license
aoles/remedy
e0bf9668ac78e4d8cd6393ba192e2f41c21e2465
efd85f33733aa9295500d4ed78367c1a8144a047
refs/heads/master
2020-03-20T11:31:07.959921
2018-06-23T12:25:51
2018-06-23T12:25:51
137,405,448
0
0
null
2018-06-14T20:22:57
2018-06-14T20:22:57
null
UTF-8
R
false
false
675
r
internal.R
#' @importFrom rstudioapi getSourceEditorContext insertText add_prefix <- function(prefix) { a <- rstudioapi::getSourceEditorContext() s <- a$selection n <- length(s) # if no text is selected if (n == 1L && nchar(s[[1L]]$text) == 0L) { pos <- s[[1L]]$range$start pos[2L] <- 1 rstudioapi::insertText(location = pos, text = prefix) } else { for (i in s) rstudioapi::insertText(location = i$range$start, text = prefix) } } enclose <- function(prefix, postfix = prefix) { a <- rstudioapi::getSourceEditorContext() for (s in a$selection) rstudioapi::insertText(location = s$range, text = sprintf("%s%s%s", prefix, s$text, postfix)) }
06ba590afa3043c01f9142010eefe3fce943b6d6
e0e0b867a2caef5899addb185f5641a1ff6c23b0
/R/import.R
b7535c621552592db32e90fe9a96a4136942fec8
[ "MIT" ]
permissive
mstaniak/giosDownloader
fba1d21f13ba1590fe2b748b9c913d4e3c480f83
a8b3b220fa6174378e7c32e69c5664550965a042
refs/heads/master
2022-02-15T23:07:09.937778
2019-08-26T12:14:34
2019-08-26T12:14:34
103,324,881
0
0
null
null
null
null
UTF-8
R
false
false
7,859
r
import.R
#' Check if there are any measurement on a given stations for chosen year and polutant. #' #' @param chosenYear year of measurements #' @param chosenPolutant measured polutant #' @param station station of interest. Please provide current names of stations (values, not names of stationCodes vector) #' #' @return logical value: TRUE if the data is available, FALSE if it's not #' #' @export #' isAvailable <- function(chosenYear, chosenPolutant, station) { availability %>% dplyr::filter(year == chosenYear, polutant == chosenPolutant) %>% dplyr::select_(.dots = station) %>% unlist(use.names = FALSE) } #' Import from one GIOŚ .xlsx file. #' #' @param station chr, name of the chosen station. #' @param polutant chr, name of chosen polutant. #' @param year chr, chosen year (yyyy). #' @param path chr, path to folder containing .xlsx file or path to .xlsx file. #' @param noHours chr, 1 or 24, defaults to 1 (hourly meas.) #' @param skip int, number of rows to skip, defaults to 3. #' Do not change if unchanged GIOŚ files are used. #' @param exact lgl, TRUE if path is a path to .xlsx file. #' #' @return tibble #' importOneXLSX <- function(station, polutant, year, path = getwd(), noHours = "1", skip = 3, exact = FALSE) { fileList <- character(0) if(exact) { fileList <- path } else { fileList <- list.files(path, pattern = "*.xlsx") %>% grep(pattern = year, value = TRUE, fixed = TRUE) %>% grep(pattern = polutant, value = TRUE, fixed = TRUE) %>% grep(pattern = paste0(noHours, "g"), value = TRUE, fixed = TRUE) } emptyFrame <- tibble::tibble(measDate = character(0), station = character(0), polutant = character(0), measurement = character(0)) if(length(fileList) == 0) return(emptyFrame) srcFile <- paste(path, fileList, sep = "/") colNames <- colnames(readxl::read_excel(srcFile)) if(!sum(grepl(colNames, pattern = station))) { isOld <- sum(grepl(names(stationCodes), pattern = station)) isNew <- sum(grepl(stationCodes, pattern = station)) if(isOld) { station <- stationCodes[station] } else if(isNew) { station <- names(stationCodes)[grep(stationCodes, pattern = station)] } if(!sum(grepl(colNames, pattern = station))) { return(emptyFrame) } } tmpFrame <- tibble::as_tibble(readxl::read_excel(srcFile, skip = skip, col_names = FALSE)) colnames(tmpFrame) <- colNames colnames(tmpFrame)[1] <- "measDate" tmpFrame <- tmpFrame[, c("measDate", station)] colnames(tmpFrame)[2] <- "measurement" tmpFrame %>% dplyr::mutate(measurement = stringr::str_replace_all(measurement, ",", ".")) %>% dplyr::mutate(measurement = as.numeric(measurement), station = station, polutant = polutant) } #' Import data for one station, multiple years and polutants. #' #' @param station chr, name of the chosen station. #' @param polutants chr, names of chosen polutants. #' @param years chr, chosen years (yyyy). #' @param path chr, path to folder containing .xlsx file or path to .xlsx file. #' @param noHours chr, 1 or 24, defaults to 1 (hourly meas.) #' @param skip int, number of rows to skip, defaults to 3. #' Do not change if unchanged GIOŚ files are used. #' @param exact lgl, TRUE if path is a path to .xlsx file. #' #' @return tibble #' #' @export #' #' @examples #' \dontrun{ #' importGiosFromXLSX("DsWrocKorzA", c("NOx", "SO2"), c("2015", "2014")) #' # Default settings, .xlsx files are in the working directory. #' importGiosFromXLSX("DsWrocKorzA", c("NOx", "SO2"), c("2015", "2014"), "path-to-the-folder") #' # Importing from a different (not working) directory. #' } #' importGiosFromXLSX <- function(station, polutants = NULL, years = NULL, path = getwd(), noHours = "1", skip = 3, exact = FALSE) { if(!exact & (is.null(polutants) | is.null(years))) stop("Years and polutants must be given if exact = FALSE") if(exact & path == getwd()) stop("Paths to files must be given if exact = TRUE") tmpResult <- vector("list", length(polutants)*length(years)) for(i in polutants) { for(j in years) { tmpResult[[paste0(i, j)]] <- importOneXLSX(station, i, j, path, noHours, skip, exact) } } tmpResult %>% dplyr::bind_rows() %>% dplyr::select(station, polutant, measDate, measurement) %>% dplyr::mutate(measDate = lubridate::ymd_hms(measDate)) %>% dplyr::mutate(measDate = lubridate::round_date(measDate, unit = "hour")) %>% dplyr::filter(lubridate::year(measDate) %in% years) } #' Import from one .csv file. #' #' @inheritParams importOneXLSX #' #' @return tibble #' importOneCSV <- function(station, polutant, year, path = getwd(), noHours = "1", skip = 3, exact = FALSE) { fileList <- character(0) if(exact) { fileList <- path } else { fileList <- list.files(path, pattern = "*.csv") %>% grep(pattern = year, value = TRUE, fixed = TRUE) %>% grep(pattern = polutant, value = TRUE, fixed = TRUE) %>% grep(pattern = paste0(noHours, "g"), value = TRUE, fixed = TRUE) } emptyFrame <- tibble::tibble(measDate = character(0), station = character(0), polutant = character(0), measurement = character(0)) if(length(fileList) == 0) return(emptyFrame) srcFile <- paste(path, fileList, sep = "/") tmpFrame <- readr::read_csv(srcFile, col_names = TRUE) colnames(tmpFrame)[1] <- "measDate" tmpFrame <- tmpFrame[-(1:2), ] colNames <- colnames(tmpFrame) if(!sum(grepl(colNames, pattern = station))) { isOld <- sum(grepl(names(stationCodes), pattern = station)) isNew <- sum(grepl(stationCodes, pattern = station)) if(isOld) { station <- stationCodes[station] } else if(isNew) { station <- names(stationCodes)[grepl(x = stationCodes, pattern = station)] } if(!sum(grepl(colNames, pattern = station))) { return(emptyFrame) } } tmpFrame <- tmpFrame[, c("measDate", station)] colnames(tmpFrame)[2] <- "measurement" tmpFrame %>% dplyr::mutate(measurement = stringr::str_replace_all(measurement, ",", ".")) %>% dplyr::mutate(measurement = as.numeric(measurement), station = station, polutant = polutant) } #' Import data for one station, multiple years and polutants from .csv files. #' #' @inheritParams importGiosFromXLSX #' #' @return tibble #' #' @export #' #' @examples #' \dontrun{ #' importGiosFromXLSX("DsWrocKorzA", c("NOx", "SO2"), c("2015", "2014")) #' # Default settings, .xlsx files are in the working directory. #' importGiosFromXLSX("DsWrocKorzA", c("NOx", "SO2"), c("2015", "2014"), "path-to-the-folder") #' # Importing from a different (not working) directory. #' } #' importGiosFromCSV <- function(station, polutants = NULL, years = NULL, path = getwd(), noHours = "1", skip = 3, exact = FALSE) { if(!exact & (is.null(polutants) | is.null(years))) stop("Years and polutants must be given if exact = FALSE") if(exact & path == getwd()) stop("Paths to files must be given if exact = TRUE") tmpResult <- vector("list", length(polutants)*length(years)) for(i in polutants) { for(j in years) { tmpResult[[paste0(i, j)]] <- importOneCSV(station, i, j, path, noHours, skip, exact) } } tmpResult %>% dplyr::bind_rows() %>% dplyr::select(station, polutant, measDate, measurement) %>% dplyr::mutate(measDate = lubridate::ymd_hms(measDate)) %>% dplyr::mutate(measDate = lubridate::round_date(measDate, unit = "hour")) %>% dplyr::filter(lubridate::year(measDate) %in% years) }
47c45124b1e8efdd70468ee3683e7395f594d41e
833fef7d1324f759c7627e46851f6d863f87d07a
/work_groups/occurrence/funcao-limpeza.R
70ddd255c422db9d3bed1c0752aba9ad59caa9b2
[ "MIT" ]
permissive
LEEClab/SDMGroup
a3796145d04706bf94c4f23ec0d7d6062f00ba27
e511d46a2645523675816c345a91d596fd10965b
refs/heads/master
2020-04-06T04:06:30.723505
2018-02-26T14:43:49
2018-02-26T14:43:49
83,036,807
6
1
null
2017-06-04T03:50:39
2017-02-24T11:55:14
R
ISO-8859-1
R
false
false
7,136
r
funcao-limpeza.R
limpeza<-function(occ.tmp=data.frame(na), background.pol, remove_latlongNA0=TRUE, remove_anoNA=TRUE, remove_limiteespacial=TRUE, check.country=TRUE, check.state=TRUE, check.municipality=TRUE, check.citycoor=TRUE, check.centroid=TRUE){ ### atribuindo ID ID=1:nrow(occ.tmp) occ.tmp=cbind(ID,occ.tmp) occ.tmp.out <- occ.tmp.out.temp <- {} #remove_latlongNA0=TRUE # testar com lastInterpreted !!! if(remove_latlongNA0==TRUE){ occ.tmp.out.temp <- occ.tmp[is.na(occ.tmp$latitude),] occ.tmp <- occ.tmp[!is.na(occ.tmp$latitude),] if (NROW(occ.tmp.out.temp)>0){ remove.type = 'lat. NA' occ.tmp.out.temp <- cbind(occ.tmp.out.temp, reason=rep(remove.type,NROW(occ.tmp.out.temp))) occ.tmp.out <- rbind(occ.tmp.out,occ.tmp.out.temp)} occ.tmp.out.temp <- occ.tmp[is.na(occ.tmp$longitude),] occ.tmp <- occ.tmp[!is.na(occ.tmp$longitude),] if (NROW(occ.tmp.out.temp)>0){ remove.type = 'long. NA' occ.tmp.out.temp <- cbind(occ.tmp.out.temp, reason=rep(remove.type,NROW(occ.tmp.out.temp))) occ.tmp.out <- rbind(occ.tmp.out,occ.tmp.out.temp)} occ.tmp.out.temp <- occ.tmp[occ.tmp$latitude %in% 0,] occ.tmp <- occ.tmp[!occ.tmp$latitude %in% 0,] if (NROW(occ.tmp.out.temp)>0){ remove.type = 'lat. 0' occ.tmp.out.temp <- cbind(occ.tmp.out.temp, reason=rep(remove.type,NROW(occ.tmp.out.temp))) occ.tmp.out <- rbind(occ.tmp.out,occ.tmp.out.temp)} occ.tmp.out.temp <- occ.tmp[occ.tmp$longitude %in% 0,] occ.tmp <- occ.tmp[!occ.tmp$longitude == 0,] if (NROW(occ.tmp.out.temp)>0){ remove.type = 'long. 0' occ.tmp.out.temp <- cbind(occ.tmp.out.temp,reason=rep(remove.type,NROW(occ.tmp.out.temp))) occ.tmp.out <- rbind(occ.tmp.out,occ.tmp.out.temp)} } #remove_anoNA=TRUE if(remove_anoNA==TRUE){ occ.tmp.out.temp <- occ.tmp[is.na(occ.tmp$yearcollected),] occ.tmp <- occ.tmp[!is.na(occ.tmp$yearcollected),] # retira anos NA if (NROW(occ.tmp.out.temp)>0) {remove.type = 'Ano NA' occ.tmp.out.temp <- cbind(occ.tmp.out.temp, reason=rep(remove.type,NROW(occ.tmp.out.temp))) occ.tmp.out <- rbind(occ.tmp.out,occ.tmp.out.temp)} } #remove_limiteespacial=TRUE # testar com lastInterpreted !!! if(remove_limiteespacial==TRUE & NROW(occ.tmp)>0) { occ.tmp.points <- SpatialPointsDataFrame(cbind(occ.tmp$longitude,occ.tmp$latitude),occ.tmp) CRS.new=background.pol@proj4string proj4string(occ.tmp.points) <- CRS.new occ.tmp.points_in <- occ.tmp.points[!is.na(over(occ.tmp.points ,geometry(background.pol))),] # dentro do poligono occ.tmp.points_out <- occ.tmp.points[is.na(over(occ.tmp.points ,geometry(background.pol))),] # fora do poligono occ.tmp.out.temp <- occ.tmp.points_out@data if (NROW(occ.tmp.out.temp)>0) { remove.type = 'Out of boundary polygon' occ.tmp.out.temp <- cbind(occ.tmp.out.temp, reason=rep(remove.type,NROW(occ.tmp.out.temp))) occ.tmp.out <- rbind(occ.tmp.out,occ.tmp.out.temp)} } set4=occ.tmp.points_in@data set4$reason=NA #set4$ID=1:nrow(set4) # subir # ### 1. Check country #check.country=TRUE if(check.country==T){ PAIS=corroboracion_pais(set4,paises) set4$ok_country=rep(NA,nrow(set4)) ;set4$ok_country[PAIS[[1]]]=1 set4$suggest_country=PAIS[[3]] cat("Country concordance checked ")} # deixar msn como prints e não como janelas #### 2. check state # just working for Brasil #check.state=TRUE if(check.state==T){ #set5<-set4[which(set4$suggest_country=="Brasil"),] #2055 DEP=corroboracion_dep(set4,estado) ok_state=rep(NA,nrow(set4)) ;ok_state[DEP[[1]]]=1 set4=cbind(set4,ok_state) set4$suggest_state=DEP[[3]] cat("State concordance checked ") } ### 3. check municipality #check.municipality=T if (check.municipality==T){ A=corroboracion(set4,mpios) set4$ok_mun=NA ;set4$ok_mun[A[[1]]]=1 set4$suggest_mun=A[[3]] cat("Municipality concordance checked ","!")} ##### 4. check that the coordinate is equal to the coordinate of the city municipality #check.citycoor=T if(check.citycoor==T){ sedes_lat=which(set4$latitude %in% sedes$lat) set4$coord_mun=NA for ( i in sedes_lat){ filas=which(sedes$lat %in% set4$latitude[i]) #elige latitudes iguales a las latitudes de municipalidades respuesta=NULL for(j in filas){# revisa si para esas latitides iguales tambien las longitudes son igules resp=set4$longitude[i]==sedes$long[j] respuesta=c(respuesta,resp) } if (TRUE %in%respuesta){# si lat y longitud son igual a la de la municipalidad pone 1 de lo contrario 0 set4$coord_mun[i]=1 }else{set4$coord_mun[i]=0} } mun.ref=set4$ID[which(set4$coord_mun==1)] # identifica cuales refID tienen la misma cordenada que la municipalidad # if (length(mun.ref)!=0){ cat(paste0("IDs ",mun.ref, " have the coordenate of the municipality, Be careful","!"))} else {cat(paste0("All the coordenate are different from the municipality","!"))} } ##### 7. check that the name coordinate is equal to the centroid of the municipality ##### #check.centroid=T if(check.centroid==T){ dat=set4 CRS.new=centroid@proj4string coordinates(dat)=~longitude+latitude proj4string(dat) <- CRS.new ovm=over(dat,centroid) mun_cent=ovm[,c("Longmuncen", "Latmuncent")] set4=cbind(set4,mun_cent) dif.lon=abs(set4$longitude-set4$Longmuncen) dif.lat=abs(set4$latitude-set4$Latmuncent) dif=cbind(dif.lon,dif.lat) iqual=which(dif[,1]<0.001 & dif[,2]<0.01) set4$coord_mun_cent=NA if (length(iqual)!=0){ set4$coord_mun_cent[iqual]=1 cat("IDs", set4$ID[iqual], "have the coordinate of the centroid of the municipality") }else{ cat("All the coordenate are different from the municipality") } } # salva dados e limpeza # geo.out=set.fin[which(is.na(set.fin$ok_country)|is.na(set.fin$ok_state)|is.na(set.fin$ok_mun)|set.fin$coord_mun==1|set.fin$coord_mun_cent==1),] # geo.ok=set.fin[which(set.fin$ok_country==1 & set.fin$ok_state==1 & set.fin$ok_mun==1 & is.na(set.fin$coord_mun==1) & is.na(set.fin$coord_mun_cent)),] project="clean.results" if(NROW(occ.tmp.out)>0){ occ.tmp.out=cbind(occ.tmp.out,ok_country=NA,suggest_country=NA,ok_state=NA, suggest_state=NA,ok_mun=NA,suggest_mun=NA,coord_mun=NA,Longmuncen=NA,Latmuncent=NA,coord_mun_cent=NA) occ.tmp.out.all=rbind(occ.tmp.out, set4) save_occurrence_records(occ.tmp.out.all,'limpeza-out',project,'clean_results') return(occ.tmp.out.all) } else{ save_occurrence_records(set4,'limpeza-out',project,'clean_results') return(set4) } #save_occurrence_records(occ.tmp.out,'limpeza-out',project,'clean_out',sep='\t') #save_occurrence_records(geo.ok,'limpeza-ok',project,'clean_in',sep='\t') }
8f94b826ce2e9ab7f8f88dd6bc9b0046dfc2cab1
b50dbb928f0fec2a278f03d277af50d725ef0619
/morex_v3/pericentromere/get_pericentromere_positions.R
2fb48baa7c291f85f056eab6697da8014c631506
[]
no_license
MorrellLAB/morex_reference
2768861cf4324864cb0317e771be600cc59286e1
9bd91f1063e836604d036b8239f769c97a4e82f9
refs/heads/master
2023-06-11T13:49:38.423120
2023-06-08T16:55:12
2023-06-08T16:55:12
191,996,559
0
0
null
null
null
null
UTF-8
R
false
false
4,627
r
get_pericentromere_positions.R
#!/usr/bin/env Rscript # This script is based on Ana Poet's approach to finding the pericentromeric positions. # See: https://github.com/lilei1/9k_BOPA_SNP/blob/master/script/PositionCentromeres.R # Morex v3 # Dependencies library(gtools) library(data.table) library(tidyverse) ### User provided arguments # List of SNPs in centromeric region. Taken from supplemental table in Munoz et al 2011. pericentromere_fp <- "~/GitHub/morex_reference/morex_v2/centromere/Table6_pericentromeres_cM.txt" supp_table6_fp <- "~/GitHub/morex_reference/morex_v2/centromere/Supp_Table6-tpg2plantgenome2011080023-sup-0009.csv" # Cross reference table between POPA (Munoz et al) and BOPA SNPs crossref_fp <- "~/GitHub/morex_reference/morex_v2/centromere/Names_9K_BOPA_SNPs_CrossRef.csv" # Vcf file with BOPA SNP position in new reference vcf_fp <- "~/GitHub/morex_reference/morex_v3/50k_9k_BOPA_SNP/9k_idt95_noRescuedSNPs.vcf" # Where do we want to output our files? out_dir <- "~/GitHub/morex_reference/morex_v3/pericentromere" #----------- # Read in data pericentromere <- read.table(pericentromere_fp, header = F) consensus_map <- read.csv(supp_table6_fp, skip = 2) crossref <- read.csv(crossref_fp) vcf <- read.table(vcf_fp) # Make column names more meaningful colnames(vcf) <- c("CHROM", "POS", "ID", "REF", "ALT", "QUAL", "FILTER", "INFO") # STEP 0: Prepare data frames # Subset VCF so that we only use SNP positions that had unique BLAST hits. # Some SNPs hit in multiple places non-uniquely and can't be used, we'll remove these. # Duplicate SNP hits all contain the pattern "ALTCHR" in the info field vcf.sub <- vcf[!vcf$INFO %like% "ALTCHR", ] # Add "chr" to beginning of string to match vcf consensus_map$Chromosome.1 <- gsub(pattern="^", replacement="chr", x=consensus_map$Chromosome.1) # Pull out markers in the pericentromere region pcentromere <- data.frame(Marker = character(), Chr = character(), cM = numeric()) for (i in pericentromere$V1) { if (i == "chr1H") { next # "NA" for chr1H, so we can't figure out pericentromere here } else { start_pos <- pericentromere[pericentromere$V1 == i, 2] end_pos <- pericentromere[pericentromere$V1 == i, 3] if (start_pos == end_pos) { temp_chr <- consensus_map[consensus_map$Chromosome.1 == i, ] temp_pcent <- temp_chr[grep(start_pos, temp_chr$cM), ] } else { temp_pcent <- consensus_map[consensus_map$Chromosome.1 == i & consensus_map$cM >= start_pos & consensus_map$cM <= end_pos, ] } # Pull out only relevant columns current_chr <- data.frame(Marker = temp_pcent$Marker, Chr = temp_pcent$Chromosome.1, cM = temp_pcent$cM) # Combine with main dataframe pcentromere <- rbind(pcentromere, current_chr) } } # STEP 1: change centromere SNP names to BOPA names # Find which SNPs have BOPA names # 129 markers in pcentromere df # 7,864 markers in crossref df Shared <- intersect(pcentromere$Marker, crossref$POPA) # 182 remaining in Shared # Subset data frames cen_sh <- pcentromere[pcentromere$Marker %in% Shared, ] crossref_sh <- crossref[crossref$POPA %in% Shared, ] # Order cross ref SNPs as in CENTROMERE crossref_sh_or <- crossref_sh[match(cen_sh$Marker, crossref_sh$POPA), ] # Merge to get all info together pcent_bopa <- merge(x = cen_sh, y = crossref_sh_or, by.x = "Marker", by.y = "POPA") # STEP 2: Find position of BOPA SNPs in the new reference genome vcf_pcent <- vcf.sub[vcf.sub$ID %in% pcent_bopa$BOPA_C | vcf.sub$ID %in% pcent_bopa$BOPA, ] # 118 are present # Sort VCF by chromosome then by position vcf_pcent_ordered <- vcf_pcent[order(vcf_pcent$CHROM, vcf_pcent$POS), ] # Find max and min of pericentromere positions pcent_table <- vcf_pcent_ordered %>% group_by(CHROM) %>% summarise(min_pos = min(POS), max_pos = max(POS)) # "NA" for chr1H positions final_table <- rbind(tibble(CHROM = "chr1H", min_pos = "NA", max_pos = "NA"), pcent_table) # STEP 3: Save to output files # Save table to file write.table(final_table, paste(out_dir, "pericentromere_physPos.txt", sep = "/"), quote=F, row.names=F, col.names=F, sep="\t") # Also save vcf containing SNPs in the pericentromeric region identified here write.table(vcf_pcent_ordered, paste(out_dir, "9k_snps_pericentromere.vcf", sep = "/"), quote=F, row.names=F, col.names=F, sep="\t")
144bdd3c27ffd0cb989b41445c01c3cff88224a4
1c7a127d6f51567bde7264d768537059a2563cec
/social_network_info_spreading_simulation/network_influence_spread_simulation.R
287c485fc4e0071f5c16e7c0684b310f7010b6a5
[ "Apache-2.0" ]
permissive
Haydart/RDataScienceIntroduction
51aa1bc6599e783ced09fadc25714d0bab6af36d
8bec4be5368f4f3fbb1cea052401361ccd499e7d
refs/heads/master
2021-08-15T04:01:27.576793
2017-11-17T09:38:09
2017-11-17T09:38:09
109,005,831
0
0
null
null
null
null
UTF-8
R
false
false
3,241
r
network_influence_spread_simulation.R
library(igraph) # prepare network data raw_graph_data = read.csv(file="social_network_graph_data.csv", header=FALSE, sep=" ") graph_data <- raw_graph_data[3:nrow(raw_graph_data), 1:2] str(graph_data) raw_graph <- graph_from_data_frame(graph_data, directed=TRUE) graph <- simplify(raw_graph) # Erdos-Renyi graph graph <- erdos.renyi.game(p.or.m=.05, n=35, directed = TRUE) # check if graph has 167 vertices & 5783 edges print(vcount(graph)) print(ecount(graph)) # CONDUCT DISTRIBUTION SIMULATION random_attempts_count <- 4 iterations_within_attempt <- 10 legend_descriptions <- lapply(c(1:iterations_within_attempt), paste0, " gen") plot_file_names <- lapply(c(1:random_attempts_count), paste0, "attempt.jpg") plot_colors <- c("black", "blanchedalmond", "blue", "blueviolet", "cyan", "darkgoldenrod1", "darkolivegreen1", "firebrick1", "deeppink", "lightskyblue") for(attempt in 1:random_attempts_count) { print(paste(as.character(attempt), "attempt")) # mark all nodes as non-infected for(vertex_index in V(graph)) { V(graph)[vertex_index]$infected <- F V(graph)[vertex_index]$color <- "green" } # set a random node to be infected first_infected_index <- sample(1:vcount(graph), 1) print(random_index) # start infection from the node with highest betweenness value #first_infected_index <- V(graph)[betweenness(graph) == max(betweenness(graph))] #print(betweenness(graph)) #print(paste("The node with highest betweenness is ", first_infected_index)) V(graph)[first_infected_index]$infected <- T V(graph)[first_infected_index]$color <- plot_colors[1] # create 0-init vertex size matrix where the source-of-infection node is 1 size_matrix = matrix(0, nrow = vcount(graph), ncol = 1) size_matrix[first_infected_index, 1] <- 1 infection_sources <- V(graph)[first_infected_index] # simulate 10 iterations of infection propagation for(index in 1:iterations_within_attempt) { neighbors_to_be_infected <- list() for(infection_source in infection_sources) { neighbors_to_be_infected <- union(neighbors_to_be_infected, neighbors(graph, V(graph)[infection_source], mode = "out")) } # rule out the nodes that were infected earlier neighbors_to_be_infected <- setdiff(neighbors_to_be_infected, V(graph)[infected == T]) infection_sources <- neighbors_to_be_infected print(paste("Iteration", index, " infected ", length(infection_sources), " nodes.")) #infect neighbors of sampled nodes for(neighbor in neighbors_to_be_infected) { V(graph)[neighbor]$infected <- T V(graph)[neighbor]$color <- plot_colors[index+1] } } # plot the graph after 10 propagation iterations & save it to file jpeg(as.character(plot_file_names[attempt]), width = 1280, height = 768) plot(graph, rescale = TRUE, ylim=c(-1, 1), xlim=c(-1.1, 0.9), edge.arrow.size = .5, asp = 0, vertex.label=NA, vertex.size=2.5 + 1.5 * as.matrix(size_matrix), layout=layout.drl(graph), main = paste("Random attempt no. ", attempt)) #plot(graph, vertex.size = 10) legend(-1.15, .75, y.intersp = .75, xjust = .5, yjust = .5, legend=as.vector(legend_descriptions), bty = "n", fill = plot_colors, cex=1.5) dev.off() }
6a0f8fe691727391c29ae0c884d09f12007753e2
251ddd5c2af5268d1d1624c1804c7c94da25ca5f
/Study/Dal.R
48ecf10bad80aeb4b72c052d9c565abbb201e622
[]
no_license
mandar2812/FrugalML
5e9ca461b74df8a2c1d4e2694d6dfbbee1ab6909
bbf60a36880abd4fdd72640f1b7ccfd667f5d516
refs/heads/master
2021-01-12T07:59:23.611050
2016-12-11T23:42:01
2016-12-11T23:42:01
null
0
0
null
null
null
null
UTF-8
R
false
false
6,074
r
Dal.R
oldwd <- getwd() setwd("/home/mikhail/Desktop/GitProjects/FrugalML") files <- list.files() # features of a data set qualities <- read.csv("openml_data_qualities.csv") separate_qualities <- split(qualities, qualities$dataset) dataSize <- qualities[qualities$quality == "InstanceCount", ] dataSize <- dataSize[order(dataSize$value, decreasing = TRUE), ] # results of algorithms evaluations <- read.csv("openml_evaluations_all.csv") subEval <- evaluations[1:800, ] separate_evaluations <- split(evaluations, evaluations$task_id) # save names of data sets for further analysis allMeasures <- data.frame() # new map for storing values map <- new.env(hash=T, parent=emptyenv()) # selects data sets by size filterSize <- TRUE if (filterSize) { instanceCount <- 25 dataSize <- dataSize[dataSize$value >= instanceCount, ] } else { instanceCount <- "all" } processedSet <- 0 for (i in 1: length(separate_evaluations)) { # make a copy of set x <- as.data.frame(separate_evaluations[i]) x <- setNames(x, c("task_id", "dataset", "algo", "error_message", "accuracy", "auroc", "training_millis", "testing_millis", "confusion_matrix")) # receive name xName <- as.character(x$dataset[1]) allMeasures[i, 1] = xName if (xName %in% dataSize$dataset) { processedSet <- processedSet + 1 if (processedSet == 1) { algorithms <- x$algo algorithmsdf <- data.frame(algorithms) algorithmsdf$colour = "black" algorithmsdf$colour[1:15]="red" algorithmsdf$colour[16:30]="orange" algorithmsdf$colour[31:45]="yellow" algorithmsdf$colour[46:60]="green" algorithmsdf$colour[61:75]="blue" algorithmsdf$colour[76:90]="grey" algorithmsdf$colour[91:nrow(algorithmsdf$colour)]="violet" shortNames <- strtrim(algorithms, 5) } # change type from factor to numeric x$auroc <- as.numeric(as.character(x$auroc)) x <- x[!is.na(x$auroc), ] x$training_millis <- as.numeric(as.character(x$training_millis)) x$testing_millis <- as.numeric(as.character(x$testing_millis)) # check if training time in milliseconds and change to seconds x <- x[!is.na(x$training_millis), ] if (max(x$training_millis > 1000000)) { x$training_millis <- x$training_millis / 1000 } x <- x[x$training_millis < 100000, ] # check if testing time in milliseconds and change for seconds x <- x[!is.na(x$testing_millis), ] if (max(x$testing_millis > 1000000)) { x$testing_millis <- x$testing_millis / 1000 } x <- x[x$testing_millis < 100000, ] # caclulate and log combined time for each algorithm x$combineTime <- log(x$training_millis + x$testing_millis) x$combineTime[x$combineTime < 0] = 0 # filter columns and save AUC, training time and name of algorithm x <- data.frame(x$auroc, x$combineTime, x$algo) smallX <- setNames(x, c("AUC", "TrainTime", "Algorithm")) smallX <- smallX[order(smallX$AUC,smallX$TrainTime,decreasing=TRUE),] smallX$AUC <- smallX$AUC * -1 # calculate Pareto front paretoFront = smallX[which(!duplicated(cummin(smallX$TrainTime))),] # insert new key or update existing one for (alg in 1: nrow(paretoFront)) { algName <- as.character(paretoFront[alg, 3]) if (is.null(map[[algName]])) { map[[algName]] <- 1 } else { frequency <- map[[algName]] + 1 map[[algName]] <- frequency } } if (processedSet == 1) { if (filterSize) { png(filename = paste("plots/size", instanceCount, ".png", sep = ""), width = 6144, height = 6144) } else { png(filename= "plots/all.png", width = 6144, height = 6144) } # plot(paretoFront[,1:2], col = rainbow(103) , xlim=c(min(paretoFront$AUC), 0), ylim=c(0,max(paretoFront$TrainTime)), pch = 20, cex = 0.9) plot(paretoFront[,1:2], col = "white", xlim=c(min(paretoFront$AUC), -0.9), ylim=c(0,5), pch = 20, cex = 0.9) text(paretoFront[,1:2], labels = substr(paretoFront[, 3], 0, 4), cex = 0.7, pos = 3 ) legend("topright", legend = strtrim(algorithms, 70), col = algorithmsdf$colour, pch = 20, lty = 1, cex = 1.2, pt.cex = 1.2) } else { # points(paretoFront[,1:2], col = rainbow(103) , xlim=c(min(paretoFront$AUC), 0), ylim=c(0,max(paretoFront$TrainTime)), pch = 20, cex = 0.9) points(paretoFront[,1:2], col = "white", xlim=c(min(paretoFront$AUC), -0.9), ylim=c(0, 5), pch = 20, cex = 0.9) text(paretoFront[,1:2], labels = substr(paretoFront[, 3], 0, 4), cex = 0.7, pos = 3 ) } } } dev.off() getValue <- function(x) { map[[x]] } # find all keys in map kys <- ls(map) # create data frame algValues <- data.frame(); for (i in 1:length(kys)) { algValues[i, 1] <- kys[i] algValues[i, 2] <- as.character(getValue(kys[i])) } algValues$V2 <- as.numeric(algValues$V2) algValues <- algValues[order(algValues$V2, decreasing = TRUE), ] algValues <- setNames(algValues, c("Algorithm", "Number of times on Pareto front")) if (filterSize) { write.csv(algValues, paste("selectedSets", instanceCount, ".csv", sep = "")) } else { write.csv(algValues, "allSets.csv") } # clean map rm(map) # store in arff format for external processing writeArff <- FALSE if (writeArff) { library(foreign) write.arff(tds, "tactivity.arff", "\n", deparse(substitute(tds))) } setwd(oldwd)
9bbd1fd68ecf111e174aa16d72d8fd669fe414b9
c744f8c5401d2ca760d22d556fa2ecbebde39a56
/rkvstore/man/rkv_iterator_size.Rd
22d6663c9bffcc9a0fd82dc7b0944cbe548197eb
[ "Apache-2.0" ]
permissive
sshyran/oracle-nosql-drivers
398816164de9a7507f7363ffbc868dfd73b85761
1f421d9ac561ee7ac4b37e084b1e97ae67f562b5
refs/heads/master
2022-03-13T23:52:03.170425
2016-04-07T14:42:14
2016-04-07T14:42:14
null
0
0
null
null
null
null
UTF-8
R
false
false
887
rd
rkv_iterator_size.Rd
% File rnosql/man/rkv_iterator_size.Rd \name{rkv_iterator_size} \alias{rkv_iterator_size} \title{Return the number of elements in the store iterator.} \description{ Returns the number of items contained in the iterator. This function can only be used with iterators returned by the rkv_multiget_iterator(). The iterators returned by other functions, such as rkv_store_iterator(), are not usable by this function. } \usage{ rkv_iterator_size(iterator) } \arguments{ \item{iterator}{(kvIterator object) The iterator parameter is the handle to the iterator for which you want sizing information. } } \value{ (int)The number of items contained in the iterator. } \examples{ key <- rkv_create_key_from_uri(store, "/user/smith") iterator <- rkv_multiget_iterator(store, key) nRec <- rkv_iterator_size(iterator) rkv_release_iterator(iterator) } \seealso{ \code{\link{rkv_multiget_iterator}}. }
0987ae2fe1d037d675bde1d3a39187e11f8ee11b
9aafde089eb3d8bba05aec912e61fbd9fb84bd49
/codeml_files/newick_trees_processed/10481_1/rinput.R
a199239e0a972d14312cac940cc9b52f0145caf9
[]
no_license
DaniBoo/cyanobacteria_project
6a816bb0ccf285842b61bfd3612c176f5877a1fb
be08ff723284b0c38f9c758d3e250c664bbfbf3b
refs/heads/master
2021-01-25T05:28:00.686474
2013-03-23T15:09:39
2013-03-23T15:09:39
null
0
0
null
null
null
null
UTF-8
R
false
false
137
r
rinput.R
library(ape) testtree <- read.tree("10481_1.txt") unrooted_tr <- unroot(testtree) write.tree(unrooted_tr, file="10481_1_unrooted.txt")
8572c92b7f66ef512c5689865b1e496764cbfc43
784f76e349f2654c6c40adc6a66b0f026c649911
/man/plotBindingPotential.Rd
c0b6d4becdb3b78905dee02103f0a39d5abd9d07
[]
no_license
bjw34032/oro.pet
a3116696b06e9b6b0e7c00eef8cd332b8665c3a8
6a5d06370c90bcdc63c87ee36b116cf6a94c5858
refs/heads/master
2022-09-07T10:46:02.908052
2022-08-20T08:32:46
2022-08-20T08:32:46
32,883,375
1
1
null
2016-10-01T13:26:13
2015-03-25T18:32:46
R
UTF-8
R
false
true
2,065
rd
plotBindingPotential.Rd
% Generated by roxygen2: do not edit by hand % Please edit documentation in R/plot.R \name{plotBindingPotential} \alias{plotBindingPotential} \title{Plot Baseline Versus Post-Treatment Binding Potentials} \usage{ plotBindingPotential( base, drug, lty45 = 2, lty = 1, lwd45 = 2, lwd = 3, col45 = "darkgrey", col = "orange", pch = 1, cex = 1, xlim = range(0, base, 0.5), ylim = range(0, drug, 0.5), xlab = expression(BP[ND]^{ Base }), ylab = expression(BP[ND]^{ Drug }), ... ) } \arguments{ \item{base}{is the vector of baseline binding potentials across brain regions.} \item{drug}{is the vector of post-treatment binding potentials across brain regions.} \item{lty45}{is the line type for the 45-degree line.} \item{lty}{is the line type for the estimated regression line.} \item{lwd45}{is the line width for the 45-degree line.} \item{lwd}{is the line width for the estimated regression line.} \item{col45}{is the color for the 45-degree line.} \item{col}{is the color for the estimated regression line.} \item{pch}{is the plotting character symbol.} \item{cex}{is the size of the plotting symbol.} \item{xlim}{is the range of values on the x-axis.} \item{ylim}{is the range of values on the y-axis.} \item{xlab}{is the label on the x-axis.} \item{ylab}{is the label on the y-axis.} \item{...}{additional arguments to be passed to the \code{plot} function.} } \value{ A plot is shown, NULL is returned } \description{ Inspired by the Lassen plot (Cunningham et al., 2010) this is a straightforward graphical summary of pre-treatment versus post-treatment binding potentials for a single subject across multiple brain regions. } \details{ See the reference below. } \references{ Cunningham VJ, Rabiner EA, Slifstein M, Laruelle M (2010). Measuring drug occupancy in the absence of a reference region: the Lassen plot re-visited, \emph{Journal of Cerebral Blood Flow & Metababolism}, \bold{30}, 46-50. } \seealso{ \code{\link{par}}, \code{\link{plot}} } \author{ Brandon Whitcher \email{bwhitcher@gmail.com} }
17976ac710417f9b630c6b0b28330defdacdbea7
793429873754b0f7b44ec4f04e7f877976cb87cf
/manipulation/map/2-encoder-map.R
228d11f7946f0a45f7f2e95c267dd103fad802b7
[]
no_license
IALSA/ialsa-2018-amsterdam
c11d16451a1fd4b6d7f703371a73aba5febd76e1
7af21117757da67337ab54a95a04a092a249a51c
refs/heads/master
2021-09-04T22:10:53.310639
2018-01-22T15:41:29
2018-01-22T15:41:29
108,875,067
0
0
null
null
null
null
UTF-8
R
false
false
15,200
r
2-encoder-map.R
# The purpose of this script is to create multistate measure to be used in modelling # knitr::stitch_rmd(script="./manipulation/rename-classify.R", output="./manipulation/rename-classify.md") #These first few lines run only when the file is run in RStudio, !!NOT when an Rmd/Rnw file calls it!! rm(list=ls(all=TRUE)) #Clear the variables from previous runs. # ---- load-sources ------------------------------------------------------------ # Call `base::source()` on any repo file that defines functions needed below. Ideally, no real operations are performed. source("./scripts/functions-common.R") # used in multiple reports source("./scripts/graph-presets.R") # fonts, colors, themes source("./scripts/graph-general.R") # simple, elemental displays source("./scripts/graph-specific.R") # complex, composite displays # ---- load-packages ----------------------------------------------------------- # Attach these packages so their functions don't need to be qualified: http://r-pkgs.had.co.nz/namespace.html#search-path library(magrittr) #Pipes # Verify these packages are available on the machine, but their functions need to be qualified: http://r-pkgs.had.co.nz/namespace.html#search-path requireNamespace("ggplot2", quietly=TRUE) requireNamespace("dplyr", quietly=TRUE) #Avoid attaching dplyr, b/c its function names conflict with a lot of packages (esp base, stats, and plyr). requireNamespace("testit", quietly=TRUE) requireNamespace("msm", quietly=TRUE) # requireNamespace("plyr", quietly=TRUE) # ---- declare-globals --------------------------------------------------------- path_input <- "./data/unshared/derived/dto-1-tuned.rds" path_output <- "./data/unshared/derived/dto-2-encoded.rds" options( origin="1970-01-01" ) # ---- load-data --------------------------------------------------------------- # load the product of 0-ellis-island.R, a list object containing data and metad dto <- readRDS(path_input) # ---- inspect-data ------------------------------------------------------------- names(dto) # 1st element - raw data, as obtained from ialsa-study-curator for RUSH-MAP study # dplyr::tbl_df(dto[["raw"]]) # 2nd element - meta data, info about variables # dto[["meta"]] # 3rd element - data produced by the greeter script # dto[["greeted"]] # 4th element - data produced by the tuner script # dto[["tuned"]] # ---- tweak-data -------------------------------------------------------------- ds <- dto[["tuned"]] ds_long <- ds # ---- describe-before-encoding -------------------------------------------------------------- # if died==1, all subsequent focal_outcome==DEAD. # during debuggin/testing use only a few ids, for manipulation use all set.seed(43) ids <- sample(unique(ds$id),3) # randomly select a few ids # custom select a few ids that give different pattern of data. To be used for testing ids <- c(33027) #,33027, 50101073, 6804844, 83001827 , 56751351, 13485298, 30597867) # ---- encode-missing-states --------------------------- ## ## ## - STEP 1 - Missing values on criterion # create an object ds_miss from ds_long # x <- c(NA, 5, NA, 7) determine_censor <- function(x, is_right_censored){ ifelse(is_right_censored, -2, ifelse(is.na(x), -1, x) ) } # new way # # create file with missing information # make_ds_miss <- function( # d, # variable # ){ # d_long <- d %>% # dplyr::mutate_( # "target" = variable # ) %>% # as.data.frame() # # (N <- length(unique(d_long$id))) # sample size # subjects <- as.numeric(unique(d_long$id)) # list the ids # # for(i in 1:N){ # # for(i in unique(ds$id)){ # use this line for testing # # Get the individual data: # (dta.i <- d_long[d_long$id==subjects[i],]) # select a single individual # # (dta.i <- d_long[d_long$id==6804844,]) # select a single individual # use this line for testing # (dta.i <- as.data.frame(dta.i %>% dplyr::arrange(-age_at_visit))) # enforce sorting # (dta.i$missed_last_wave <- (cumsum(!is.na(dta.i$target))==0L)) # is the last obs missing? # (dta.i$presumed_alive <- is.na(any(dta.i$age_at_death))) # can we presume subject alive? # (dta.i$right_censored <- dta.i$missed_last_wave & dta.i$presumed_alive) # right-censored? # # dta.i$target_recoded <- determine_censor(dta.i$target, dta.i$right_censored) # use when tracing # (dta.i$target <- determine_censor(dta.i$target, dta.i$right_censored)) # replace in reality # (dta.i <- as.data.frame(dta.i %>% dplyr::arrange(age_at_visit))) # (dta.i <- dta.i %>% dplyr::select(-missed_last_wave, -right_censored )) # # Rebuild the data: # if(i==1){d_miss <- dta.i}else{d_miss <- rbind(d_miss,dta.i)} # } # # this part is not finished yet, need to make replacing the old variable # d_miss <- d_miss %>% # # drop original variable # dplyr::mutate( # mmse = target # ) %>% # dplyr::select(-target) # # return(d_miss) # } # # usage # ds_miss <- ds_long %>% make_ds_miss(variable = "mmse") # old way (N <- length(unique(ds_long$id))) # sample size subjects <- as.numeric(unique(ds_long$id)) # list the ids # ds_long_temp <- ds_long # i <- 5; for(i in 1:N){ # for(i in unique(ds$id)){ # use this line for testing # Get the individual data: # ds_long <- ds_long_temp %>% # dplyr::select(id, fu_year, age_at_visit,died, age_death, mmse) %>% # as.data.frame() (dta.i <- ds_long[ds_long$id==subjects[i],]) # select a single individual # (dta.i <- ds_long[ds_long$id==6804844,]) # select a single individual # use this line for testing (dta.i <- as.data.frame(dta.i %>% dplyr::arrange(-age_at_visit))) # enforce sorting (dta.i$missed_last_wave <- (cumsum(!is.na(dta.i$mmse))==0L)) # is the last obs missing? (dta.i$presumed_alive <- is.na(any(dta.i$age_at_death))) # can we presume subject alive? # (dta.i$presumed_alive <- is.na(any(dta.i$age_death))) # can we presume subject alive? (dta.i$right_censored <- dta.i$missed_last_wave & dta.i$presumed_alive) # right-censored? # dta.i$mmse_recoded <- determine_censor(dta.i$mmse, dta.i$right_censored) # use when tracing (dta.i$mmse <- determine_censor(dta.i$mmse, dta.i$right_censored)) # replace in reality (dta.i <- as.data.frame(dta.i %>% dplyr::arrange(age_at_visit))) (dta.i <- dta.i %>% dplyr::select(-missed_last_wave, -right_censored )) # Rebuild the data: if(i==1){ds_miss <- dta.i}else{ds_miss <- rbind(ds_miss,dta.i)} } # the created data set (ds_miss) replaces NA in mmse with cencored values (-1, -2) where appropriate ds_long %>% dplyr::filter(id %in% ids) %>% as.data.frame() %>% print() # note the updated value in mmse and the new variabe presumed_alive ds_miss %>% dplyr::filter(id %in% ids) %>% print() # ds_miss contains the mmse values corrected for missing states (-1,-2) # (e.g. if last mmse observation was NA, but we new respondent was alive) # and presumed_alive indicator # ---- encode-multi-states ------------------------------ ## ## ## - STEP 2 - Criterion into a state variable # in this step we focus on a variable that will identify the states to be modeled # a few things will happen: # 1) age_at_visit will become age (needed for passing to msm estimation routines) # 2) variable state will replace mmse (the basis for it) # 3) mmse will reappear at the end of the set # 4) a NEW ROW will be created for each subject containing the measure at death encode_multistates <- function( d, # data frame in long format outcome_name, # measure to compute live states age_name, # age at each wave age_death_name, # age of death dead_state_value # value to represent dead state ){ # declare arguments for debugging # d = ds_miss # outcome_name = "mmse";age_name = "age_at_visit";age_death_name = "age_death";dead_state_value = 4 (subjects <- sort(unique(d$id))) # list subject ids (N <- length(subjects)) # count subject ids d[,"raw_outcome"] <- d[,outcome_name] # create a copy # standardize names colnames(d)[colnames(d)==outcome_name] <- "state" # ELECT requires this name colnames(d)[colnames(d)==age_name] <- "age" # ELECT requires this name # for(i in unique(ds$id)){ # use this line for testing for(i in 1:N){ # Get the individual data: i = 1 (dta.i <- d[d$id==subjects[i],]) # (dta.i <- ds_long[ds_long$id==6804844,]) # select a single individual # use this line for testing # Encode live states dta.i$state <- ifelse( dta.i$state > 26, 1, ifelse( # healthy dta.i$state <= 26 & dta.i$state >= 23, 2, ifelse( # mild CI dta.i$state < 23 & dta.i$state >= 0, 3, dta.i$state))) # mod-sever CI # Is there a death? If so, add a record: (death <- !is.na(dta.i[,age_death_name][1])) if(death){ (record <- dta.i[1,]) (record$state <- dead_state_value) (record$age <- dta.i[,age_death_name][1]) (ddta.i <- rbind(dta.i,record)) }else{ddta.i <- dta.i} # Rebuild the data: if(i==1){dta1 <- ddta.i}else{dta1 <- rbind(dta1,ddta.i)} } # dta1[,age_death_name] <- NULL colnames(dta1)[colnames(dta1)=="raw_outcome"] <- outcome_name dta1[dta1$state == dead_state_value,outcome_name] <- NA_real_ dta1[dta1$state == dead_state_value,"fu_year"] <- NA_real_ return(dta1) } ds_ms <- encode_multistates( d = ds_miss, outcome_name = "mmse", # currently supports mmse only, todo: rework functins in tidyverse age_name = "age_at_visit", age_death_name = "age_at_death", dead_state_value = 4 ) # review ds_miss %>% dplyr::filter(id %in% 50107169) %>% print() # notice how ds_ms %>% dplyr::filter(id %in% 50107169) %>% print() # 1) age_at_visit becomes age (needed for modeling) # 2) variable state replaces mmse (which was the basis for it) # 3) mmse reappears at the end of the set # 4) most importantly, ds_ms creates an additional row for each subject # this row identifies measurement at death of which we know for sure only age # all other which refer to the time of death should be set to NA as unknown # ---- correct-values-at-death ----------------------- ## ## ## - STEP 3 - Longitudinal corrections # previous step created an additional row for each subject, measurement at death # the values in other variables carried over into the new row # this is ok with time-invariant measures (to the left of wave/fu_year) # but NOT ok with time-variant measures (to the right of wave/fu_year) # time-invariant measures must be replaced with NA in measures at the moment of death correct_values_at_death <- function( ds, # data frame in long format with multistates encoded outcome_name, # measure to correct value in dead_state_value # value that represents dead state ){ ds[ds$state == dead_state_value, outcome_name] <- NA_real_ return(ds) } ds_corrected <- ds_ms # inherits the form # manually correct values for data_at_visit ds_corrected[ds_corrected$state == 4, "date_at_visit"] <- NA # because of date format # automatically correct values for time-variant measures ds_corrected <- ds_corrected %>% correct_values_at_death("wave",4) # ds_corrected <- ds_corrected %>% correct_values_at_death("date_at_visit",4) ds_corrected <- ds_corrected %>% correct_values_at_death("dementia",4) ds_corrected <- ds_corrected %>% correct_values_at_death("cogn_global",4) ds_corrected <- ds_corrected %>% correct_values_at_death("gait",4) ds_corrected <- ds_corrected %>% correct_values_at_death("grip",4) ds_corrected <- ds_corrected %>% correct_values_at_death("htm",4) ds_corrected <- ds_corrected %>% correct_values_at_death("bmi",4) ds_corrected <- ds_corrected %>% correct_values_at_death("physact",4) ds_corrected <- ds_corrected %>% correct_values_at_death("firstobs",4) # ds_corrected <- ds_corrected %>% correct_values_at_death("income_40",4) # ds_corrected <- ds_corrected %>% correct_values_at_death("cogact_old",4) # ds_corrected <- ds_corrected %>% correct_values_at_death("socact_old",4) # ds_corrected <- ds_corrected %>% correct_values_at_death("soc_net",4) # ds_corrected <- ds_corrected %>% correct_values_at_death("social_isolation",4) # TODO: automate this step # presumed_alive is logical for the state of data at the time of access # TODO: place the presumed_alive variabe together with time invariant variables # inspect the resultant data set ds_corrected %>% dplyr::filter(id %in% ids) %>% print() # ds_corrected contains data set of long structure with respect to time # It has been augmented with the measurement at the time of death # and corrected for time-invariant and time-variant values in other variabels # ---- inspect-created-multistates ---------------------------------- # compare before and after ms encoding view_id <- function(ds1,ds2,id){ cat("Data set A:","\n") print(ds1[ds1$id==id,] %>% as.data.frame()) cat("\nData set B","\n") print(ds2[ds2$id==id,]) } # view a random person for sporadic inspections set.seed(39) ids <- sample(unique(ds_miss$id),1) # ids <- 68914513 ids <- c(33027) # trailing NA; presumed alive # ids <- c(1243685) # dead; only 4 obs; developed dementia on the last one view_id(ds_long, ds_miss, 33027) # NA -> -1 OR -2 view_id(ds_miss, ds_ms, 33027) # age_at_visit -> age; mmse -> state; + mmse view_id(ds_long, ds_ms, 33027) # all together view_id(ds_long, ds_miss, 402800) # NA -> -1 OR -2 # nothing happens for this person view_id(ds_miss, ds_ms, 402800) # age_at_visit -> age; mmse -> state; + mmse view_id(ds_ms,ds_corrected, 402800) # longitudinal corrections # to find people you might use for examples target_cohort <- ds_long %>% dplyr::filter(died==1) %>% dplyr::group_by(id) %>% dplyr::summarize(n=n()) %>% dplyr::filter(n==2) %>% dplyr::arrange(id) # ----- transitions-matrix ----------------------------- # simple frequencies of states table(ds_corrected$state) # examine transition matrix # msm::statetable.msm(state,id,ds_ms) knitr::kable(msm::statetable.msm(state,id,ds_ms)) # TODO: examine transition cases for missing states (-2 and -1) # ---- save-to-disk ------------------------------------------------------------ # Save as a compress, binary R dataset. It's no longer readable with a text editor, but it saves metadata (eg, factor information). # at this point there exist two relevant data sets: # ds_long - subset of variables focal to the project # ds_miss - missing states are encoded # ds_ms - multi states are encoded # it is useful to have access to all three while understanding/verifying encodings names(dto) dto[["encoded"]] <- list() dto[["encoded"]][["missing"]] <- ds_miss # we preserve these forms to compare later dto[["encoded"]][["multistate"]] <- ds_ms # we preserve these forms to compare later dto[["encoded"]][["corrected"]] <- ds_corrected # we preserve these forms to compare later names(dto) names(dto$encoded) saveRDS(dto, file=path_output, compress="xz")
33250697eac4fd69f2644821c7b0d9f5021d1133
4fa206129b99ef56086794c7f00a601572e2ae53
/05练习题.R
90bda574754e859c2ea0a0d9c3287c1e003986c6
[]
no_license
yuxi-xi/R-homework
8c4c3ad923876acd20c56f1fabd78a81d2a31094
49e30122591e71354e85b39c38956766e3029d00
refs/heads/main
2023-01-05T19:18:41.509915
2020-11-05T15:54:54
2020-11-05T15:54:54
308,061,434
0
0
null
null
null
null
UTF-8
R
false
false
446
r
05练习题.R
#5-1 a_list<-list(alpha=1,list(beta=2,gamma=3,delta=3),eta=NULL) length(a_list) b_list<-list(c(0,1,4,9), 16, 25, 36, 49, NULL, 64, NULL, 81, NULL) b_list #5-2 (a_data_frame<-data.frame( iris )) colMeans(a_data_frame[1:4]) #5-3 a<-data.frame( id=1 ) x<-cbind(beaver1,a) b<-data.frame( id=2 ) y<-cbind(beaver2,b) rbind(x,y)
d8b1333eae9fd80b156abfc27c2ca1102a174878
6fd39305ca3170f97c995f027deb30b4213314b1
/man/plot.SDD.Rd
0df83bf33751fc1e15e94804a099b54350c8bdcc
[]
no_license
cran/SDD
c22c74d48c8bd428f360a83ff993e03c0e73fa13
a5e4ec6e60365fd0dd0e943c91f6a0afdbbb07da
refs/heads/master
2020-05-07T12:12:04.473973
2015-02-24T00:00:00
2015-02-24T00:00:00
17,693,505
0
0
null
null
null
null
UTF-8
R
false
false
1,295
rd
plot.SDD.Rd
\name{plot.SDD} \alias{plot.SDD} \title{Plot Method for SDD objects} \description{ Plot method for objects of class \code{"SDD"}. } \usage{ \method{plot}{SDD} (x, norm = FALSE, stability = FALSE, step = 5, \dots) } \arguments{ \item{x}{a \code{SDD} object} \item{norm}{ an optional logical; if \code{TRUE}, when \code{dtype="ADF"} or when \code{dtype="ACF"}, the "normalized" p-values of the ADF are computed. } \item{stability}{an optional logical; if \code{TRUE}, when \code{dtype="RPADF"}, to evaluate the stability of the test-results a graphical representation of the confidence interval is displayed. } \item{step}{ an optional scalar; it sets the step between x-ticks in plot. Default value is 5. } \item{\dots}{graphics parameters to be passed to the plotting routines.} } \value{ No values are returned from the plot function. } \author{ Luca Bagnato, Lucio De Capitani, Angelo Mazza and Antonio Punzo } \seealso{ \code{\link{SDD-package}}, \code{\link{ADF}}, \code{\link{SMI}} } \examples{ data("SMI") res <- ADF(SMI, plot=FALSE) plot(res) } % Add one or more standard keywords, see file 'KEYWORDS' in the % R documentation directory. \keyword{ ~kwd1 } \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
d416c4e805d448d3dfae3df41e1218ffc4530c21
5150cf610a34c6c5be9b598277db1834d8fb16b4
/tests/testthat/test-HOC.R
84abb1f3224f0a6b0b91de1b38cf9438e2500066
[]
no_license
SPI-Birds/pipelines
f3ab78668e526a47bd298b0f7f4127e274a4dfd0
cb4bd41bc26d991fa54e520bb15b54333696b4cb
refs/heads/master
2023-08-16T18:15:29.835023
2023-08-09T09:51:56
2023-08-09T09:51:56
153,275,927
0
3
null
2022-12-04T14:48:00
2018-10-16T11:42:17
R
UTF-8
R
false
false
10,635
r
test-HOC.R
testthat::skip_if(!exists("data_path")) pipeline_output <- format_HOC(db = paste0(data_path, "/HOC_Hochstadt_Germany")) test_that("HOC outputs all files...", { expect_true(all("HOC" %in% pipeline_output$Brood_data$PopID)) expect_true(all("HOC" %in% pipeline_output$Capture_data$CapturePopID)) expect_true(all("HOC" %in% pipeline_output$Individual_data$PopID)) expect_true(all("HOC" %in% pipeline_output$Location_data$PopID)) }) test_that("Brood_data returns an expected outcome...", { #We want to run tests for all possible outcomes of ClutchType_calculated #Take a subset of only HOC data HOC_data <- dplyr::filter(pipeline_output$Brood_data, PopID %in% "HOC") #Test 1: Brood where clutch type = first expect_equal(subset(HOC_data, BroodID == "2016-H101-1")$Species, "PARMAJ") expect_equal(subset(HOC_data, BroodID == "2016-H101-1")$ClutchType_calculated, "first") expect_equal(subset(HOC_data, BroodID == "2016-H101-1")$LayDate, as.Date("2016-04-22")) expect_equal(subset(HOC_data, BroodID == "2016-H101-1")$ClutchSize, 7L) expect_equal(subset(HOC_data, BroodID == "2016-H101-1")$BroodSize, NA_integer_) expect_equal(subset(HOC_data, BroodID == "2016-H101-1")$NumberFledged, 0L) expect_equal(subset(HOC_data, BroodID == "2016-H101-1")$AvgChickMass, NA_real_) expect_equal(subset(HOC_data, BroodID == "2016-H101-1")$AvgTarsus, NA_real_) #Test 2: Brood where clutch type = replacement (because first is known to have failed) expect_equal(subset(HOC_data, BroodID == "2016-H111-2")$Species, "PARMAJ") expect_equal(subset(HOC_data, BroodID == "2016-H111-2")$ClutchType_calculated, "replacement") expect_equal(subset(HOC_data, BroodID == "2016-H111-2")$LayDate, as.Date("2016-05-30")) expect_equal(subset(HOC_data, BroodID == "2016-H111-2")$ClutchSize, 6) expect_equal(subset(HOC_data, BroodID == "2016-H111-2")$BroodSize, NA_integer_) expect_equal(subset(HOC_data, BroodID == "2016-H111-2")$NumberFledged, 4) expect_equal(round(subset(HOC_data, BroodID == "2016-H111-2")$AvgChickMass, 2), 13.65) expect_equal(round(subset(HOC_data, BroodID == "2016-H111-2")$AvgTarsus, 2), 18.20) #Test 3: Brood where clutch type = replacement (past the cutoff) expect_equal(subset(HOC_data, BroodID == "2017-H101-2")$Species, "PARMAJ") expect_equal(subset(HOC_data, BroodID == "2017-H101-2")$ClutchType_calculated, "replacement") expect_equal(subset(HOC_data, BroodID == "2017-H101-2")$LayDate, as.Date("2017-06-03")) expect_equal(subset(HOC_data, BroodID == "2017-H101-2")$ClutchSize, 6L) expect_equal(subset(HOC_data, BroodID == "2017-H101-2")$BroodSize, NA_integer_) expect_equal(subset(HOC_data, BroodID == "2017-H101-2")$NumberFledged, 1L) expect_equal(round(subset(HOC_data, BroodID == "2017-H101-2")$AvgChickMass, 2), 12.00) expect_equal(round(subset(HOC_data, BroodID == "2017-H101-2")$AvgTarsus, 2), 15.92) #Test 4: Brood where clutch type = second expect_equal(subset(HOC_data, BroodID == "2017-H71-2")$Species, "PARMAJ") expect_equal(subset(HOC_data, BroodID == "2017-H71-2")$ClutchType_calculated, "second") expect_equal(subset(HOC_data, BroodID == "2017-H71-2")$LayDate, as.Date("2017-05-31")) expect_equal(subset(HOC_data, BroodID == "2017-H71-2")$ClutchSize, 8L) expect_equal(subset(HOC_data, BroodID == "2017-H71-2")$BroodSize, NA_integer_) expect_equal(subset(HOC_data, BroodID == "2017-H71-2")$NumberFledged, 4L) expect_equal(round(subset(HOC_data, BroodID == "2017-H71-2")$AvgChickMass, 2), 13.75) expect_equal(round(subset(HOC_data, BroodID == "2017-H71-2")$AvgTarsus, 2), 18.55) }) test_that("Individual data returns an expected outcome...", { #We want to run a test for each sex for individuals caught as adults and chicks #Take a subset of only HOC data HOC_data <- dplyr::filter(pipeline_output$Individual_data, PopID %in% "HOC") #Test 1: First as adult expect_equal(subset(HOC_data, IndvID == "C1X0940")$Sex, "F") expect_equal(subset(HOC_data, IndvID == "C1X0940")$Species, "PARMAJ") #They should have no BroodIDLaid or Fledged because she was never caught as a chick expect_equal(subset(HOC_data, IndvID == "C1X0940")$BroodIDLaid, NA_character_) expect_equal(subset(HOC_data, IndvID == "C1X0940")$BroodIDFledged, NA_character_) #Ring age and season are as expected expect_equal(subset(HOC_data, IndvID == "C1X0940")$RingSeason, 2014L) expect_equal(subset(HOC_data, IndvID == "C1X0940")$RingAge, "adult") #Test 2: Caught first as chick expect_equal(subset(HOC_data, IndvID == "C1X0972")$Sex, NA_character_) expect_equal(subset(HOC_data, IndvID == "C1X0972")$Species, "PARMAJ") #Check that BroodIDLaid/Fledged are as expected expect_equal(subset(HOC_data, IndvID == "C1X0972")$BroodIDLaid, "2014-H61-1") expect_equal(subset(HOC_data, IndvID == "C1X0972")$BroodIDFledged, "2014-H61-1") #Ring season is as expected expect_equal(subset(HOC_data, IndvID == "C1X0972")$RingSeason, 2014) expect_equal(subset(HOC_data, IndvID == "C1X0972")$RingAge, "chick") }) test_that("Capture data returns an expected outcome...", { #Take a subset of only HOC data HOC_data <- dplyr::filter(pipeline_output$Capture_data, CapturePopID %in% "HOC") #Test 1: Individual ringed as a chick #Test there are the correct number of capture records expect_equal(nrow(subset(HOC_data, IndvID == "C3F8488")), 5) #Test that the first and 5th capture are as expected expect_equal(subset(HOC_data, IndvID == "C3F8488")$CaptureDate[1], as.Date("2014-05-18")) expect_equal(subset(HOC_data, IndvID == "C3F8488")$CaptureDate[5], as.Date("2016-06-27")) #Test that age observed is as expected on first capture #Test that age observed is as expected on 5th capture expect_equal(subset(HOC_data, IndvID == "C3F8488")$Age_observed[1], 1L) expect_equal(subset(HOC_data, IndvID == "C3F8488")$Age_observed[5], 4L) #Test that age calculated is correct on first capture and last capture expect_equal(subset(HOC_data, IndvID == "C3F8488")$Age_calculated[1], 1L) expect_equal(subset(HOC_data, IndvID == "C3F8488")$Age_calculated[5], 7L) #Test 2: Individual caught only as adult #Test it has the correct number of capture records expect_equal(nrow(subset(HOC_data, IndvID == "C3K7291")), 7) #Test that the first capture is as expected expect_equal(subset(HOC_data, IndvID == "C3K7291")$CaptureDate[1], as.Date("2016-05-09")) #Test that the 7th capture is as expected expect_equal(subset(HOC_data, IndvID == "C3K7291")$CaptureDate[7], as.Date("2019-05-08")) #Test that first and last age observed is as expected expect_equal(subset(HOC_data, IndvID == "C3K7291")$Age_observed[1], 4L) expect_equal(subset(HOC_data, IndvID == "C3K7291")$Age_observed[7], 4L) #Test that first and last age calculated is as expected expect_equal(subset(HOC_data, IndvID == "C3K7291")$Age_calculated[1], 4L) expect_equal(subset(HOC_data, IndvID == "C3K7291")$Age_calculated[7], 10L) #Test 3: Individual caught as 1st year adult pre 2019 #This individual should be treated as EURING 4 #Test it has the correct number of capture records expect_equal(nrow(subset(HOC_data, IndvID == "C3K7272")), 5) #Test that the first capture is as expected expect_equal(subset(HOC_data, IndvID == "C3K7272")$CaptureDate[1], as.Date("2016-03-08")) #Test that the 7th capture is as expected expect_equal(subset(HOC_data, IndvID == "C3K7272")$CaptureDate[5], as.Date("2019-05-09")) #Test that first and last age observed is as expected expect_equal(subset(HOC_data, IndvID == "C3K7272")$Age_observed[1], 4L) expect_equal(subset(HOC_data, IndvID == "C3K7272")$Age_observed[5], 4L) #Test that first and last age calculated is as expected expect_equal(subset(HOC_data, IndvID == "C3K7272")$Age_calculated[1], 4L) expect_equal(subset(HOC_data, IndvID == "C3K7272")$Age_calculated[5], 10L) #Test 4: Individual caught as 1st year adult post 2019 #This individual should be treated as EURING 5 #Test it has the correct number of capture records expect_equal(nrow(subset(HOC_data, IndvID == "C5E9102")), 2) #Test that the first capture is as expected expect_equal(subset(HOC_data, IndvID == "C5E9102")$CaptureDate[1], as.Date("2019-03-16")) #Test that the 7th capture is as expected expect_equal(subset(HOC_data, IndvID == "C5E9102")$CaptureDate[2], as.Date("2019-05-08")) #Test that first and last age observed is as expected expect_equal(subset(HOC_data, IndvID == "C5E9102")$Age_observed[1], 5L) expect_equal(subset(HOC_data, IndvID == "C5E9102")$Age_observed[2], 4L) #Test that first and last age calculated is as expected expect_equal(subset(HOC_data, IndvID == "C5E9102")$Age_calculated[1], 4L) expect_equal(subset(HOC_data, IndvID == "C5E9102")$Age_calculated[2], 4L) #Test 5: Individual found dead in DeadCapture ID table #Test it has the correct number of capture records expect_equal(nrow(subset(HOC_data, IndvID == "C5E8940")), 3) #Test that the first capture is as expected expect_equal(subset(HOC_data, IndvID == "C5E8940")$CaptureDate[1], as.Date("2019-05-13")) #Test that the 7th capture is as expected expect_equal(subset(HOC_data, IndvID == "C5E8940")$CaptureDate[3], as.Date("2019-05-23")) #Test that first and last age observed is as expected expect_equal(subset(HOC_data, IndvID == "C5E8940")$Age_observed[1], 1L) expect_equal(subset(HOC_data, IndvID == "C5E8940")$Age_observed[3], 1L) #Test that first and last age calculated is as expected expect_equal(subset(HOC_data, IndvID == "C5E8940")$Age_calculated[1], 1L) expect_equal(subset(HOC_data, IndvID == "C5E8940")$Age_calculated[3], 1L) }) test_that("Location_data returns an expected outcome...", { #We want to run tests for nest boxes (there are no mistnets) #Take a subset of only NIOO data HOC_data <- dplyr::filter(pipeline_output$Location_data, PopID %in% "HOC") #Test 1: Nestbox check expect_true(subset(HOC_data, LocationID == "H1")$LocationType == "NB") #Expect LocationID and NestboxID are the same expect_true(subset(HOC_data, LocationID == "H1")$NestboxID == "H1") #Expect Start and EndSeason is as expected expect_equal(subset(HOC_data, LocationID == "H1")$StartSeason, 2014L) expect_equal(subset(HOC_data, LocationID == "H1")$EndSeason, NA_integer_) #Check that LocationID is in the expected PopID expect_equal(subset(HOC_data, LocationID == "H1")$PopID, "HOC") #Check that latitude and longitude are as expected expect_equal(round(subset(HOC_data, LocationID == "H1")$Latitude, 2) %>% setNames(nm = NULL), 11.26) expect_equal(round(subset(HOC_data, LocationID == "H1")$Longitude, 2) %>% setNames(nm = NULL), 48.06) })
5f578119da67e7b4790dac1e221302ee03d74d15
a646c5a1c7ddf5598b4fc4104a5456104e6b3dc3
/plot1.R
02b6b89e1f3d058778255af51149fce65dbdd8ce
[]
no_license
andrew57jm/ExData_Plotting1
491ad35431d4af0274e07eeb3017cac2a374def1
e3ae61483f5b2860ef33d5077ea9024aa6e7132e
refs/heads/master
2021-01-19T21:18:59.749355
2016-03-07T00:35:31
2016-03-07T00:35:31
53,272,803
0
0
null
2016-03-06T19:47:34
2016-03-06T19:47:33
null
UTF-8
R
false
false
512
r
plot1.R
plot1 <- function() { library(data.table) library(dplyr) library(lubridate) # read data and filter the dates we're interested in pow <- fread("household_power_consumption.txt",na.strings=c("?")) pow <- filter(pow,Date=="1/2/2007" | Date=="2/2/2007") # open the png device png(file="plot1.png") # do the plot hist(pow$Global_active_power,col="red",main="Global Active Power", xlab = "Global Active Power (kilowatts)") dev.off() }
1529adf059d774efca80acc10dc53c362a0fb7cb
207ffc920f0c738733643ee781ca6aa4ab801e80
/metapop/metapop_r/MetaPop_Preprocessing_Summaries.R
45007098137e175bd828b3b94c59456103549d7c
[ "MIT" ]
permissive
metaGmetapop/metapop
c1db90e08996971efe97ffc914ac0282b9dadd27
0fdc3e589202e79755fc2f09343e7c8196e8ab63
refs/heads/master
2023-04-10T14:53:32.198651
2023-04-04T12:47:27
2023-04-04T12:47:27
158,002,337
33
9
null
null
null
null
UTF-8
R
false
false
10,758
r
MetaPop_Preprocessing_Summaries.R
options <- commandArgs(trailingOnly = T) #universal directory_name <- options[1] threads <- as.numeric(options[2]) library_location <- options[3] if(library_location == ""){ library_location <- .libPaths() } ref_fasta <- options[4] ref_genes <- options[5] #Component specific min_cov <- as.numeric(options[6]) min_dep <- as.numeric(options[7]) original_base_names <- options[9] original_base_names <- strsplit(original_base_names, split=",")[[1]] setwd(directory_name) original_files <- options[8] original_files <- list.files(original_files, full.names = T) #For my own dev use suppressMessages(suppressWarnings(library(doParallel, lib.loc = library_location))) suppressMessages(suppressWarnings(library(data.table, lib.loc = library_location))) suppressMessages(suppressWarnings(library(ggplot2, lib.loc = library_location))) suppressMessages(suppressWarnings(library(cowplot, lib.loc = library_location))) suppressMessages(suppressWarnings(library(bit64, lib.loc = library_location))) cov_depth <- list.files(path="MetaPop/03.Breadth_and_Depth", full.names = T, pattern="breadth_and_depth") c_d_names <- substring(cov_depth, 30, nchar(cov_depth)-22) output_bams <- list.files(path = "MetaPop/02.Filtered_Samples", full.names = T) output_bams <- output_bams[!grepl(".bai", output_bams)] cl <- makeCluster(min(threads, detectCores())) registerDoParallel(cl) orig_read_counts <- foreach(i = original_files, .combine = c) %dopar% { as.numeric(system(paste0("samtools view -c ", i), intern = T)) } stopCluster(cl) overall_summaries <- data.table(sample = original_base_names, read_counts = orig_read_counts, finish_counts = 0) cl <- makeCluster(min(threads, detectCores())) registerDoParallel(cl) finish_read_counts <- foreach(i = output_bams, .combine = c) %dopar% { as.numeric(system(paste0("samtools view -c ", i), intern = T)) } stopCluster(cl) overall_summaries$finish_counts[match(c_d_names, overall_summaries$sample)] <- finish_read_counts overall_summaries[, removed := read_counts - finish_counts] overall_summaries[, read_counts := NULL] overall_summaries <- melt.data.table(overall_summaries, id.vars = c("sample")) overall_summaries <- overall_summaries[order(overall_summaries$variable, decreasing = T),] read_filtering <- ggplot(overall_summaries, aes(x = sample, y = value, fill = variable)) + geom_bar(stat = "identity", position = "dodge") + ylab("Read Count") + xlab("Sample Origin") + scale_fill_manual("Read\nFiltering", values = c("#2ca9e1", "grey65"), labels = c("Read Kept", "Read Removed")) + coord_flip() + theme_minimal() read_filtering <- read_filtering + theme(axis.title = element_text(size = 14), axis.text = element_text(size = 14)) title <- ggdraw() + draw_label( paste0("Preprocessing Overview\nRead Filtering"), fontface = 'bold', x = 0, hjust = 0 ) + theme( # add margin on the left of the drawing canvas, # so title is aligned with left edge of first plot plot.margin = margin(0, 0, 0, 7) ) read_filtering <- plot_grid(title, read_filtering, nrow = 2, rel_heights = c(0.1, 0.9)) cl <- makeCluster(min(threads, detectCores())) registerDoParallel(cl) coverage_and_depth <- foreach(i = 1:length(cov_depth), .packages = c("data.table")) %dopar% { tmp <- fread(cov_depth[i], sep = "\t") tmp[, source := c_d_names[i]] } stopCluster(cl) #Making these legends later is a pain, doing it this way is easy. color_legend_plot <- ggplot(data = data.table(dots = c(1,2,3)), aes(x = dots, fill = factor(dots))) + geom_bar()+ scale_fill_manual(name = "Contig\nAssessment", values = alpha(c("grey65","#2ca9e1", "#FF0000"), 1), labels = c("Low Coverage", "Low Depth", "Passing Contig"))+ theme(legend.text = element_text(size = 14), legend.title = element_text(size = 14)) color_leg <- get_legend(color_legend_plot) #We have the data to plot hists of coverage/depth passing, and can show both reads passing and contigs passing. create_summary_viz <- function(depth_data, file_name, file_size, cov=min_cov, depth=min_dep, leg = color_leg){ group.colors <- c('Insufficient Coverage' = "grey65", 'Insufficient Depth' = "#2CA9E1", 'Passing Contig' = "#FF0000") depth_data$pass_level <- ifelse(depth_data$V3 >= cov, ifelse(depth_data$V4 >= depth, "Passing Contig", "Insufficient Depth"), "Insufficient Coverage") depth_data <- depth_data[order(depth_data$pass_level),] donut_TF <- depth_data donut_TF$coord <- seq(0, 1, length.out = nrow(donut_TF)) #Quirk of geom_rect; if the data is left like so, it will plot a single rectangle for each row of data around the donut. #This will result in visual artifacts, slow plotting speed, and massively oversized PDFs. donut_TF$ymax = cumsum(donut_TF$coord) donut_TF$ymin = c(0, head(donut_TF$ymax, n=-1)) maxes <- donut_TF[, max(ymax, na.rm = T), by = pass_level] donut_TF <- donut_TF[match(c("Insufficient Coverage", "Insufficient Depth", "Passing Contig")[c("Insufficient Coverage", "Insufficient Depth", "Passing Contig") %in% donut_TF$pass_level], donut_TF$pass_level),] donut_TF$ymax[match(donut_TF$pass_level, maxes$pass_level)] <- maxes$V1 donut_TF[,ymax:=-ymax] donut_TF[,ymin:=-ymin] title <- ggdraw() + draw_label( paste0(file_name, "\nDepth and Coverage of Contigs"), fontface = 'bold', x = 0, hjust = 0 ) + theme( # add margin on the left of the drawing canvas, # so title is aligned with left edge of first plot plot.margin = margin(0, 0, 0, 7) ) #Produces a contig-level summary of passage by overview_donut <- ggplot(donut_TF, aes(fill=pass_level, xmin=4.5, xmax=6, ymin=ymin, ymax=ymax))+ geom_rect()+ coord_polar(theta="y") + xlim(c(0, 6))+ theme(panel.grid=element_blank(),axis.text=element_blank(),axis.ticks=element_blank(),axis.title=element_blank(), panel.background = element_blank()) + #annotate("text", x = 0, y = 0, label = file_name, size = 3) + annotate("text", x = 0.70, y = 0, label = paste("Original Contigs:", nrow(depth_data)),size = 3) + annotate("text", x = 0.20, y = 0, label = paste("Contigs with Passing Coverage and TAD:", sum(depth_data$pass_level == "Passing Contig")),size = 3) + labs(title="")+ guides(fill=FALSE) + scale_fill_manual(values = group.colors) overview_donut <- plot_grid(NULL, overview_donut, leg, NULL, ncol = 4, rel_widths = c(.5, .85, .15, .3)) overview_donut <- plot_grid(title, overview_donut, nrow = 2, rel_heights = c(0.1, 0.9)) contig_breakdown <- ggplot(depth_data, aes(x = V3, y = V4, fill = pass_level)) + geom_point(alpha = 0.6, shape = 21, color = "grey80", size = 4) + geom_vline(xintercept = cov)+ geom_hline(yintercept = depth)+ theme_minimal() + ylab("Truncated Average Sequencing Depth")+ xlab("Percent of Genome Covered")+ scale_fill_manual(values = group.colors)+ annotate("text", x = cov, y = Inf, label = paste("Minimum Coverage:", cov, " "), vjust=1, hjust = 1) + annotate("text", x = Inf, y = depth*(19/20), label = paste("Minimum TAD:", depth), vjust = 1, hjust = 1) + expand_limits(x = 0, y = 0) contig_breakdown <- contig_breakdown + theme(legend.position = "none", #axis.line = element_line("grey80"), axis.title = element_text(size = 14), axis.text = element_text(size = 14), panel.grid = element_line(colour = "grey80")) depth_boxplots <- ggplot(depth_data, aes(y = V4, fill = pass_level))+ geom_boxplot(outlier.color = "grey80", outlier.shape = 21, outlier.size = 4) + scale_fill_manual(values = group.colors) + ylab("Truncated Average Depth")+ xlab("")+ theme_minimal()+ expand_limits(y = 0) depth_boxplots <- depth_boxplots + theme(legend.position = "none", axis.text = element_blank(), #axis.title = element_blank(), axis.line.y = element_line("grey80"), axis.ticks = element_blank(), panel.grid = element_line(colour = "grey80")) cov_boxplots <- ggplot(depth_data, aes(y = V3, fill = pass_level))+ geom_boxplot(outlier.color = "grey80", outlier.shape = 21, outlier.size = 4) + scale_fill_manual(values = group.colors) + xlab("")+ ylab("Percent of Genome Covered") + expand_limits(y = 0) + theme_minimal()+ coord_flip() cov_boxplots <- cov_boxplots + theme(legend.position = "none", axis.text = element_blank(), #axis.title = element_blank(), axis.line.x = element_line("grey80"), axis.ticks = element_blank(), panel.grid = element_line(colour = "grey80")) c_d_plot <- plot_grid(cov_boxplots, NULL, contig_breakdown, depth_boxplots, ncol = 2, align = "hv", rel_widths = c(3, 1), rel_heights = c(1, 3), axis = "xy") legend_plot <- plot_grid(NULL, leg, NULL, NULL, ncol = 2, rel_widths = c(3, 1), rel_heights = c(1, 4)) c_d_plot <- ggdraw(c_d_plot) + draw_plot(legend_plot) c_d_plot <- plot_grid( title, c_d_plot, ncol = 1, # rel_heights values control vertical title margins rel_heights = c(0.1, 0.9) ) return(list(overview_donut, c_d_plot)) } pdf("MetaPop/12.Visualizations/preprocessing_summaries.pdf", width = 16, height = 9) print(read_filtering) for(i in 1:length(coverage_and_depth)){ tmp <- create_summary_viz(coverage_and_depth[[i]], c_d_names[i], file.size(cov_depth[i])) print(tmp[[1]]) print(tmp[[2]]) } dev.off()
fbc5d539c1f30239140306113e6ff9bc179b8247
b28f74d681bb5dfbf34549c82a8c932f77c1b0a8
/man/pep_to_prn.Rd
b8711090b3ba167d52d4b9a1b2de48eaf53d79ec
[ "MIT" ]
permissive
sailfish009/proteoQ
b07e179e9fe27a90fd76cde2ed7caa55e793e9d6
e6a4fe79a21f9a9106a35d78c2ce42d59e9d82e2
refs/heads/master
2022-12-25T20:06:40.340740
2020-10-15T20:18:14
2020-10-15T20:18:14
null
0
0
null
null
null
null
UTF-8
R
false
true
2,060
rd
pep_to_prn.Rd
% Generated by roxygen2: do not edit by hand % Please edit documentation in R/peptable.R \name{pep_to_prn} \alias{pep_to_prn} \title{Helper of Pep2Prn} \usage{ pep_to_prn(id, method_pep_prn, use_unique_pep, gn_rollup, ...) } \arguments{ \item{id}{Character string; one of \code{pep_seq}, \code{pep_seq_mod}, \code{prot_acc} and \code{gene}.} \item{method_pep_prn}{Character string; the method to summarize the \code{log2FC} and the \code{intensity} of peptides by protein entries. The descriptive statistics includes \code{c("mean", "median", "weighted_mean", "top_3_mean", "lfq_max", "lfq_top_2_sum", "lfq_top_3_sum", "lfq_all")} with \code{median} being the default for TMT and \code{lfq_top_3_sum} for LFQ. The representative \code{log10-intensity} of reporter (or LFQ) ions at the peptide levels will be the weight when summarizing \code{log2FC} with various \code{"top_n"} statistics or \code{"weighted_mean"}.} \item{use_unique_pep}{Logical. If TRUE, only entries that are \code{TRUE} or equal to \code{1} under the column \code{pep_isunique} in \code{Peptide.txt} will be used, for summarizing the \code{log2FC} and the \code{intensity} of peptides into protein values. The default is to use unique peptides only. For \code{MaxQuant} data, the levels of uniqueness are according to the \code{pep_unique_by} in \code{\link{normPSM}}. The argument currently do nothing to \code{Spectrum Mill} data where both unique and shared peptides will be kept.} \item{gn_rollup}{Logical; if TRUE, rolls up protein accessions to gene names.} \item{...}{\code{filter_}: Variable argument statements for the filtration of data rows. Each statement contains a list of logical expression(s). The \code{lhs} needs to start with \code{filter_}. The logical condition(s) at the \code{rhs} needs to be enclosed in \code{exprs} with round parenthesis. For example, \code{pep_len} is a column key in \code{Peptide.txt}. The statement of \code{filter_peps_at = exprs(pep_len <= 50)} will remove peptide entries with \code{pep_len > 50}.} } \description{ Helper of Pep2Prn }
f6bc00ad9e90bf4377361ea1bbda86ee7ed67dbd
9c2402aaf87d352954fd132e09e75b023354ee76
/10번.R
eb6706faf0fe3e3454d46b8e699c321d1a5e59d8
[]
no_license
tlfzgjadyd/R-Hadoop
70ff542119763e2129ddc9a0410baed3e2ddf23b
06e29d22d1cd61311f8bcb412bf19cb491ec03f8
refs/heads/dev
2022-12-29T17:43:21.380912
2020-10-15T09:01:14
2020-10-15T09:01:14
302,491,125
0
0
null
2020-10-15T09:01:15
2020-10-09T00:17:36
R
UTF-8
R
false
false
68
r
10번.R
x <- c(1:4) A <- matrix(x, 2, 2) B <- matrix(x, 2, 2, byrow = T) A B
6974a7be37de6a01961448dcb2fbc7984a34b6ad
fe1d921f0e087f5c5d58afa07511d79b114facfa
/inst/extdata/transition-probs/F3.R
abcab0d9c885fd30a98562ef6d0892c44e263b53
[ "Apache-2.0" ]
permissive
Dordt-Statistics-Research/LaByRInth
2acf9651a5a14db832ea975a2a44cd48c625f693
ff44da887171586fc5ac40cd4f6ba701bc6d598f
refs/heads/master
2021-01-01T04:53:07.756202
2018-10-19T01:06:51
2018-10-19T01:06:51
97,264,302
0
1
null
2017-08-04T19:52:09
2017-07-14T18:56:28
null
UTF-8
R
false
false
183,163
r
F3.R
## Copyright 2018 Jason Vander Woude ## ## Licensed under the Apache License, Version 2.0 (the "License"); ## you may not use this file except in compliance with the License. ## You may obtain a copy of the License at ## ## http://www.apache.org/licenses/LICENSE-2.0 ## ## Unless required by applicable law or agreed to in writing, software ## distributed under the License is distributed on an "AS IS" BASIS, ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## See the License for the specific language governing permissions and ## limitations under the License. ## This file is auto-generated by multi-model-symbolics.sage for F3 ## generation plants. To generate a similar file for any generation of ## recombinant inbred line (RIL) plants, load this SAGE file in a SAGE ## interpreter and run the function 'parse_probs_to_R' with the single ## parameter being the generation of the plants where a value of 2 corresponds ## to F2, 3 corresponds to F3, etc. Running the function will print the required ## text for the R file to the console where it must be copied and pasted into a ## file called 'F{generation}.R' and saved in the appropriate directory. ## To download SAGE, visit https://www.sagemath.org/download.html ## There is a seperate function for each file because at runtime, only one ## function will be needed, so there is no need to source to code for all other ## generations site.pair.transition.probs <- list( list( function(r) { matrix(c( 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 11/16, 1/16, 1/16, 3/16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 11/16, 1/16, 1/16, 3/16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 3/8, 1/8, 1/8, 3/8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 11/16, 1/16, 1/16, 3/16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 7/16, 1/16, 1/16, 7/16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 7/16, 1/16, 1/16, 7/16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 3/16, 1/16, 1/16, 11/16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 11/16, 1/16, 1/16, 3/16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 7/16, 1/16, 1/16, 7/16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 7/16, 1/16, 1/16, 7/16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 3/16, 1/16, 1/16, 11/16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 3/8, 1/8, 1/8, 3/8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 3/16, 1/16, 1/16, 11/16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 3/16, 1/16, 1/16, 11/16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) } ), list( function(r) { matrix(c( 11/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 3/16, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( -1/8*r^5 + 3/8*r^4 - 5/8*r^3 + 3/4*r^2 - 11/16*r + 11/16, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 3/16*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 3/16*r, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 5/16*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 3/16*r, -1/8*r^5 + 3/8*r^4 - 5/8*r^3 + 5/8*r^2 - 5/16*r + 1/16, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 1/8*r^2, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 3/16*r, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 1/8*r^2, -1/8*r^5 + 3/8*r^4 - 5/8*r^3 + 5/8*r^2 - 5/16*r + 1/16, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 5/16*r, 1/8*r^5 -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^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 1/4*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 1/4*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3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4 + 1/2*r^3 - 3/8*r^2 + 3/16*r, -1/8*r^5 + 3/8*r^4 - 5/8*r^3 + 3/4*r^2 - 11/16*r + 11/16, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 1/8*r^2, -1/8*r^5 + 3/8*r^4 - 5/8*r^3 + 5/8*r^2 - 5/16*r + 1/16, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 3/16*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, -1/8*r^5 + 3/8*r^4 - 5/8*r^3 + 5/8*r^2 - 5/16*r + 1/16, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 1/8*r^2, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 3/16*r, -1/8*r^5 + 3/8*r^4 - 5/8*r^3 + 3/4*r^2 - 9/16*r + 3/16, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 5/16*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 11/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 3/16 ), nrow=4, ncol=4, byrow=T) } ), list( function(r) { matrix(c( 11/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 3/16, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/8*r^5 - 1/4*r^4 + 3/8*r^3 - 3/8*r^2 + 5/16*r + 3/8, -1/8*r^5 + 1/4*r^4 - 1/4*r^3 + 1/8*r^2 - 1/16*r + 1/16, -1/8*r^5 + 1/4*r^4 - 1/4*r^3 + 1/8*r^2 - 1/16*r + 1/16, 1/8*r^5 - 1/4*r^4 +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 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 1/4*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 1/4*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/8*r^4 - 1/4*r^3 + 1/8*r^2 + 1/8*r + 3/16, -1/8*r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 + 1/8*r^3 + 1/8*r^2 - 3/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 11/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 3/16 ), nrow=4, ncol=4, byrow=T) } ), list( function(r) { matrix(c( 3/8, 0, 0, 0, 1/8, 0, 0, 0, 1/8, 0, 0, 0, 3/8, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/8*r^4 - 1/4*r^3 + 3/8*r^2 - 3/8*r + 3/8, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 1/8*r^2 + 1/8*r, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/16, 1/8*r^4 - 1/4*r^3 + 3/8*r^2 - 1/4*r + 1/16, 1/8*r^4 - 1/4*r^3 + 1/8*r^2, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/16, 1/8*r^4 - 1/4*r^3 + 1/8*r^2, 1/8*r^4 - 1/4*r^3 + 3/8*r^2 - 1/4*r + 1/16, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 1/8*r^2 + 1/8*r + 3/16, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 3/8*r^2 - 3/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/8*r^4 - 1/4*r^3 + 3/8*r^2 - 3/8*r + 3/8, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r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/4*r^3 + 3/8*r^2 - 3/8*r + 3/16, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 1/8*r^2 + 1/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 3/8, 0, 0, 0, 1/8, 0, 0, 0, 1/8, 0, 0, 0, 3/8 ), nrow=4, ncol=4, byrow=T) } ), list( function(r) { matrix(c( 11/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 3/16, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 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matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3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*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 1/4*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 1/4*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 5/16*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3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/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 1/8*r^2, 1/8*r^4 - 1/4*r^3 + 3/8*r^2 - 1/4*r + 1/16, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 1/8*r^2 + 1/8*r, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 3/8*r^2 - 3/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 11/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 3/16 ), nrow=4, ncol=4, byrow=T) } ), list( function(r) { matrix(c( 7/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 7/16, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 1/4*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/8*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 + r^3 - 9/16*r^2 + 3/16*r, -1/4*r^6 + 3/4*r^5 - 9/8*r^4 + r^3 - 9/16*r^2 + 3/16*r, 1/4*r^6 - 3/4*r^5 + 9/8*r^4 - 5/4*r^3 + 19/16*r^2 - 7/8*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 1/4*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 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*r, 1/4*r^6 - 3/4*r^5 + 9/8*r^4 - 3/4*r^3 - 1/16*r^2 + 1/2*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 3/16, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/32, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/32, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 3/16, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 1/32, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 1/32, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 1/32, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 1/32, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 3/16, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/32, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/32, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 7/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 7/16 ), nrow=4, ncol=4, byrow=T) } ), list( function(r) { matrix(c( 7/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 7/16, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 1/4*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) },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 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 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6 - 3/4*r^5 + 9/8*r^4 - 5/4*r^3 + 19/16*r^2 - 7/8*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r,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 - 7/8*r + 7/16, -1/4*r^6 + 3/4*r^5 - 9/8*r^4 + r^3 - 9/16*r^2 + 3/16*r, -1/4*r^6 + 3/4*r^5 - 9/8*r^4 + r^3 - 9/16*r^2 + 3/16*r, 1/4*r^6 - 3/4*r^5 + 9/8*r^4 - 3/4*r^3 - 1/16*r^2 + 1/2*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 3/16, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/32, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/32, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 3/16, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 1/32, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 1/32, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 1/32, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 1/32, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 3/16, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/32, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/32, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 7/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 7/16 ), nrow=4, ncol=4, byrow=T) } ), list( function(r) { matrix(c( 3/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 11/16, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32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7/16*r^2 - 7/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( -1/8*r^5 + 3/8*r^4 - 5/8*r^3 + 3/4*r^2 - 9/16*r + 3/16, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 5/16*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, -1/8*r^5 + 3/8*r^4 - 5/8*r^3 + 5/8*r^2 - 5/16*r + 1/16, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 1/8*r^2, 1/8*r^5 - 3/8*r^4 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/16*r + 11/16, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 3/16*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 3/16*r, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 5/16*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4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*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 3/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 11/16 ), nrow=4, ncol=4, byrow=T) } ), list( function(r) { matrix(c( 11/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 3/16, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/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*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 1/4*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1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r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/8*r^5 - 1/4*r^4 + 1/8*r^3 + 1/8*r^2 - 3/16*r + 3/16, -1/8*r^5 + 1/4*r^4 - 1/4*r^3 + 1/8*r^2 - 1/16*r + 1/16, -1/8*r^5 + 1/4*r^4 - 1/4*r^3 + 1/8*r^2 - 1/16*r + 1/16, 1/8*r^5 - 1/4*r^4 + 3/8*r^3 - 3/8*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r^4 - 1/4*r^3 + 1/8*r^2 + 1/8*r, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 3/8*r^2 - 3/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 11/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 3/16 ), nrow=4, ncol=4, byrow=T) } ), list( function(r) { matrix(c( 7/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 7/16, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 1/4*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 3/16, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/32, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/32, 1/8*r^4 - 1/4*r^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 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 1/4*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/4*r^6 - 3/4*r^5 + 9/8*r^4 - 3/4*r^3 - 1/16*r^2 + 1/2*r, -1/4*r^6 + 3/4*r^5 - 9/8*r^4 + r^3 - 9/16*r^2 + 3/16*r, -1/4*r^6 + 3/4*r^5 - 9/8*r^4 + r^3 - 9/16*r^2 + 3/16*r, 1/4*r^6 - 3/4*r^5 + 9/8*r^4 - 5/4*r^3 + 19/16*r^2 - 7/8*r + 7/16, -1/4*r^6 + 3/4*r^5 - 9/8*r^4 + r^3 - 9/16*r^2 + 3/16*r, 1/4*r^6 - 3/4*r^5 + 9/8*r^4 - 3/4*r^3 + 3/16*r^2, 1/4*r^6 - 3/4*r^5 + 9/8*r^4 - 5/4*r^3 + 15/16*r^2 - 3/8*r + 1/16, -1/4*r^6 + 3/4*r^5 - 9/8*r^4 + r^3 - 9/16*r^2 + 3/16*r, -1/4*r^6 + 3/4*r^5 - 9/8*r^4 + r^3 - 9/16*r^2 + 3/16*r, 1/4*r^6 - 3/4*r^5 + 9/8*r^4 - 5/4*r^3 + 15/16*r^2 - 3/8*r + 1/16, 1/4*r^6 - 3/4*r^5 + 9/8*r^4 - 3/4*r^3 + 3/16*r^2, -1/4*r^6 + 3/4*r^5 - 9/8*r^4 + r^3 - 9/16*r^2 + 3/16*r, 1/4*r^6 - 3/4*r^5 + 9/8*r^4 - 5/4*r^3 + 19/16*r^2 - 7/8*r + 7/16, -1/4*r^6 + 3/4*r^5 - 9/8*r^4 + r^3 - 9/16*r^2 + 3/16*r, -1/4*r^6 + 3/4*r^5 - 9/8*r^4 + r^3 - 9/16*r^2 + 3/16*r, 1/4*r^6 - 3/4*r^5 + 9/8*r^4 - 3/4*r^3 - 1/16*r^2 + 1/2*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 5/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/16*r^2 - 7/8*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16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r + 1/32, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 3/16, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/32, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/32, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 7/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 7/16 ), nrow=4, ncol=4, byrow=T) } ), list( function(r) { matrix(c( 7/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 7/16, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 1/4*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 3/16, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/32, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/32, 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/16*r^2 + 1/2*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*r^6 + 3/4*r^5 - r^4 + 3/4*r^3 - 5/16*r^2 + 1/16*r + 3/16, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, 1/4*r^6 - 3/4*r^5 + r^4 - 3/4*r^3 + 5/16*r^2 - 1/16*r + 1/32, -1/4*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+ 1/4*r^2 - 1/8*r + 1/32, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 3/16, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/32, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/32, 1/8*r^4 - 1/4*r^3 + 1/4*r^2 - 1/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 7/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 7/16 ), nrow=4, ncol=4, byrow=T) } ), list( function(r) { matrix(c( 3/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 11/16, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/8*r^4 - 1/4*r^3 + 3/8*r^2 - 3/8*r + 3/16, -1/8*r^4 + 1/4*r^3 -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3 + 5/8*r^2 - 5/16*r + 1/16, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 1/8*r^2, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, -1/8*r^5 + 3/8*r^4 - 5/8*r^3 + 3/4*r^2 - 11/16*r + 11/16, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 3/16*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 3/16*r, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 5/16*r ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16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row=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r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, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 3/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 11/16 ), nrow=4, ncol=4, byrow=T) } ), list( function(r) { matrix(c( 3/8,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T) }, function(r) { matrix(c( 0, 0, 0, 3/8, 0, 0, 0, 1/8, 0, 0, 0, 1/8, 0, 0, 0, 3/8 ), nrow=4, ncol=4, byrow=T) } ), list( function(r) { matrix(c( 3/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 11/16, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/8*r^5 - 1/4*r^4 + 1/8*r^3 + 1/8*r^2 - 3/16*r + 3/16, -1/8*r^5 + 1/4*r^4 - 1/4*r^3 + 1/8*r^2, -1/8*r^5 + 1/4*r^4 - 1/4*r^3 + 1/8*r^2, 1/8*r^5 - 1/4*r^4 + 3/8*r^3 - 3/8*r^2 + 3/16*r, -1/8*r^5 + 1/4*r^4 - 1/4*r^3 + 1/8*r^2 - 1/16*r + 1/16, 1/8*r^5 - 1/4*r^4 + 1/8*r^3, 1/8*r^5 - 1/4*r^4 + 3/8*r^3 - 1/4*r^2 + 1/16*r, -1/8*r^5 + 1/4*r^4 - 1/4*r^3 + 1/8*r^2, -1/8*r^5 + 1/4*r^4 - 1/4*r^3 + 1/8*r^2 - 1/16*r + 1/16, 1/8*r^5 - 1/4*r^4 + 3/8*r^3 - 1/4*r^2 + 1/16*r, 1/8*r^5 - 1/4*r^4 + 1/8*r^3, -1/8*r^5 + 1/4*r^4 - 1/4*r^3 + 1/8*r^2, 1/8*r^5 - 1/4*r^4 + 3/8*r^3 - 3/8*r^2 + 5/16*r + 3/8, -1/8*r^5 + 1/4*r^4 - 1/4*r^3 + 1/8*r^2 - 1/16*r + 1/16, -1/8*r^5 + 1/4*r^4 - 1/4*r^3 + 1/8*r^2 - 1/16*r + 1/16, 1/8*r^5 - 1/4*r^4 + 1/8*r^3 + 1/8*r^2 - 3/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 5/16*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 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*r, 1/8*r^4 - 1/4*r^3 + 3/8*r^2 - 1/4*r + 1/16, 1/8*r^4 - 1/4*r^3 + 1/8*r^2, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 3/8*r^2 - 3/8*r + 3/8, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/16, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r + 1/16, 1/8*r^4 - 1/4*r^3 + 1/8*r^2 + 1/8*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/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r^4 - 1/4*r^3 + 1/8*r^2 - 1/16*r + 1/16, -1/8*r^5 + 1/4*r^4 - 1/4*r^3 + 1/8*r^2, 1/8*r^5 - 1/4*r^4 + 1/8*r^3, 1/8*r^5 - 1/4*r^4 + 3/8*r^3 - 1/4*r^2 + 1/16*r, -1/8*r^5 + 1/4*r^4 - 1/4*r^3 + 1/8*r^2 - 1/16*r + 1/16, 1/8*r^5 - 1/4*r^4 + 1/8*r^3 + 1/8*r^2 - 3/16*r + 3/16, -1/8*r^5 + 1/4*r^4 - 1/4*r^3 + 1/8*r^2 - 1/16*r + 1/16, -1/8*r^5 + 1/4*r^4 - 1/4*r^3 + 1/8*r^2 - 1/16*r + 1/16, 1/8*r^5 - 1/4*r^4 + 3/8*r^3 - 3/8*r^2 + 5/16*r + 3/8 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 3/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 11/16 ), nrow=4, ncol=4, byrow=T) } ), list( function(r) { matrix(c( 3/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 11/16, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 5/16*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, -1/8*r^5 + 3/8*r^4 - 5/8*r^3 + 3/4*r^2 - 9/16*r + 3/16, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 3/16*r, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 1/8*r^2, -1/8*r^5 + 3/8*r^4 - 5/8*r^3 + 5/8*r^2 - 5/16*r + 1/16, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 -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^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 3/8*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 3/16*r^2 + 1/4*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/32*r + 1/32, 1/16*r^4 - 1/16*r^2 + 1/32*r, 1/16*r^4 - 1/4*r^3 + 5/16*r^2 - 5/32*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 3/32*r, 1/16*r^4 - 3/16*r^2 + 5/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/4*r^3 + 7/16*r^2 - 7/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 1/8*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 3/16*r^2 - 3/16*r + 3/16, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, -1/16*r^4 + 1/8*r^3 - 1/8*r^2 + 1/16*r + 1/32, 1/16*r^4 - 1/8*r^3 + 1/16*r^2 + 1/16*r + 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 1/8*r^4 - 1/4*r^3 + 3/8*r^2 - 3/8*r + 3/16, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 1/8*r^2 + 1/8*r, -1/8*r^4 + 1/4*r^3 - 1/4*r^2 + 1/8*r, 1/8*r^4 - 1/4*r^3 + 3/8*r^2 - 1/4*r + 1/16, 1/8*r^4 - 1/4*r^3 + 1/8*r^2, -1/8*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1/8*r^2 - 1/16*r + 1/16, 1/8*r^5 - 1/4*r^4 + 3/8*r^3 - 3/8*r^2 + 5/16*r + 3/8 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( -1/8*r^5 + 3/8*r^4 - 5/8*r^3 + 3/4*r^2 - 9/16*r + 3/16, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 5/16*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, -1/8*r^5 + 3/8*r^4 - 5/8*r^3 + 5/8*r^2 - 5/16*r + 1/16, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 1/8*r^2, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 3/16*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 1/8*r, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 1/8*r^2, -1/8*r^5 + 3/8*r^4 - 5/8*r^3 + 5/8*r^2 - 5/16*r + 1/16, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 3/16*r, -1/8*r^5 + 3/8*r^4 - 3/8*r^3 + 5/16*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 3/16*r, 1/8*r^5 - 3/8*r^4 + 1/2*r^3 - 3/8*r^2 + 3/16*r, -1/8*r^5 + 3/8*r^4 - 5/8*r^3 + 3/4*r^2 - 11/16*r + 11/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 3/16, 0, 0, 0, 1/16, 0, 0, 0, 1/16, 0, 0, 0, 11/16 ), nrow=4, ncol=4, byrow=T) } ), list( function(r) { matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11/16, 1/16, 1/16, 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11/16, 1/16, 1/16, 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3/8, 1/8, 1/8, 3/8 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11/16, 1/16, 1/16, 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7/16, 1/16, 1/16, 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7/16, 1/16, 1/16, 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3/16, 1/16, 1/16, 11/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11/16, 1/16, 1/16, 3/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7/16, 1/16, 1/16, 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7/16, 1/16, 1/16, 7/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3/16, 1/16, 1/16, 11/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3/8, 1/8, 1/8, 3/8 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3/16, 1/16, 1/16, 11/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3/16, 1/16, 1/16, 11/16 ), nrow=4, ncol=4, byrow=T) }, function(r) { matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ), nrow=4, ncol=4, byrow=T) } ) )
b4fd727fef99e41d0ff844861abf7e588af02142
446e8ed6dc4b6f01a62e0944bcafc1e7bdde1652
/man/show_themes.Rd
4c4db8d6b933c26c31b33ac427ebefb73a630dc8
[ "MIT" ]
permissive
jlopezper/essurvey
2f24d269334fde904a2ed4b76ce771e98c85b252
1bd88d41ca714ad5ad5d8ac61b71566142d8322e
refs/heads/master
2020-04-27T13:19:53.757688
2019-03-08T13:24:39
2019-03-08T13:24:39
174,365,791
0
0
null
2019-03-07T14:59:43
2019-03-07T14:59:43
null
UTF-8
R
false
true
625
rd
show_themes.Rd
% Generated by roxygen2: do not edit by hand % Please edit documentation in R/show_funs.R \name{show_themes} \alias{show_themes} \title{Return available themes in the European Social Survey} \usage{ show_themes() } \value{ character vector with available themes } \description{ This function returns the available themes in the European Social Survey. However, contrary to \code{\link{show_countries}} and \code{\link{show_country_rounds}}, themes can not be downloaded as separate datasets. This and \code{\link{show_theme_rounds}} serve purely for informative purposes. } \examples{ show_themes() }
2c9be175fdaada0053952eecaaa0ac2426a37348
83f7cbd1728e1756ce26f249f23e562143de6b5c
/SimulationMain.Revisions.wPCs.vs1.dev.R
e7c877ef589a9f58057fc01fb7d741b274065744
[]
no_license
mturchin20/InterPath
765135535783c63122ba5d006ba671ac1cb4448f
4b07e1377aa6bfd14cda7ed5e1ffb02ce52bd494
refs/heads/master
2021-09-08T23:55:41.264911
2021-09-06T23:28:53
2021-09-06T23:28:53
136,239,536
0
0
null
null
null
null
UTF-8
R
false
false
5,887
r
SimulationMain.Revisions.wPCs.vs1.dev.R
#library("MAPITR") library("devtools") devtools::load_all("/users/mturchin/LabMisc/RamachandranLab/MAPITR") args <- commandArgs() #print(args) X.File <- args[6] Genes.File <- args[7] Covars.File <- args[8] Genes.Analysis.File <- args[9] Output1.File <- args[10] seed.value <- as.numeric(as.character(args[11])) n.datasets <- as.numeric(as.character(args[12])) pve <- as.numeric(as.character(args[13])) rho <- as.numeric(as.character(args[14])) pc.var <- as.numeric(as.character(args[15])) #ngenes <- as.numeric(as.character(args[16])) nsnps <- as.numeric(as.character(args[16])) ncausal1 <- as.numeric(as.character(args[17])) ncausal2 <- as.numeric(as.character(args[18])) #ncausal3 <- args[19] set.seed(seed.value) X <- as.matrix(read.table(X.File, header=T)); Genes <- read.table(Genes.File, header=F); Covars <- read.table(Covars.File, header=T); Genes.Analysis <- read.table(Genes.Analysis.File, header=F); PCs <- as.matrix(Covars[,(ncol(Covars)-9):ncol(Covars)]); Xmean=apply(X, 2, mean); Xsd=apply(X, 2, sd); X=t((t(X)-Xmean)/Xsd) ind = nrow(X); nsnp = ncol(X) ### Define the Simulation Parameters ### #n.datasets = 1 #Total Number of Simulations #pve = 0.6; #Heritability of the trait #rho = 0.8; #Proportion of the heritability caused by additive effects {0.8, 0.5} #pc.var = 0.1 ### Set Up Causal Pathways in Three Groups #ngenes = 20; #number of genes needed to get around 1000 SNPs pulled for G1, G2, and G3 nsnps = 1000; ncausal1 = .02; ncausal2 = .02 #Percent of SNPs needed for G1 and G2 ncausal3 = 1-(ncausal1+ncausal2) #Remaining SNPs to be allocated to G3 ### Create a list to save the final Results ### #pval_mat = matrix(nrow = nrow(Genes),ncol = n.datasets); pval_mat <- cbind(Genes[,1], pval_mat); #genes_chosen = matrix(nrow = ngenes, ncol = n.datasets); #G1_snps = matrix(nrow = ncausal1,ncol = n.datasets) #G2_snps = matrix(nrow = ncausal2,ncol = n.datasets) ### Run the Analysis ### for(i in 1:n.datasets) { #Select Causal Pathways gene.ids = 1:nrow(Genes) # genes.pulled.ids.temp <- sample(gene.ids, 1, replace=F); gene.ids.sampled <- sample(gene.ids); snp.total <- 0; genes.pulled.ids <- c(); genes.pulled.SNPs <- c(); snp.total.running <- c(0); numloop <- 1; while ((snp.total <= 1000) || (numloop >= length(gene.ids))) { gene.temp <- Genes[gene.ids.sampled[numloop],]; genes.pulled.ids <- c(genes.pulled.ids, gene.ids.sampled[numloop]); genes.pulled.SNPs <- c(genes.pulled.SNPs, unlist(strsplit(as.character(gene.temp[1,2]), ","))); snp.total <- length(genes.pulled.SNPs); snp.total.running <- c(snp.total.running, snp.total); numloop <- numloop + 1; } genes.pulled <- Genes[genes.pulled.ids,]; print(c(numloop, snp.total, length(genes.pulled.ids), snp.total.running[length(snp.total.running)-1])); # for (j in 1:nrow(genes.pulled)) { # genes.pulled.SNPs <- c(genes.pulled.SNPs, unlist(strsplit(as.character(genes.pulled[j,2]), ","))); # } genes.pulled.SNPs.uniq <- unique(genes.pulled.SNPs); genes.pulled.SNPs.uniq.ids <- 1:length(genes.pulled.SNPs.uniq) s1.ids=sample(genes.pulled.SNPs.uniq.ids, round(ncausal1*length(genes.pulled.SNPs.uniq)), replace=F) s2.ids=sample(genes.pulled.SNPs.uniq.ids[-s1.ids], round(ncausal2*length(genes.pulled.SNPs.uniq)), replace=F) s3.ids.size <- round(ncausal3*length(genes.pulled.SNPs.uniq)); if (s3.ids.size > length(genes.pulled.SNPs.uniq.ids[-c(s1.ids,s2.ids)])) { s3.ids.size <- s3.ids.size - 1; } s3.ids=sample(genes.pulled.SNPs.uniq.ids[-c(s1.ids,s2.ids)], s3.ids.size, replace=F) s1 <- genes.pulled.SNPs.uniq[s1.ids] s2 <- genes.pulled.SNPs.uniq[s2.ids] s3 <- genes.pulled.SNPs.uniq[s3.ids] ### Simulate the Additive Effects ### SNPs.additive = c(s1,s2,s3); # print(dim(X)) # print(SNPs.additive) Xmarginal = X[,SNPs.additive] beta=rnorm(dim(Xmarginal)[2]) y_marginal=c(Xmarginal%*%beta) beta=beta*sqrt(pve*rho/var(y_marginal)) y_marginal=Xmarginal%*%beta ### Simulate Pairwise Interaction matrix ### Xepi = c(); b = c() for(j in 1:ncausal1){ Xepi = cbind(Xepi,X[,s1[j]]*X[,s2]) } ### Simulate the Pairwise Effects ### beta=rnorm(dim(Xepi)[2]) y_epi=c(Xepi%*%beta) beta=beta*sqrt(pve*(1-rho)/var(y_epi)) y_epi=Xepi%*%beta ### Define the effects of the PCs ### beta=rnorm(dim(PCs)[2]) y_pcs=c(PCs%*%beta) beta=beta*sqrt(pc.var/var(y_pcs)) y_pcs=PCs%*%beta ### Simulate the (Environmental) Error/Noise ### y_err=rnorm(ind) y_err=y_err*sqrt((1-pve-pc.var)/var(y_err)) ### Simulate the Total Phenotypes ### y=y_marginal+y_epi+y_pcs+y_err y=(y-mean(y))/sd(y) ### Check dimensions ### print(dim(X)); print(length(y)); ###################################################################################### ###################################################################################### ###################################################################################### ptm <- proc.time() #Start clock MAPITR_Output <- MAPITR(X,y,Genes.Analysis[1:10,],Covariates=PCs) print(proc.time() - ptm) #Stop clock print(head(MAPITR_Output$Results)) # write.table(y, paste(Output1.File, ".Simulation.Pheno.txt", sep=""), quote=FALSE, col.name=FALSE, row.name=FALSE); # write.table(genes.pulled, paste(Output1.File, ".Simulation.nGenes.txt", sep=""), quote=FALSE, col.name=FALSE, row.name=FALSE); # write.table(s1, paste(Output1.File, ".Simulation.nCausal1.txt", sep=""), quote=FALSE, col.name=FALSE, row.name=FALSE); # write.table(s2, paste(Output1.File, ".Simulation.nCausal2.txt", sep=""), quote=FALSE, col.name=FALSE, row.name=FALSE); # write.table(MAPITR_Output$Results, paste(Output1.File, ".Results.Output.txt", sep=""), quote=FALSE, col.name=TRUE, row.name=FALSE); # ### Save Results ### # pval_mat[,j] = pvals # G1_snps[,j] = Pthwys_1 # G2_snps[,j] = Pthwys_2 } #Save final Results #Final = list(pval_mat,G1_snps,G2_snps)
884f1dbc46f1cb5e18e2999608ca0a8037220b57
09d8eb9f8703e8fd5c089eb58a559d4242b44a55
/plot1.R
c20670d3fdb3ba7c91dc5b10bcc4a169a19de09f
[]
no_license
yachabach/ExData_Plotting1
098ef2360d3cf67112720faaf1cf913f5f43f75b
1fb5a5af132888212366f6d7bdfc69f3ca4df393
refs/heads/master
2022-12-12T11:46:09.509680
2020-08-24T12:25:00
2020-08-24T12:25:00
289,589,814
0
0
null
null
null
null
UTF-8
R
false
false
601
r
plot1.R
# Generate plot #1 from coursera assignment # Plot1 <- function() { # Load data from working directory # fileNm <- "household_power_consumption.txt" hd <- fread(fileNm, nrows = 1) y <- fread(fileNm, skip = 64800, nrows = 5000, header = TRUE) colnames(y) = colnames(hd) #subset textual date data z <- y[grep('^1/2/2007|^2/2/2007',y$Date),] # Open png output device # png(file = "plot1.png") #draw histogram as assigned # with(z,hist(as.numeric(Global_active_power), col = "red", xlab = "Global Active Power (kilowatts)", main = "Global Active Power")) dev.off() }
4f1d9c90390c9c54814a141c35965f2febebc08c
e08f3b0790613a5c81f72db72e5a912a63052288
/estimate r 9-21.R
ae30aa08b054f7e3da0955594de9ab200b7cbaef
[]
no_license
MSTRoth/PSC_Homeless
edb33718997ac2a1e4c9884529f5510369166aba
943ce81b2657ea8bb54e2bd238c82feaed22f062
refs/heads/master
2020-06-07T06:47:29.544425
2019-08-16T20:23:46
2019-08-16T20:23:46
192,951,593
0
0
null
null
null
null
UTF-8
R
false
false
3,720
r
estimate r 9-21.R
####first and last##### options(scipen=10000) library(tidyverse) ####Estimates##### setwd("X:/1 Marielle Folder/Spending Data/Estimates files") ###actual and estimated values by year#### #####quarter views#### quarters <- read_csv("quarters.csv") data <- quarters %>% gather("quarter_FY","outlay", 2:57) %>% separate("quarter_FY", c("quarter", "FY"), sep = "_") %>% filter(quarter =="Q3"|quarter == "Q4") dataDoD <- data %>% filter(X1 == "Department of Defense--Military Programs") dataDHS <- data %>% filter(X1 == "Department of Homeland Security") dataVA <- data %>% filter(X1 == "Department of Veterans Affairs") dataTotal <- data %>% filter(X1 == "Total Outlays") ggplot(data, aes(x=`quarter`, y=outlay))+ geom_bar(stat = "identity", position =position_dodge())+ facet_grid(FY~X1) + theme(axis.text.x = element_text(angle = -45))+ labs(title = "obligated amount by quarter by fiscal year") #colnames(dataDoD) ggplot(dataDoD, aes(x=`quarter`, y=outlay, group = FY))+ geom_line(stat = "identity")+ facet_wrap("FY") + theme(axis.text.x = element_text(angle = -45))+ labs(title = "obligated amount by quarter by fiscal year - DoD") ggplot(dataDHS, aes(x=`quarter`, y=outlay, group = FY))+ geom_line(stat = "identity")+ facet_wrap("FY") + theme(axis.text.x = element_text(angle = -45))+ labs(title = "obligated amount by quarter by fiscal year - DHS") ggplot(dataVA, aes(x=`quarter`, y=outlay, group = FY))+ geom_line(stat = "identity")+ facet_wrap("FY") + theme(axis.text.x = element_text(angle = -45))+ labs(title = "obligated amount by quarter by fiscal year - VA") ggplot(dataTotal, aes(x=`quarter`, y=outlay, group = FY))+ geom_line(stat = "identity")+ facet_wrap("FY") + theme(axis.text.x = element_text(angle = -45))+ labs(title = "obligated amount by quarter by fiscal year - Total") ######quarter percent total year#### pertot <- read_csv("percent of total year quarter.csv") data<-pertot %>% gather("quarter_FY", "percent_total", 2:57) %>% separate("quarter_FY",c("quarter","FY"), sep = "_") %>% select(-X58) #%>% # filter(quarter =="Q1"|quarter == "Q4") ggplot(data, aes(x=quarter, y=percent_total, group = FY))+ geom_line(stat = "identity")+ facet_grid(FY~X1) + theme(axis.text.x = element_text(angle = -45))+ labs(title = "quarter - percent of total FY obligations") dataDoD <- data %>% filter(X1 == "Department of Defense--Military Programs") dataDHS <- data %>% filter(X1 == "Department of Homeland Security") dataVA <- data %>% filter(X1 == "Department of Veterans Affairs") dataTotal <- data %>% filter(X1 == "Total Outlays") ggplot(dataDoD, aes(x=`quarter`, y=percent_total, group = FY))+ geom_line(stat = "identity")+ facet_wrap("FY") + theme(axis.text.x = element_text(angle = -45))+ labs(title = "quarter - percent of total FY obligations - DoD") ggplot(dataDHS, aes(x=`quarter`, y=percent_total, group = FY))+ geom_line(stat = "identity")+ facet_wrap("FY") + theme(axis.text.x = element_text(angle = -45))+ labs(title = "quarter - percent of total FY obligations - DHS") ggplot(dataVA, aes(x=`quarter`, y=percent_total, group = FY))+ geom_line(stat = "identity")+ facet_wrap("FY") + theme(axis.text.x = element_text(angle = -45))+ labs(title = "quarter - percent of total FY obligations - VA") ggplot(dataTotal, aes(x=`quarter`, y=percent_total, group = FY))+ geom_line(stat = "identity")+ facet_wrap("FY") + theme(axis.text.x = element_text(angle = -45))+ labs(title = "quarter - percent of total FY obligations - Total")
e2b90c44129da244e37b3909ff0bb6ba459c2235
c122e77a34976b987ad45f70b5802e79098702a4
/inst/shinyApps/hisreg/R/modFordelinger.R
4c7b97dafde56b4760be49fe425ac7f218ada15d
[]
no_license
Rapporteket/hisreg
b4d212fdca74dbd8fcc4dfbbc2bc1922f84b90dc
7e06f4d5d39c357696d35146f5da5508eaa20586
refs/heads/master
2022-09-20T06:04:16.198184
2022-05-03T14:26:44
2022-05-03T14:26:44
77,216,862
0
0
null
2020-02-24T11:10:24
2016-12-23T10:03:24
R
UTF-8
R
false
false
9,786
r
modFordelinger.R
#hjelpefunksjon som lager topp og bunntekst til tabellen cont <- function(enh, usRole) { if (usRole == "SC") { avd = "Valgt avdeling" } else { avd = "Din avdeling" } if (enh == 1) { htmltools::withTags(table( class = "display", thead( tr( th(rowspan = 2, "Kategori"), th(class = "dt-center", colspan = 3, avd), th(class = "dt-center", colspan = 3, "Landet forøveig") ), tr( lapply(rep(c("N", "Antall", "Andel"), 2), th) ) ) )) } else{ htmltools::withTags(table( class = "display", thead( tr( lapply(c("Kategori", "N", "Antall", "Andel"), th) ) ) )) } } #modul UI modFordelingerUI <- function(id, varValg = varValgFordeling) { ns <- shiny::NS(id) enhvalg <- c("Egen avd. mot landet forøvrig" = 1, "Hele landet" = 0, "Egen avdeling" = 2) shiny::sidebarLayout( shiny::sidebarPanel(width = 3, div(id = ns("sbPanel"), shiny::selectInput(ns("varSel"), label = "Velg variabel", choices = varValg, selected = varValg[[1]]), shiny::selectInput(ns("typInt"), label = "Type intervensjon", choices = typInt, selected = 99), shiny::uiOutput(ns("SC")), shiny::selectInput(ns("enhSel"), label = "Velg enhe(er)", choices = enhvalg, selected = enhvalg[[1]]), shiny::dateRangeInput(ns("dateRan"), label = "Tidsperiode", language = "no", separator = "til", min = "2011-01-01", max = Sys.Date(), start = "2011-01-01", end = Sys.Date()), shiny::selectInput(ns("kjoSle"), label = "Kjønn", choices = kjoenn, selected = 99), shiny::sliderInput(ns("aldSli"), label = "Alder", min = 0, max = 130, value = c(0, 130)), shiny::uiOutput(ns("figfil"))), shiny::actionLink(inputId=ns("nullstill"), style="color:black" , label = "Nullstill Valg") ), shiny::mainPanel(width = 9, shiny::fluidRow( shiny::column(6, tabsetPanel(id = ns("tabs"), tabPanel("Figur", value = "fig", shiny::plotOutput(ns("figur"), width = "95%", height = "600px"), downloadButton(ns("lastNedBilde"), "Last ned bilde")), tabPanel("Tabell", value = "tab", DT::DTOutput(ns("tabell")), downloadButton(ns("lastNed"), "Last ned tabell") ))) ) )#mainpanel )#sidebarLayout } #moduleserver modFordelinger <- function(input, output, session, rID, role, ss, RegData) { output$figfil <- shiny::renderUI({ ns <- session$ns if (input$tabs == "fig") { shiny::selectInput(ns("outfil"), label = "Velg bildeformat", choices = c("pdf", "png", "jpg", "bmp", "tif", "svg")) } }) output$SC <- renderUI({ ns <- session$ns if (role == "SC") { shiny::selectInput(ns("shSelect"), label = "Velg Avdeling", choices = avdValg, selected = rID ) } }) resh <- reactive( if (role == "SC"){ req(input$shSelect) } else { rID } ) observeEvent(req(input$nullstill), {shinyjs::reset("sbPanel")}) data <- reactive({ hisreg::hisregFigAndeler(RegData = RegData, valgtVar = input$varSel, datoFra = min(input$dateRan), datoTil = max(input$dateRan), minald = input$aldSli[1], maxald = input$aldSli[2], reshID = resh(), enhetsUtvalg = input$enhSel, forlop1 = input$typInt, erMann = as.numeric(input$kjoSle)) }) #data til en dataramme df <- shiny::reactive({ if (is.table(data()$Andeler$Hoved)) { if (input$enhSel == 1) { data.frame("Kategori" = as.data.frame(data()$Andeler$Hoved)[, 1], "Antall." = rep(data()$Antall$Hoved, length(data()$Andeler$Hoved)), "N." = round((as.data.frame(data()$Andeler$Hoved)[, 2] / 100) * data()$Antall$Hoved), "Andel." = round(as.data.frame(data()$Andeler$Hoved)[, 2] / 100, digits = 3), "Antall" = rep(data()$Antall$Rest, length(data()$Andeler$Hoved)), "N" = round((as.data.frame(data()$Andeler$Rest)[, 2] / 100) * data()$Antall$Rest), "Andel" = round(as.data.frame(data()$Andeler$Rest)[, 2] / 100, digits = 3)) } else { data.frame("Kategori" = as.data.frame(data()$Andeler$Hoved)[, 1], "Antall." = rep(data()$Antall$Hoved, length(data()$Andeler$Hoved)), "N." = round((as.data.frame(data()$Andeler$Hoved)[, 2] / 100) * data()$Antall$Hoved), "Andel." = round(as.data.frame(data()$Andeler$Hoved)[, 2] / 100 , digits = 3)) } } else{ if (input$enhSel == 1) { data.frame("Kategori" = data()$Grtxt, "Antall." = rep(data()$Antall$Hoved, length(data()$Andeler$Hoved)), "N." = round((data()$Andeler$Hoved / 100) * data()$Antall$Hoved), "Andel." = round(data()$Andeler$Hoved / 100, digits = 3), "Antal" = rep(data()$Antall$Rest, length(data()$Andeler$Hoved)), "N" = round((data()$Andeler$Rest / 100) * data()$Antall$Rest), "Andel" = round(data()$Andeler$Rest / 100, digits = 3)) } else { data.frame("Kategori" = data()$Grtxt, "Antall." = rep(data()$Antall$Hoved, length(data()$Andeler$Hoved)), "N." = round((data()$Andeler$Hoved / 100) * data()$Antall$Hoved), "Andel." = round(data()$Andeler$Hoved / 100, digits = 3)) } } }) #andelsfigurer output$figur <- renderPlot( hisreg::hisregFigAndeler(RegData = RegData, valgtVar = input$varSel, datoFra = min(input$dateRan), datoTil = max(input$dateRan), minald = input$aldSli[1], maxald = input$aldSli[2], reshID = resh(), enhetsUtvalg = input$enhSel, forlop1 = input$typInt, erMann = as.numeric(input$kjoSle)) ) #tabell observe({ cont <- cont(input$enhSel, role) output$tabell <- DT::renderDT( if (input$enhSel == 1) { df() %>% datatable(selection = "none", container = cont, rownames = FALSE, options = list(dom = "t")) %>% DT::formatPercentage(c("Andel", "Andel."), digits = 1) } else{ df() %>% datatable(selection = "none", container = cont, rownames = FALSE, options = list(dom = "t")) %>% DT::formatPercentage("Andel.", digits = 1) } ) }) output$lastNed <- downloadHandler( filename = function() { paste0(input$varSel, Sys.time(), ".csv") }, content = function(file) { tab <- df() write.csv2(tab, file, row.names = F) } ) output$lastNedBilde <- downloadHandler( filename = function(){ paste0(input$varSel, Sys.time(), '.', input$outfil) }, content = function(file){ hisreg::hisregFigAndeler(RegData = RegData, valgtVar = input$varSel, datoFra = min(input$dateRan), datoTil = max(input$dateRan), minald = input$aldSli[1], maxald = input$aldSli[2], reshID = resh(), enhetsUtvalg = input$enhSel, forlop1 = input$typInt, outfile = file, erMann = as.numeric(input$kjoSle)) } ) #logging shiny::observe({ if (rapbase::isRapContext()) { if (input$tabs == "fig") { mld <- paste( "Hisreg: figur - fordeling. variabel -", input$varSel ) } else if (input$tabs == "tab") { mld <- paste( "Hisreg: tabell - fordeling. variabel -", input$varSel ) } rapbase::repLogger( session = ss, msg = mld ) mldNLF <- paste( "Hisreg: nedlasting figur - fordeling. variabel", input$varSel ) mldNLT <- paste( "Hisreg: nedlasting tabell - fordeling. variabel", input$varSel ) shinyjs::onclick( "lastNedBilde", rapbase::repLogger( session = ss, msg = mldNLF ) ) shinyjs::onclick( "lastNed", rapbase::repLogger( ss, msg = mldNLT ) ) } }) }
4fd8b240fd4dd0f125607744e55d5450a73dbb19
c90e263ccf61d5d6c0bc33c715c85beec9cf6ef1
/man/cenreg.Rd
0fb00ec6dee22bdadc3dcd9ce6e6afdc501b3fa2
[]
no_license
cran/NADA
d68537895922ff0d882fbd1e4db0ea5bc8b83bb1
b3584c690049bd498b427db75ebee4fadcb24bb7
refs/heads/master
2020-12-24T13:18:24.287687
2020-03-22T08:46:09
2020-03-22T08:46:09
17,681,060
2
4
null
null
null
null
UTF-8
R
false
false
4,729
rd
cenreg.Rd
\name{cenreg} \alias{cenreg} \title{ Compute regression equations and likelihood correlation coefficient for censored data. } \description{ Computes regression equations for singly censored data using maximum likelihood estimation. Estimates of slopes and intercept, tests for significance of parameters,and predicted quantiles (Median = points on the line) with confidence intervals can be computed. } \usage{ cenreg(obs, censored, groups, ...) } \arguments{ \item{obs}{ Either a numeric vector of observations or a formula. See examples below. } \item{censored}{ If a formula is not specified, this should be a logical vector indicating TRUE where an observation in obs is censored (a less-than value) and FALSE otherwise. } \item{groups}{ If a formula is not specified, this should be a numeric or factor vector that represents the explanatory variable. } \item{...}{ Additional items that are common to this function and the \code{survreg} function from the `survival' package. The most important of which is `dist' and `conf.int'. See Details below. } } %END arguments \details{ This routine is a front end to the \code{survreg} routine in the \code{survival} package. There are many additional options that are supported and documented in \code{survfit}. Only a few have relevance to the evironmental sciences. A very important option is `dist' which specifies the distributional model to use in the regression. The default is `lognormal'. Another important option is `conf.int'. This is NOT an option to \code{survreg} but is an added feature (due to some arcane details of R it can't be documented above). The `conf.int' option specifies the level for a two-sided confidence interval on the regression. The default is 0.95. This interval will be used in when the output object is passed to other generic functions such as \code{mean} and \code{quantile}. See Examples below. Also supported is a `gaussian' or a normal distribution. The use of a gaussian distribution requires an interval censoring context for left-censored data. Luckily, this routine automatically does this for you -- simply specify `gaussian' and the correct manipulations are done. If any other distribution is specified besides lognormal or gaussian, the return object is a raw survreg object -- it is up to the user to `do the right thing' with the output (and input for that matter). If you are using the formula interface: The \code{censored} and \code{groups} parameters are not specified -- all information is provided via a formula as the \code{obs} parameter. The formula must have a \code{Cen} object as the response on the left of the \code{~} operator and, if desired, terms separated by + operators on the right. See examples below. The reported likelihood r correlation coefficient measures the linear association between y (groups) and x (obs), based on the difference in log likelihoods between the fitted model and the null model. Slopes and intercepts are fit by maximum likelihood. A lognormal distribution is fit by default, with a normal distribution being an option. Estimates of predicted values on the line can be obtained by specifying the values for all x variables at which y is to be predicted. Requesting the median (p=0.5) will provide estimates on the line for a lognormal distribution. Estimates of the mean are also possible, as are estimates of other percentiles. Equations for confidence intervals follow those of Meeker and Escobar (1098). } \value{ Returns a \code{\link{summary.cenreg}} object. } \references{ Helsel, Dennis R. (2005). Nondectects and Data Analysis; Statistics for censored environmental data. John Wiley and Sons, USA, NJ. Meeker, W.Q. and L. A. Escobar (1998). Statistical Methods for Reliability Data. John Wiley and Sons, USA, NJ. } \author{ R. Lopaka Lee <rclee@usgs.gov> Dennis Helsel <dhelsel@practicalstats.com> } \seealso{ \code{\link{Cen}}, \code{\link{cenmle}}, \code{\link{predict-methods}} } \examples{ % with(TCEReg, cenreg(log(TCEConc), TCECen, PopDensity)) # (examples in Chap 12 of the NADA book) data(TCEReg) # Using the formula interface with(TCEReg, cenreg(Cen(TCEConc, TCECen)~PopDensity)) # Two or more explanatory variables requires the formula interface tcemle2 = with(TCEReg, cenreg(Cen(TCEConc, TCECen)~PopDensity+Depth)) # Prediction of quantiles at PopDensity=5 and Depth=110 predict(tcemle2, c(5, 110)) } \keyword{survival}
8750daf8416361c94af717e0ae279be42cfe9cf1
4aebc58b3b753e9d99f44a90ef4f83aae474f917
/server.R
614265ebe52b8f1c12bde640e2e05108bb7a73e3
[]
no_license
civilstat/MixedPanel
55413b13e26549b65c50f088fc1e791f241d2d6c
fc8b8d081b6035252fce6c640b3bdebffe209cd9
refs/heads/master
2021-01-01T18:23:09.604697
2015-10-05T22:36:30
2015-10-05T22:36:30
33,269,799
0
0
null
null
null
null
UTF-8
R
false
false
3,154
r
server.R
library(shiny) # Define server logic to plot a Hypergeometric distribution with explanatory text shinyServer(function(input, output) { # Slider input for number of women output$Nwomen <- renderUI({ sliderInput("Nwomen", paste("Number of", input$subgroup, "candidates:"), min = 0, max = input$Ntotal, value = min(8, input$Ntotal), step = 1) }) # Slider input for panel size output$Npanel <- renderUI({ sliderInput("Npanel", "Size of panel:", min = 1, max = input$Ntotal, value = min(5, input$Ntotal), step = 1) }) # Slider input for nr women whose prob to evaluate output$Nchosen <- renderUI({ sliderInput("Nchosen", paste("Number of", input$subgroup, "panelists whose probability we want to evaluate:"), min = 0, max = min(input$Npanel, input$Nwomen), value = c(0,0), step = 1) }) # Specify the hypergeometric distribution from the inputs thisDhyper <- function(x) { dhyper(x, m = input$Nwomen, n = (input$Ntotal - input$Nwomen), k = input$Npanel) } # Function that generates a plot of the distribution. The function # is wrapped in a call to reactivePlot to indicate that: # 1) It is "reactive" and therefore should be automatically # re-executed when inputs change # 2) Its output type is a plot output$distPlot <- reactivePlot(function() { minMorK <- min(input$Nwomen, input$Npanel) thisBorder <- rep("black", minMorK + 1) thisBorder[(input$Nchosen[1]:input$Nchosen[2])+1] <- "red" barplot(100*thisDhyper(0:minMorK), names = 0:minMorK, xlab = paste("Number of", input$subgroup, "members on a panel of", input$Npanel), ylab = "Probability (%)", border = thisBorder) }) output$probText <- renderUI({ strNchosen <- ifelse(input$Nchosen[1] == input$Nchosen[2], input$Nchosen[1], paste(input$Nchosen[1], "to", input$Nchosen[2])) HTML( paste0("Let's say you started with <b>", input$Ntotal, "</b> candidates, of whom <b>", input$Nwomen, "</b> were ", input$subgroup, ", and you randomly chose a panel of <b>", input$Npanel, "</b> people from this candidate pool.<br/>The probability that your panel has <b>", strNchosen, "</b> ", input$subgroup, " members would be about <b>", round(sum(100*thisDhyper(input$Nchosen[1]:input$Nchosen[2])), 1), "%</b>.") ) }) output$footnoteText <- renderUI({ HTML("(Calculations are based on the hypergeometric distribution, as in <a href='http://stats.stackexchange.com/questions/11836/probability-of-panel-assignment'>this StackExchange example</a>.<br/>Code available <a href='https://github.com/civilstat/MixedPanel'>on Github</a>.)") }) })
88e80b88e81101525d37d9f36dca365c7f988e3a
688185e8e8df9b6e3c4a31fc2d43064f460665f1
/man/rad.Rd
ea89dc00201c51f5ec03ef402a809cc6eda8d7e1
[]
no_license
IPS-LMU/emuR
4b084971c56e4fed9032e40999eeeacfeb4896e8
eb703f23c8295c76952aa786d149c67a7b2df9b2
refs/heads/master
2023-06-09T03:51:37.328416
2023-05-26T11:17:13
2023-05-26T11:17:13
21,941,175
17
22
null
2023-05-29T12:35:55
2014-07-17T12:32:58
R
UTF-8
R
false
true
786
rd
rad.Rd
% Generated by roxygen2: do not edit by hand % Please edit documentation in R/misc.R \name{rad} \alias{rad} \title{Function to convert between Hertz and Radians} \usage{ rad(vec, samfreq = 20000, hz = TRUE) } \arguments{ \item{vec}{A numerical vector of frequencies in Hz or radians} \item{samfreq}{A single element numerical vector of the sampling frequency. Defaults to 20000 Hz} \item{hz}{Logical. If TRUE, convert from Hz to radians otherwise from radians to hz} } \description{ convert between Hertz and Radians } \examples{ # 4000 Hz in radians at a sampling frequency of 8000 Hz rad(4000, 8000) # pi/2 and pi/4 radians in Hz at a sampling frequency of 10000 Hz rad(c(pi/2, pi/4), 10000, FALSE) } \seealso{ \code{\link{help}} } \author{ Jonathan Harrington } \keyword{math}
2a400ff9074effff1bbda2e9817c751fcb393cd2
db26d059b38d4c7e51aae2fb4b6a72efe8007c43
/ceRNA_helper/get_correlation.R
f4ba27db08cd25b19d4f3483f9accf84d0b101e7
[]
no_license
duc-do/DyCeR
5f5f3f4fb099a3052770fedb36221bbb57638444
76a651e97a5bec8b7c748b7256c8342614e5b91d
refs/heads/master
2021-08-30T16:39:36.233992
2017-12-18T17:51:25
2017-12-18T17:51:25
114,670,223
1
0
null
null
null
null
UTF-8
R
false
false
1,012
r
get_correlation.R
### ----- variables ------##### cat(paste(" compute correlation and pvalue","\n")) #mRNA.expression = lasso.result$residual.expression mRNA.expression = regression.data$mRNA cor.info = WGCNA::corAndPvalue(t(mRNA.expression),use = "pairwise.complete.obs") pair.dt = pair.dt ### ----- analysis ------##### cluster = parallel::makeCluster(parallel::detectCores()-1) parallel::clusterExport(cl = cluster,varlist = c("pair.dt", "cor.info"),envir = environment()) cat(paste(" assign correlation","\n")) pair.dt$cor = pbapply::pbsapply(cl = cluster, X = 1:nrow(pair.dt), FUN = function(index){ RNAi = pair.dt$RNAi[index]; RNAj = pair.dt$RNAj[index] return(cor.info$cor[RNAi,RNAj]) }) cat(paste(" assign correlation pvalues","\n")) pair.dt$cor.pvalue = pbapply::pbsapply(cl = cluster, X = 1:nrow(pair.dt), FUN = function(index){ RNAi = pair.dt$RNAi[index]; RNAj = pair.dt$RNAj[index] return(cor.info$p[RNAi,RNAj]) }) stopCluster(cluster) ### ----- clean-up ------##### rm(mRNA.expression, cor.info)
ba58df4fcc37033a676765f80f9f7ee1bdf2bd54
2fb67b51e9b082a41cf31e748b6745b5cb7c743d
/modules/scfmLandcoverInit/scfmLandcoverInit.R
732553418b237d9592147ee076bb29159e48dc80
[]
no_license
tati-micheletti/SpaDESinAction
4724314e1e28bba8f837f7a1a99fefedd52d2041
6a39918a0f1b18ccbb752276f007302a64cef508
refs/heads/master
2020-07-06T08:40:08.520939
2019-10-10T16:14:26
2019-10-10T16:14:26
202,958,164
0
4
null
2019-10-10T15:44:01
2019-08-18T04:06:27
HTML
UTF-8
R
false
false
13,286
r
scfmLandcoverInit.R
stopifnot(packageVersion("SpaDES") >= "0.99.0") defineModule(sim,list( name = "scfmLandcoverInit", description = "Takes the LCC05 classification of 39 land cover classes, and reclassifies it to flammable and inflammable [1,0]", keywords = c("fire", "LCC05", "land cover classification 2005", "BEACONs"), childModules = character(), authors = c( person(c("Eliot", "J", "B"),"McIntire", email = "Eliot.McIntire@canada.ca", role = c("aut", "cre")), person("Steve", "Cumming", email = "stevec@sbf.ulaval.ca", role = c("aut")), person("Ian", "Eddy", email = "ian.eddy@canada.ca", role = c("aut"))), version = numeric_version("0.1.0"), spatialExtent = raster::extent(rep(NA_real_, 4)), timeframe = as.POSIXlt(c("2005-01-01", NA)), documentation = list("README.txt", "scfmLandcoverInit.Rmd"), timeunit = "year", citation = list(), reqdPkgs = list("fasterize", "purrr", "raster", "sf", 'rgeos', "PredictiveEcology/LandR@development", "PredictiveEcology/reproducible@development"), parameters = rbind( defineParameter(".plotInitialTime", "numeric", start(sim), NA, NA, desc = "Initial time for plotting"), defineParameter(".plotInterval", "numeric", NA_real_, NA, NA, desc = "Interval between plotting"), defineParameter(".saveInitialTime", "numeric", NA_real_, NA, NA, desc = "Initial time for saving"), defineParameter(".saveInterval", "numeric", NA_real_, NA, NA, desc = "Interval between save events"), defineParameter("useCache", "logical", TRUE, NA, NA, desc = "Use cache"), defineParameter("neighbours", "numeric", 8, NA, NA, desc = "Number of immediate cell neighbours"), defineParameter("sliverThreshold", "numeric", 10000, NA, NA, desc = "fire regime polygons with area less than this number will be merged") ), inputObjects = bind_rows( expectsInput(objectName = "ecodistrict", objectClass = "numeric", desc = "Ecodistrict number to use as studyArea"), # added expectsInput(objectName="nNbrs", objectClass = "numeric", desc = "raster cell neighborhood defaults to 8"), # added expectsInput(objectName = "studyArea", objectClass = "SpatialPolygonsDataFrame", desc = "", sourceURL = "http://sis.agr.gc.ca/cansis/nsdb/ecostrat/district/ecodistrict_shp.zip"), expectsInput(objectName = "vegMap", objectClass = "RasterLayer", desc = "Landcover to build flammability map", sourceURL = "ftp://ftp.ccrs.nrcan.gc.ca/ad/NLCCLandCover/LandcoverCanada2005_250m/LandCoverOfCanada2005_V1_4.zip"), expectsInput(objectName = "rasterToMatch", objectClass = "RasterLayer", desc = "template raster for raster GIS operations.", sourceURL = "https://drive.google.com/open?id=1WkTFn6RssKHgUBKSfAhDYcKS5Kb1Wsef"), expectsInput(objectName = "fireRegimePolys", objectClass = "SpatialPolygonsDataFrame", desc = "Areas to calibrate individual fire regime parameters. Defaults to ecoregions", sourceURL = "http://sis.agr.gc.ca/cansis/nsdb/ecostrat/region/ecoregion_shp.zip"), expectsInput(objectName = "ageMap", objectClass = "RasterLayer", desc = "Default map to define flammable map", sourceURL = NA), expectsInput(objectName = "flammableMap", objectClass = "RasterLayer", desc = "map of landscape flammability") ), outputObjects = bind_rows( createsOutput(objectName = "cellsByZone", objectClass = "data.frame", desc = "explains which raster cells are in which polygon"), createsOutput(objectName = "flammableMap", objectClass = "RasterLayer", desc = "map of landscape flammability"), createsOutput(objectName = "landscapeAttr", objectClass = "list", desc = "list of polygon attributes inc. area"), createsOutput(objectName = "landscapeAttrHARVEST", objectClass = "list", desc = "list of polygon attributes inc. area especifically for harvest"), createsOutput(objectName = "fireRegimeRas", objectClass = "RasterLayer", desc = "Rasterized version of fireRegimePolys with values representing polygon ID") ) ) ) doEvent.scfmLandcoverInit = function(sim, eventTime, eventType, debug = FALSE) { switch(eventType, init = { sim <- Init(sim) sim <- scheduleEvent(sim, P(sim)$.plotInitialTime, "scfmLandcoverInit", "plot") }, plot = { Plot(sim$vegMap, new = TRUE, title = "Vegetation Classes") # schedule future event(s) sim <- scheduleEvent(sim, time(sim) + P(sim)$.plotInterval, "scfmLandcoverInit", "plot") }, warning(paste("Undefined event type: '", events(sim)[1, "eventType", with = FALSE], "' in module '", events(sim)[1, "moduleName", with = FALSE], "'", sep = ""))) return(invisible(sim)) } Init <- function(sim) { message("checking sim$fireRegimePolys for sliver polygons...") if (sf::st_is_longlat(sim$fireRegimePolys) & is.na(P(sim)$sliverThreshold)) { sim$fireRegimePolys <- projectInputs(x = sim$fireRegimePolys, targetCRS = crs(sim$vegMap)) stop("You must supply P(sim)$sliverThreshold for fireRegimePolys with an unprojected CRS") } sim$fireRegimePolys$trueArea <- gArea(sim$fireRegimePolys, byid = TRUE) if (is.na(P(sim)$sliverThreshold)) { sim@params[[currentModule(sim)]]$sliverThreshold <- 1e4 } if (any(sim$fireRegimePolys$trueArea < P(sim)$sliverThreshold)) { message("sliver polygon(s) detected. Merging to their nearest valid neighbour") sim$fireRegimePolys <- Cache(deSliver, sim$fireRegimePolys, threshold = P(sim)$sliverThreshold, userTags = c("deSliver", currentModule(sim))) } if (is.null(sim$fireRegimePolys$PolyID)) { if (is.null(sim$fireRegimePolys$REGION_)) { sim$fireRegimePolys$PolyID <- row.names(sim$fireRegimePolys) } else { sim$fireRegimePolys$PolyID <- as.numeric(sim$fireRegimePolys$REGION_) } } temp <- sf::st_as_sf(sim$fireRegimePolys) temp$PolyID <- as.numeric(temp$PolyID) #fasterize needs numeric; row names must stay char sim$fireRegimeRas <- fasterize::fasterize(sf = temp, raster = sim$vegMap, field = "PolyID") sim$flammableMap <- LandR::defineFlammable(sim$vegMap, filename2 = NULL) sim$flammableMap <- setValues(raster(sim$flammableMap), sim$flammableMap[]) sim$flammableMap <- mask(sim$flammableMap, mask = sim$fireRegimeRas) # This makes sim$landscapeAttr & sim$cellsByZone outs <- Cache(genFireMapAttr, sim$flammableMap, sim$fireRegimePolys, P(sim)$neighbours) sim$landscapeAttr <- outs$landscapeAttr sim$landscapeAttrHARVEST <- genFireMapAttrHARVEST(flammableMap = sim$flammableMap, nNbrs = sim$nNbrs) # TO COMPARE WITH THE OTHER OUT sim$cellsByZone <- outs$cellsByZone return(invisible(sim)) } genFireMapAttr <- function(flammableMap, fireRegimePolys, neighbours) { #calculate the cell size, total area, and number of flammable cells, etc. #All areas in ha cellSize <- prod(res(flammableMap)) / 1e4 # in ha if (neighbours == 8) w <- matrix(c(1, 1, 1, 1, 0, 1, 1, 1, 1), nrow = 3, ncol = 3) else if (neighbours == 4) w <- matrix(c(0, 1, 0, 1, 0, 1, 0, 1, 0), nrow = 3, ncol = 3) else stop("illegal neighbours specification") makeLandscapeAttr <- function(flammableMap, weight, fireRegimePolys) { neighMap <- focal(x = flammableMap, w = w, na.rm = TRUE) #default function is sum(...,na.rm) # extract table for each polygon valsByPoly <- raster::extract(neighMap, fireRegimePolys, cellnumbers = TRUE) valsByPoly <- lapply(valsByPoly, na.omit) names(valsByPoly) <- fireRegimePolys$PolyID uniqueZoneNames <- fireRegimePolys$PolyID #get unique zones. valsByZone <- lapply(uniqueZoneNames, function(ecoName) { aa <- valsByPoly[names(valsByPoly) == ecoName] if (is.list(aa)) aa <- do.call(rbind, aa) return(aa) }) names(valsByZone) <- uniqueZoneNames # Derive frequency tables of number of flammable cells, per polygon type, currently ECOREGION nNbrs <- lapply(valsByZone, function(x) { nNbrs <- tabulate(x[, 2] + 1, 9)#depends on sfcmLandCoverInit names(nNbrs) <- 0:8 return(nNbrs) }) nFlammable <- lapply(valsByZone, function(x) { sum(getValues(flammableMap)[x[, 1]], na.rm = TRUE) #sums flammable pixels in FRI polygons }) landscapeAttr <- purrr::transpose(list(cellSize = rep(list(cellSize), length(nFlammable)), nFlammable = nFlammable, nNbrs = nNbrs, cellsByZone = lapply(valsByZone, function(x) x[, 1]))) landscapeAttr <- lapply(landscapeAttr, function(x) { append(x, list(burnyArea = x$cellSize * x$nFlammable)) }) names(landscapeAttr) <- names(valsByZone) return(landscapeAttr) } landscapeAttr <- makeLandscapeAttr(flammableMap, w, fireRegimePolys) cellsByZoneFn <- function(flammableMap, landscapeAttr) { cellsByZone <- data.frame(cell = 1:ncell(flammableMap), zone = NA_character_, stringsAsFactors = FALSE) for (x in names(landscapeAttr)) { cellsByZone[landscapeAttr[[x]]$cellsByZone, "zone"] <- x } return(cellsByZone) } cellsByZone <- cellsByZoneFn(flammableMap, landscapeAttr) return(invisible(list(landscapeAttr = landscapeAttr, cellsByZone = cellsByZone))) } ### template initilization .inputObjects <- function(sim) { invisible(tryCatch(dev.off(), error = function(e){})) dev.new() dev.new() quickPlot::clearPlot() dPath <- dataPath(sim) #where files will be downloaded cacheTags = c(currentModule(sim), "function:.inputObjects") if (!suppliedElsewhere("ecodistrict", sim)) { sim$ecodistrict <- 644 } if (!suppliedElsewhere("studyArea", sim)) { message("study area not supplied. Using Ecodistrict 644") sim$studyArea <- Cache(prepInputs, url = extractURL(objectName = "studyArea", sim = sim), destinationPath = getPaths()$inputPath, targetCRS = "+proj=aea +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84", filename2 = "studyArea", overwrite = TRUE) %>% .[.[["ECODISTRIC"]] %in% sim$ecodistrict, ] } if (!suppliedElsewhere("rasterToMatch", sim)) { message("rasterToMatch not supplied. generating from Canada Forest's Age Map using cropped to studyArea") sim$rasterToMatch <- Cache(prepInputs, url = extractURL(objectName = "rasterToMatch", sim = sim), targetFile = "can_age04_1km.tif", studyArea = sim$studyArea, destinationPath = getPaths()$inputPath, userTags = "objectName:RTM", filename2 = NULL) } if (!suppliedElsewhere("vegMap", sim)) { message("vegMap not supplied. Using default LandCover of Canada 2005 V1_4a") sim$vegMap <- LandR::prepInputsLCC(year = 2005, destinationPath = dPath, studyArea = sim$studyArea, rasterToMatch = sim$rasterToMatch, filename2 = TRUE, overwrite = TRUE, userTags = c("cacheTags", "vegMap")) } if (!suppliedElsewhere("fireRegimePolys", sim)) { message("fireRegimePolys not supplied. Using default ecoregions of Canada cropped to study Area") sim$fireRegimePolys <- Cache(prepInputs, url = extractURL("fireRegimePolys", sim), destinationPath = dPath, studyArea = sim$studyArea, rasterToMatch = sim$rasterToMatch, filename2 = TRUE, overwrite = TRUE, userTags = c("cacheTags", "fireRegimePolys")) } if (!suppliedElsewhere("ageMap",sim)){ message(crayon::yellow("Age map was not provided. Using Canada's age map from 2004 1km resolution")) sim$ageMap <- Cache(prepInputs, url = "https://drive.google.com/open?id=1WkTFn6RssKHgUBKSfAhDYcKS5Kb1Wsef", targetFile = "can_age04_1km.tif", studyArea = sim$studyArea, destinationPath = dataPath(sim), userTags = "objectName:ageMap", filename2 = NULL) } if (!suppliedElsewhere("flammableMap", sim)){ sim$flammableMap <- sim$ageMap names(sim$flammableMap) <- "flammableMap" } if (!suppliedElsewhere("sliverThreshold", sim)){ sim$sliverThreshold <- 10000 } if (!suppliedElsewhere("numTypes", sim)){ sim$numTypes <- 8 } if (!suppliedElsewhere("landscapeAttr", sim)){ sim$landscapeAttr = list(cellSize = 6.25) } if (!suppliedElsewhere("nNbrs", sim)){ sim$nNbrs <- 8 } if (!suppliedElsewhere("areaInHa", sim)){ sim$areaInHa = pi } return(invisible(sim)) }
ada7091e334737d6e2f51b0b65c1941ace30eeb7
e04fdb3830feea19fc2d7f0dc937b21039af996b
/Software/RBrownie/man/addHS.Rd
4513f79fe2eb899d501c5afad0bdd0fbb1c44c90
[]
no_license
bomeara/omearatenure
c53b2bb41f313e84cd551c59317918657a3fbef1
dd0fac37c26712e71bfdf0ad39e36b9b29c8f616
refs/heads/master
2020-04-08T08:33:03.815826
2014-11-03T07:26:40
2014-11-03T07:26:40
null
0
0
null
null
null
null
UTF-8
R
false
false
4,176
rd
addHS.Rd
\name{addHS} \alias{addHS} %- Also NEED an '\alias' for EACH other topic documented here. \title{ Add Heuristic search command to brownie object } \description{ This function adds a character string to the the \code{commands} slot of a brownie object (or list of brownie objects) which instructs the brownie program to run a heuristic search. } \usage{ addHS(obj, nreps = NULL, rearrlimit = NULL, maxnumspp = NULL, minnumspp = NULL, minsamp = NULL, structwt = NULL, pthreshold = NULL, subsample = NULL, movefreq = NULL, file = NULL, showtries = NULL, coal = NULL, ms = NULL, aic.mode = NULL, gridwidth = NULL, gridsize = NULL, maxrecursions = NULL, branch.export = NULL, usetempfile = FALSE) } %- maybe also 'usage' for other objects documented here. \arguments{ \item{obj}{ A brownie object (or list of brownie objects) } \item{nreps}{ Number of random starting species trees to use } \item{rearrlimit}{ Limit search to X rearrangements for each nrep } \item{maxnumspp}{ The maximum number of species to split the samples into. } \item{minnumspp}{ The minimum number of samples per species (NOT the number of species). } \item{minsamp}{ The minimum number of samples per species (NOT the number of species). } \item{structwt}{ StructWt } \item{pthreshold}{ Run search until a certain p-value threshold is reach. } \item{subsample}{ %% ~~Describe \code{subsample} here~~ } \item{movefreq}{ Sets the relative proportion of times to try: 1.) Species tree branch swaps, 2.) Moving samples from one species to another, 3.) Increasing the number of species, 4.) Decreasing the number of species, 5.) Attempt to reroot the species tree. If these don't sum to one, the program will automatically scale them up or down. } \item{file}{ The brownie core write the output of the analysis to this file (optional) } \item{showtries}{ %% ~~Describe \code{showtries} here~~ } \item{coal}{ Not currently used } \item{ms}{ Not currently used } \item{aic.mode}{ Not currently used } \item{gridwidth}{ affects grid search } \item{gridsize}{ affects grid search } \item{maxrecursions}{ affects grid search } \item{branch.export}{ If set to 0, returns a single estimate of the best branch lengths on the species tree. If set to 1, returns a table of equally-good branch lengths. If set to 2, returns a table of the best and neighboring branch lengths, suitable for doing a contour plot of score versus branch lengths } \item{usetempfile}{ Should a tempfile be written to (instead of file). Not currently used. } } \details{ Instructs Brownie to perform a heuristic search on \code{obj} when \code{obj} is run. %% From brownie command-line: %% \begin{tabular}{l | c | r} %% Keyword & Option type & Current setting \\ %% \hline %% NReps & <integer-value> & 5 \\ %% RearrLimit & <integer-value>|None & None \\ %% MaxNumSpp & <integer-value> & 100 \\ %% MinNumSpp & <integer-value> & 1 \\ %% MinSamp & <integer-value> & 3 \\ %% StructWt & <double> & 0.5 \\ %% PThreshold & <double> & 1.0 \\ %% Subsample & <double> & 2.0 \\ %% MoveFreq & (number number number number number [number]) & (0.8 0.01 0.01 0.01 0.17 0.0 ) \\ %% File & <file-name> & besttrees.tre \\ %% ShowTries & No|Yes & No \\ %% AIC_mode & 0|1|2|3|4 & 4 \\ %% GridWidth & <double> & 10.0 \\ %% GridSize & <integer-value> & 15.0 \\ %% MaxRecursions & <integer-value> & 20 \\ %% Branch_export & 0|1|2 & 2 \\ %% \hline %% \end{tabular} } \value{ Returns the original object (\code{obj}) with 'hs' command added. } \references{ %% ~put references to the literature/web site here ~ } \author{ J. Conrad Stack } \note{ %% ~~further notes~~ } %% ~Make other sections like Warning with \section{Warning }{....} ~ \seealso{ %% ~~objects to See Also as \code{\link{help}}, ~~~ } \examples{ data(parrot) ptmp = clearCommands(parrot) ptmp = addHS(ptmp,file="besttrees.tre2") commands(ptmp) } % Add one or more standard keywords, see file 'KEYWORDS' in the % R documentation directory. \keyword{ methods }
5b4a0c0e9b5498b16d27259a8eda75dfe43afed4
9327560c9c09fbf7670e6723d7a821352906d875
/Matrices/NamingMatrix.R
32f108baf3b2b988d733f7a3ef2232cb5cdfc988
[ "Apache-2.0" ]
permissive
Siddharth1698/R-programming---A-TO-Z---For-Data-Science
5037f90824ebdcc4be7facc5401915d7dd4de659
63b127ecaeae86d6d7cb8497e9aca698fe94b8ec
refs/heads/master
2020-05-26T09:30:00.537644
2019-06-02T20:12:32
2019-06-02T20:12:32
188,186,917
0
0
null
null
null
null
UTF-8
R
false
false
198
r
NamingMatrix.R
tempRec <- rep(c("a","B","zZ"),each = 3) tempRec Bravo <- matrix(tempRec,3,3) Bravo rownames(Bravo) <- c("HOW","ARE","YOU") Bravo colnames(Bravo) <- c("x","Y","Z") Bravo Bravo["HOW","Y"] <- 0 Bravo
07c994ddff9121a85e03dcdc9043ba277b027126
2448d4800d4336b53489bcce3c17a32e442a7716
/man/install_version.Rd
97dcc424d532dfdc930e4597dd3c25def712e33f
[]
no_license
vsbuffalo/devtools
17d17fd1d2fb620fef8d9883dffed389f80e39fb
782e6b071d058eea53aae596a3c120d61df2f0b4
refs/heads/master
2020-12-24T10:41:24.637105
2016-02-18T14:03:05
2016-02-18T14:03:05
52,121,375
2
0
null
2016-02-19T22:42:43
2016-02-19T22:42:43
null
UTF-8
R
false
true
1,748
rd
install_version.Rd
% Generated by roxygen2: do not edit by hand % Please edit documentation in R/install-version.r \name{install_version} \alias{install_version} \title{Install specified version of a CRAN package.} \usage{ install_version(package, version = NULL, repos = getOption("repos"), type = getOption("pkgType"), ...) } \arguments{ \item{package}{package name} \item{version}{If the specified version is NULL or the same as the most recent version of the package, this function simply calls \code{\link{install}}. Otherwise, it looks at the list of archived source tarballs and tries to install an older version instead.} \item{repos}{ character vector, the base URL(s) of the repositories to use, e.g., the URL of a CRAN mirror such as \code{"http://cran.us.r-project.org"}. For more details on supported URL schemes see \code{\link{url}}. Can be \code{NULL} to install from local files, directories or URLs: this will be inferred by extension from \code{pkgs} if of length one. } \item{type}{character, indicating the type of package to download and install. Will be \code{"source"} except on Windows and some OS X builds: see the section on \sQuote{Binary packages} for those. } \item{...}{Other arguments passed on to \code{\link{install}}.} } \description{ If you are installing an package that contains compiled code, you will need to have an R development environment installed. You can check if you do by running \code{\link{has_devel}}. } \author{ Jeremy Stephens } \seealso{ Other package installation: \code{\link{install_bitbucket}}, \code{\link{install_github}}, \code{\link{install_git}}, \code{\link{install_svn}}, \code{\link{install_url}}, \code{\link{install}}, \code{\link{uninstall}} }
1c668fbb38be00e0ceab5fb3991bef60760fe99b
ffdea92d4315e4363dd4ae673a1a6adf82a761b5
/data/genthat_extracted_code/futile.any/examples/anylength.Rd.R
a121c380e8c7470fd355b57b59808ac455913758
[]
no_license
surayaaramli/typeRrh
d257ac8905c49123f4ccd4e377ee3dfc84d1636c
66e6996f31961bc8b9aafe1a6a6098327b66bf71
refs/heads/master
2023-05-05T04:05:31.617869
2019-04-25T22:10:06
2019-04-25T22:10:06
null
0
0
null
null
null
null
UTF-8
R
false
false
246
r
anylength.Rd.R
library(futile.any) ### Name: anylength ### Title: Get the generic length of an object ### Aliases: anylength ### Keywords: attribute ### ** Examples m <- matrix(c(1,2,3,4,5,6), ncol=2) anylength(m) v <- c(1,2,3,4,5) anylength(v)
2c3457b170f1d2865d416929f6244bd55056d2c9
dd8132404e8c7b028cb13cba904c50aace01c6a7
/swt/src/spc/se.u/se_mod3.r
5128171d39110feb4a6643f4db1d39792021dc0e
[]
no_license
arnoldrobbins/gt-swt
d0784d058fab9b8b587f850aeccede0305d5b2f8
2922b9d14b396ccd8947d0a9a535a368bec1d6ae
refs/heads/master
2020-07-29T09:41:19.362530
2019-10-04T11:36:01
2019-10-04T11:36:01
209,741,739
15
0
null
null
null
null
UTF-8
R
false
false
796
r
se_mod3.r
include "source/copy.r" include "source/cprow.r" include "source/dohelp.r" include "source/display_message.r" include "source/domark.r" include "source/doopt.r" include "source/dosopt.r" include "source/dotlit.r" include "source/getrange.r" include "source/xindex.r" include "source/makset.r" include "source/doundo.r" include "source/draw_box.r" include "source/getstr.r" include "source/getwrd.r" include "source/join.r" include "source/litmesg.r" include "source/move.r" include "source/settab.r" include "source/uniquely_name.r" include "source/getkn.r" include "source/pvem.r" include "source/saynum.r" include "source/knscan.r" include "source/doglob.r" include "source/doshell.r" include "source/whereami.r"
b9be64d14d9511e0ef20b9e82098507188f8f49e
4a5266dbc98a6b96ccd2204b17ebe4994480904a
/tests/testthat/test_middle_date.R
74ea047cae437a64e78d25757ced1d6b11827035
[ "MIT" ]
permissive
piotr-ole/gantt
3a454b89ddae8fa5a33a0336b0e41bb1e70697ba
e59e27b8abf7ba7b9c8da0a299862ce08caf7af1
refs/heads/master
2020-09-13T12:56:50.945369
2020-01-22T14:23:38
2020-01-22T14:23:38
222,786,863
7
0
null
null
null
null
UTF-8
R
false
false
238
r
test_middle_date.R
test_that("calculate middle date", { expect_equal(middle_date(as.Date('2020-01-01'), as.Date('2020-01-03')), as.Date('2020-01-02')) expect_equal(middle_date(as.Date('2020-01-01'), as.Date('2020-01-04')), as.Date('2020-01-03')) })
4761560270bebcfccf9f985d0a53a4146ca763cc
18492dec7cab25005f797a8e36f207c7d228a107
/plot4.R
2cf10506562d8e15245dce1a966f193c7f29723a
[]
no_license
rhosek/homework
19ad971137b593ee9cf2a31106a70c7395f4a99a
5927e48ed8d9c57076e5cf658c720af1343e118f
refs/heads/master
2016-09-02T02:38:41.755958
2015-10-18T23:23:44
2015-10-18T23:23:44
42,406,600
0
0
null
null
null
null
UTF-8
R
false
false
2,924
r
plot4.R
## First, download the zipped data file to 'downloads' directory using the given link and then extract the file ## Change the R working directory to 'downloads/exdata-data-household_power_consumption' to read in the portion of the file of interest setwd("C:/Users/Ronald/Downloads/exdata-data-household_power_consumption") ## Read the first 20 lines of file to see header and file organization ## The file is sequential in time with one entry per minute. In other words, each minute is one row in file. ## The Date and time sampling starts on 12/16/2006 at approximately 17:24 ## We are only interested in values sampled on 2/1 and 2/2/2007 ## At one sample/minute, there will be 24 x 60 = 1440 samples/day ## We would like to skip X lines in the file to get us near 2/1 ## We then read at least 2 x 1440 lines to make sure we include all of the samples for 2/1 and 2/2 ## There are approximately 46 days and 7 hours from the time the file starts to the beginning of 2/1 ## This translates to 66,600 minutes. So we will skip 66,600 lines and then read the next 3000 ## This should give us a dataframe with the records we need which can be sub-setted to get only 2/1 and 2/2. df1 <- read.table("household_power_consumption.txt", header = TRUE, sep = ";", na.strings = "?", skip=66600, nrow = 3000) ## We also need to get the right variable (column) names. df2 <- read.table("household_power_consumption.txt", header = TRUE, sep = ";", nrow = 3) n <- names(df2) names(df1) <- n ## Change the working directory back to homework setwd("~/R/Homework") ## Get lubridate for handling date-time variables library(dplyr) library(lubridate) ## create df3 to keep df1 intact df3 <- df1 df3$Date <- dmy(df3$Date) ## subset for the two days of interest df3 <- subset(df3, df3$Date > dmy("31/1/2007") & df3$Date < dmy("3/2/2007")) par(mfcol = c(2,2)) par(mar=c(3, 3, 2, 2), ps = 12, pty = "s") plot(df3$Global_active_power, type="l", pch=0, ylab="Global Active Power", xaxt='n') axis(1, c(1, 1440,2880), c("Thu","Fri", "Sat")) par(mar=c(3, 3, 2, 2), ps = 12, pty = "s") plot(df3$Sub_metering_1,type="l", pch=0, ylab="Energy Sub Metering", xaxt='n', col="black") points(df3$Sub_metering_2,type="l", pch=0, col="red") points(df3$Sub_metering_3,type="l", col="blue") axis(1, c(1, 1440,2880), c("Thu","Fri", "Sat")) legend("topright", inset=0, cex = .5, c("Sub_metering_1", "Sub_metering_2","Sub_metering_3"), lty=c(1,1,1), col=c("black","red","blue"), horiz=FALSE, bty="n") par(mar=c(4, 3, 2, 2), ps = 12, pty = "s") plot(df3$Voltage,type="l", pch=0, ylab="Voltage", xlab = "datetime", xaxt='n') axis(1, c(1, 1440,2880), c("Thu","Fri", "Sat")) par(mar=c(4, 3, 2, 2), ps = 12, pty = "s") plot(df3$Global_reactive_power, type="l", pch=0, ylab = "Global_reactive_power", xlab = "datetime", xaxt='n') axis(1, c(1, 1440,2880), c("Thu","Fri", "Sat")) dev.print(png, "plot4.png", width = 480, height = 480, units = "px")
472b843d5cbef8efa90bd55614f044a7d9939e67
c1a4c35179dd8862fbc40b09eea92e3f491a81e3
/tests/testthat.R
50c2d1b80ba42a871ae9914f708988c89eb7dc00
[ "MIT" ]
permissive
sdhutchins/documenteR
3a5f16dbcbdb2b0369572d459e40fa28abb5e74d
461d25295ec2bb58a4e7ad95311d4b53a07c670d
refs/heads/master
2020-03-27T17:11:12.483900
2019-05-07T19:02:09
2019-05-07T19:02:09
146,833,831
2
0
null
null
null
null
UTF-8
R
false
false
64
r
testthat.R
library(testthat) library(documenteR) test_check("documenteR")
e529415651e823d04dba2b7961b9cf7e0f5351ba
867acb8f398b7d8b04670c5be619aec972fb7415
/week-3/cachematrix.R
0680586b9f257ffffade8f13b7a82c526fda5915
[]
no_license
rlambert2/rprogramming
aeb3a44f23b339d2d65f769dcfb6adbec132f1c8
daf67dd033ef0518d009654ece3cd5198311c639
refs/heads/master
2021-05-03T04:52:57.274529
2016-09-30T01:00:06
2016-09-30T01:00:06
69,115,368
0
0
null
null
null
null
UTF-8
R
false
false
1,158
r
cachematrix.R
## These functions create a matrix object that caches its inverse, ## then computes the inverse of the matrix, and checks to see if that value ## is in the cache. If it is, it returns the cached value. If it's not ## it returns the newly calculated value. ## makeCacheMatrix creates a matrix object that caches its inverse, and ## makes a list of functions that will be used in the cacheSolve function. makeCacheMatrix <- function(x = matrix()) { inv = NULL set = function(y) { x <<- y inv <<- NULL } get = function() x setinv = function(inverse) inv <<- inverse getinv = function() inv list(set=set, get=get, setinv=setinv, getinv=getinv) } ## cacheSolve checks to see if the inverse of this matrix ## has been cached. If it has, it returns the cached matrix. ## If it hasn't, it calcs and returns the inverse of the matrix. cacheSolve <- function(x, ...) { ## Return a matrix that is the inverse of 'x' inv = x$getinv() if (!is.null(inv)){ message("getting cached data") return(inv) } mat.data = x$get() inv = solve(mat.data, ...) x$setinv(inv) inv }
bc9267d4244437bb2613687a403cdd9ea25a2f30
020dd885e28b843c8eccc7fbcf0ea74c0f64d2bc
/Analyze.R
d8e14e8248c3adb30fb020aa81d4695aa5d76b96
[]
no_license
MUST-learning/R-studio
c28a3a22de66ba0cc6a8feb6632fb6a39141118c
0b7b6d4b822c941783d550aa25d69aa0cd9ad8e4
refs/heads/master
2021-07-21T18:22:51.209471
2017-11-01T02:23:15
2017-11-01T02:23:15
105,896,570
0
0
null
null
null
null
ISO-8859-3
R
false
false
4,032
r
Analyze.R
#read the data gcds <- read.csv("crdds.csv", header=TRUE, sep=",") # get columns' name and descriptions source("readcolnames.R") # load the definition of functions defined in a file colinf <- readcolnames() colnames(gcds) <- append(colinf[[2]], 'Class') coldes <- append(colinf[[1]], 'Class') # Describe data #descriptive statistics£Ĵone by one #This one is not recommended, interval is more suitable table(data1$credit_usage) barplot(table(data1$credit_usage)) library(ggplot2) # suppressMessages(library(ggplot2)) # The good and bad customers freq = tabulate(gcds$Class) # mydata$v1 <- factor(mydata$v1, # levels = c(1,2,3), # labels = c("red", "blue", "green")) pie <- ggplot(gcds, aes(x="", fill = factor(Class))) + geom_bar(width=1) + coord_polar(theta = "y") + # theme_void() + labs(x = "") + scale_fill_discrete(name="Class", breaks=c("1", "2"), labels=c("good", "bad")) + theme(axis.title.x=element_blank(), axis.ticks.x=element_blank()) + theme(legend.position = c(0.9, 0.9), plot.title = element_text(hjust = 0.5)) + ggtitle("Distribution of Class") + annotate("text", x=1, y=700, label="bad=243") + annotate("text", x=1, y=150, label="good=557") print(pie) # Sampling # tranform character column to factor coltypes <- sapply(gcds, mode) for (i in 1:ncol(gcds)) { if (coltypes[[i]] == "character") gcds[[i]] <- factor(gcds[[i]]) } # gcds$Class[gcds$Class == 1] <- 'Good' # gcds$Class[gcds$Class == 2] <- 'Bad' gcds$Class <- factor(gcds$Class, levels=c(1,2), labels=c("Good", "Bad")) set.seed(2) ids <- 1:nrow(gcds) trainratio <- 0.8 trainids <- sample(ids, trunc(length(ids)*trainratio)) trainset <- gcds[trainids, ] testset <- gcds[-trainids, ] # head(trainset, 2) # Feature Selection library(caret) # library(class) library(LiblineaR) # gcds2 <- gcds[complete.cases(gcds), ] control <- trainControl(method="repeatedcv", number=5, repeats=4) model <- train(Class~., data=trainset, method="regLogistic", trControl=control) importance <- varImp(model, scale=FALSE) # print(importance) plot(importance) # Modeling # Select top 10 important features fbyimp <- row.names(importance[[1]]) top15 <- fbyimp[1:15] selfeas <- c(top15, "Class") # decision tree model library(tree) treemodel <- tree(Class ~ ., data=trainset[,selfeas]) #train the model plot(treemodel, main="classification tree") text(treemodel, pretty=0) cprob <-predict(treemodel, testset[, top15]) chat <- rep("Good", nrow(cprob) ) chat[cprob[,1]>=0.5] <- "Bad" chat0 <- factor(chat,labels = c("Good","Bad")) #ROCR 0.734 library(ROCR) tab <- table(chat0, testset$Class) print(tab) pred <- prediction(as.numeric(chat0), as.numeric(testset$Class)) pref <- performance(pred, "tpr", "fpr") auc <- performance(pred, "auc") print(auc@y.values) plot(pref) # support vector machine 0.694 control <- trainControl(method="cv", savePredictions = T, classProbs = T) svmmodel <- train(Class~., data=trainset[, selfeas], method="svmRadialSigma", trControl=control) chat <- predict(svmmodel, newdata = testset[, top15]) tab <- table(chat, testset$Class) print(tab) pred <- prediction(as.numeric(chat), as.numeric(testset$Class)) pref <- performance(pred, "tpr", "fpr") auc <- performance(pred, "auc") print(auc@y.values) plot(pref) # neural networks model 0.744 library(caret) parameters<- expand.grid(.decay = c(0.5, 0.1), .size = c(5, 6, 7)) nnmodel <- train(trainset[, top15], trainset[,"Class"], method="nnet", tuneLength = 10, trace = F, maxit = 1000, tuneGrid= parameters) chat <- predict(nnmodel, newdata = testset[, top15]) tab <- table(chat, testset$Class) print(tab) pred <- prediction(as.numeric(chat), as.numeric(testset$Class)) pref <- performance(pred, "tpr", "fpr") auc <- performance(pred, "auc") print(auc@y.values) plot(pref)
a8576e0bdee8ee22e913adf0f7e82fb238f97de0
e573dd102635ce15f9270cc4ab91a6a3d1878979
/R/read-any-bitmap.R
e8f41fa2d19db6a9c98cb80e1da4e87faa2b2ad4
[]
no_license
jefferis/readbitmap
c0dd88f813f44480217744b31f8531dd0b8d4c16
9e4080ef73f4d689c616fde7a5530996580aea16
refs/heads/master
2021-01-23T03:28:43.142674
2018-06-27T11:48:41
2018-06-27T11:48:41
2,964,648
2
3
null
2018-05-21T11:52:24
2011-12-12T14:27:24
R
UTF-8
R
false
false
3,862
r
read-any-bitmap.R
# Functions to identify and read a variety of bitmap image formats. ############################################################################### #' Identify the type of an image using the magic value at the start of the file #' #' Currently works for png, jpeg, BMP, and tiff images. Will seek to start of #' file if passed a connection. For details of magic values for files, see e.g. #' \url{http://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files} #' @param source Path to file or connection #' @param Verbose Whether to write a message to console on failure (Default #' \code{FALSE}) #' @return character value corresponding to standard file extension of image #' format (i.e. jpg, png, bmp, tif) or \code{NA_character_} on failure. #' @export #' @examples #' jpegfile=system.file("img", "Rlogo.jpg", package="jpeg") #' image_type(jpegfile) #' jpeg_pretending_to_be_png=tempfile(fileext = '.png') #' file.copy(jpegfile, jpeg_pretending_to_be_png) #' image_type(jpeg_pretending_to_be_png) #' unlink(jpeg_pretending_to_be_png) image_type<-function(source,Verbose=FALSE){ if (inherits(source, "connection")) seek(source, 0) magic = readBin(source, what = 0L, n = 8, size = 1L, signed = FALSE) if(isTRUE(all.equal(magic[1:2], c(66, 77)))) return('bmp') else if(isTRUE(all.equal(magic[1:8], c(0x89,0x50,0x4E,0x47,0x0D, 0x0A, 0x1A, 0x0A))) ) return('png') else if(isTRUE(all.equal(magic[1:2], c(0xFF, 0xD8)))) return('jpg') else if(isTRUE(all.equal(magic[1:4], c(0x49, 0x49, 0x2A, 0x00)))) return('tif') else if(isTRUE(all.equal(magic[1:4], c(0x4D, 0x4D, 0x00, 0x2A)))) return('tif') # otherwise we failed to identify the file if(Verbose) warning("Failed to identify image type of: ",source, ' with magic: ',format.hexmode(as.raw(magic))) return(NA_character_) } #' Read in a bitmap image in JPEG, PNG, BMP or TIFF format #' #' By default uses magic bytes at the start of the file to identify the image #' type (rather than the file extension). Currently uses readers in bmp, jpeg, #' png, and tiff packages. #' @param f Path to image file #' @param channel Integer identifying channel to return for an RGB image #' @param IdentifyByExtension Identify by file extension only (Default FALSE) #' @param ... Additional parameters passed to underlying image readers #' @return Objects returned by \code{\link[jpeg]{readJPEG}}, #' \code{\link[png]{readPNG}}, \code{\link[bmp]{read.bmp}}, or #' \code{\link[tiff]{readTIFF}}. See their documentation for details. #' @importFrom png readPNG #' @importFrom jpeg readJPEG #' @importFrom bmp read.bmp #' @importFrom tiff readTIFF #' @export #' @seealso \code{\link{image_type}}, \code{\link[jpeg]{readJPEG}}, #' \code{\link[png]{readPNG}}, \code{\link[bmp]{read.bmp}}, #' \code{\link[tiff]{readTIFF}} #' @examples #' img1=read.bitmap(system.file("img", "Rlogo.jpg", package="jpeg")) #' str(img1) #' img2 <- read.bitmap(system.file("img", "Rlogo.png", package="png")) #' # nb the PNG image has an alpha channel #' str(img2) read.bitmap<-function(f,channel,IdentifyByExtension=FALSE,...){ if(!file.exists(f)) stop("File: ",f," does not exist.") if(IdentifyByExtension) ext=tolower(sub(".*\\.([^.]+)$","\\1",f)) else ext=image_type(f) readfun=switch(ext,png=readPNG,jpeg=readJPEG,jpg=readJPEG,bmp=read.bmp, tif=readTIFF,tiff=readTIFF, stop("File f: ",f," does not appear to be a PNG, BMP, JPEG, or TIFF")) im=readfun(f,...) if(!missing(channel) && length(dim(im))==3) im=im[,,channel] #BMP stores the alpha channel first (ARGB order), convert to RGBA for consistency with PNG files if (ext=="bmp" && (length(dim(im))==3) && dim(im)[3] == 4) { att <- attributes(im) im <- array(c(im[,,2:4],im[,,1]),dim(im)) attributes(im) <- att } im }
b75c90d7810e252b5062719b59c23e3c259f7bd5
502ab31e267cf5096b01ce1ccb97fd36ace11ee9
/4. extract_CUSIP.R
ee19dcf89f343fec3fd14b2afd8a5a851f57f408
[]
no_license
SpyridonGkikopoulos/Block_Codes
3cf2fee5c638d8b293008cd44e528e925cbc37fc
e1e5142bd6647b4004c2c76c326032f16415e926
refs/heads/master
2023-06-11T21:51:44.523883
2021-07-06T04:46:40
2021-07-06T04:46:40
null
0
0
null
null
null
null
UTF-8
R
false
false
2,932
r
4. extract_CUSIP.R
start_QTR <- "2018Q4" end_QTR <- "2018Q4" ### use this dir to download files out_dir <- "/Users/evolkova/Documents/Blocks/" ### generate all dates get_dates <- function(start_QTR, end_QTR) { require(data.table) require(zoo) require(lubridate) require(dplyr) end_QTR <- end_QTR %>% as.yearqtr("%YQ%q") %>% as.Date() all_dates <- start_QTR %>% as.yearqtr("%YQ%q") %>% as.Date() while (all_dates[length(all_dates)] < ymd(end_QTR)) { all_dates <- c(all_dates, all_dates[length(all_dates)] %m+% months(3)) } return(all_dates) } ### regex to extract CUSIP from filing extract_CUSIP <- function(EFiling) { require(stringr) ## get 6 lines before and 4 lines after line CUSIP pat_1 <- "((\\n.*){6})CUSIP.*((\\n.*){4})" get_block <- str_extract(EFiling, pat_1) # set pattern to extract CUSIP pat_2 <- "(?=\\d.*\\d)[a-zA-Z0-9]{9}|\\d\\w{6} \\w\\w \\w|\\d\\w{5} \\w\\w \\w| [a-zA-Z0-9]{7}\\r|\\d\\w{5} \\w\\w\\w|(?=#.*\\d)[a-zA-Z0-9]{9}|(?=\\w\\d.*)[a-zA-Z0-9]{9}| \\d\\w{5}-\\w\\w-\\w|\\d\\w{5}-\\w\\w\\w|\\d\\w{6}|\\d\\w{5}-\\w{2}-\\w|\\d\\w{5}\\n.*\\n.*| \\d\\w{2} \\d\\w{2} \\d\\w{2}|\\d\\w{2} \\w{3} \\d{2} \\d|\\d{6} \\d{2} \\d| \\d\\w{4} \\w{1} \\w{2} \\w|\\w{6} \\d{2} \\d{1}|\\d{3} \\d{3} \\d{3}|\\d{6} \\d{2} \\d{1}| \\w{3} \\w{3} \\d{2} \\d{1}|\\w{5} \\w{1} \\d{2} \\d{1}|\\d{6} \\d{1} \\d{2}| \\d{3} \\d{3} \\d{1} \\d{2}|\\d\\w{2}\\n.*\\d\\w{2}|\\d{6} \\d{2}\\n.*|\\d{5} \\d{2} \\d{1}| \\d{5} \\w{1} \\w{2} \\w{1}|\\d\\w{5}|\\d\\w{2}-\\w{3}-\\w{3}" # Extract CUSIP from within the blocks extracted CUSIP <- str_extract(get_block, pat_2) return(CUSIP) } ### remove duplicates from CIK-CUSIP map CUSIP_table <- function(CUSIP) { require(data.table) CUSIP_df <- data.table(CUSIP) CUSIP_df[, quarter := paste0(year(dates[i]), quarter(dates[i]))] CUSIP_df[, CUSIP := gsub("\\s", "", CUSIP)] CUSIP_df[, CUSIP := gsub("-", "", CUSIP)] CUSIP_df[, CUSIP := toupper(CUSIP)] CUSIP_df[, CUSIP6 := substr(CUSIP, 1, 6)] CUSIP_df[, CUSIP := substr(CUSIP, 1, 8)] return(CUSIP_df) } CUSIP_all <- NULL dates <- get_dates(start_QTR, end_QTR) for (i in 1:length(dates)) { print(Sys.time()) print(paste0("year: ", year(dates[i]), ", quarter: ", quarter(dates[i]))) dbname <- paste0(out_dir, "Clean Forms/sc13_", year(dates[i]), quarter(dates[i]), ".sqlite") ## connect to db con <- dbConnect(drv = RSQLite::SQLite(), dbname = dbname) ## Fetch data into data frame res <- dbSendQuery(con, "SELECT * FROM filings") res1 <- dbFetch(res, n = -1) sec_name <- paste0(out_dir, "Parsed Forms/", year(dates[i]), quarter(dates[i]), ".rds") sec_header <- readRDS(sec_name) match <- match(sec_header$FILENAME, res1$FILENAME) CUSIP <- extract_CUSIP(res1$FILING) CUSIP_df <- CUSIP_table(CUSIP) sec_header$CUSIP <- CUSIP_df$CUSIP[match] sec_header$CUSIP6 <- CUSIP_df$CUSIP6[match] saveRDS(sec_header, sec_name) dbDisconnect(con) }
9597695dca4539f79193bdbe5aeb0d820776d69a
42250f07c9cd59b962e23b5f94801a195c04f6cc
/tests/testthat/test_mlr_learners_surv_glmnet.R
5374207fc3f65b4c32548ee99d1644c605c21d81
[ "LGPL-3.0-only" ]
permissive
mlr-org/mlr3survival
fbb262e6a60f02cc775f1d4e06da6ee51c9a71f1
a1cbd60a9ac9e8078daa837f6b99bf5ba2bbc45c
refs/heads/master
2020-04-06T22:55:19.048008
2019-10-21T09:09:58
2019-10-21T09:09:58
157,852,127
8
0
MIT
2019-07-01T15:33:58
2018-11-16T10:31:22
R
UTF-8
R
false
false
222
r
test_mlr_learners_surv_glmnet.R
context("surv.glmnet") test_that("autotest", { learner = mlr_learners$get("surv.glmnet") expect_learner(learner) result = run_autotest(learner, exclude = "feat_single") expect_true(result, info = result$error) })
54979b3b51e571d41c3041ed455813a725c20ad9
745295046a9499a459f379c2931db70e21cd39e3
/components-rwrapper/src/main/resources/plot_line_chart.R
43839bbfeb30dfc9d47fc7b4e52f8f5c46447113
[]
no_license
AnalyticsWorkbench/Components
bc109595c5707388ffe2c319cdbbfdadedabfde6
cd7ab7eeaed7480712a3270cc9f81af0a7041634
refs/heads/master
2022-12-09T15:05:38.538578
2019-05-23T15:23:48
2019-05-23T15:23:48
136,925,042
2
1
null
2022-12-05T23:55:36
2018-06-11T12:44:40
JavaScript
UTF-8
R
false
false
231
r
plot_line_chart.R
plot_line_chart <- function(data) { values <- c(data) plot(values[[1]],type="o") } resultData <- list(dataUrl='line.data',plotUrl='line.png') write.table(data, file="line.data") png('line.png') plot_line_chart(data) dev.off()
8725aab7d1c5ec803133edb4b8738d28e0e6c7ca
a76f598b25592f0b49bf0865b2b92dfaf92357e9
/tests/testthat/test_slise.R
c27f007aac83e4ba8e4dd87b9772c6b4ab1777e6
[ "MIT" ]
permissive
edahelsinki/slise
a22b90e0ce06223a93bcf35bde96207254a602d5
a7bc95384282168aa1642008b31d9159ab02eb72
refs/heads/master
2023-04-08T13:01:14.106004
2023-04-03T12:24:29
2023-04-03T12:24:29
203,325,030
8
1
MIT
2023-01-17T10:36:53
2019-08-20T07:39:52
R
UTF-8
R
false
false
4,408
r
test_slise.R
context("Tests for the slise algorithm") source("setup.R") test_that("Check SLISE", { for (i in c(rep(c(4, 8, 16), 2))) { data <- data_create(i * 30, i, floor(i * 0.5), 0.03, 0.3, 0.3) slise1 <- slise.fit(data$X, data$Y, epsilon = 0.1, lambda1 = 0) slise2 <- slise.fit(data$X, data$Y, epsilon = 0.1, lambda1 = 0.1) ols <- .lm.fit(data$X, data$Y)$coefficients slise1_loss <- slise1$value slise2_loss <- slise2$value ols1_loss <- loss_sharp(ols, data$X, data$Y, epsilon = 0.1, lambda1 = 0) ols2_loss <- loss_sharp(ols, data$X, data$Y, epsilon = 0.1, lambda1 = 0.1) expect_lt(slise1_loss, ols1_loss) expect_lt(slise2_loss, ols2_loss) x <- rnorm(length(data$alpha) - 1) y <- sum(x * data$alpha[-1]) + data$alpha[[1]] expl1_alpha <- slise.explain(data$X, data$Y, 0.03, x, y, 0)$coefficients expl2_alpha <- slise.explain(data$X, data$Y, 0.03, x, y, 0.1)$coefficients expect_equal(sum(expl1_alpha[-1] * x) + expl1_alpha[[1]], y) expect_equal(sum(expl2_alpha[-1] * x) + expl2_alpha[[1]], y) } }) test_that("Check SLISE formula", { data <- data.frame(y = rnorm(8), a = rnorm(8), b = rnorm(8)) model <- slise.formula(y ~ a * b + abs(a), data, 0.1, normalise = TRUE) expect_equal(length(model$coefficients), 5) expect_equal(length(model$normalised_coefficients), 5) expect_true(model$intercept) model <- slise.formula(y ~ a * b + abs(a) + 0, data, 0.1, normalise = TRUE) expect_equal(length(model$coefficients), 5) expect_equal(length(model$normalised_coefficients), 4) expect_true(model$intercept) model <- slise.formula(y ~ a * b + abs(a) + 0, data, 0.1, normalise = FALSE, lambda1 = 0.1) expect_equal(length(model$coefficients), 4) expect_false(model$intercept) model <- slise.formula(y ~ poly(a, b, degree = 2), data, 0.1, normalise = FALSE, lambda1 = 0.1) expect_equal(length(model$coefficients), 6) expect_true(model$intercept) }) test_that("Check SLISE comb", { for (i in c(rep(5, 3))) { data <- data_create(i * 30, i, floor(i * 0.5), 0.03, 0.3, 0.3) x <- data$X[1, ] y <- data$clean[1] expl1 <- slise.explain_comb(data$X, data$Y, 0.03, x, y, variables = 3) expl2 <- slise.explain_comb(data$X, data$Y, 0.10, x, y, variables = 3) expect_equal(predict(expl1, x)[[1]], y) expect_equal(predict(expl2, x)[[1]], y) expect_gte(3, sparsity(expl1$alpha[-1])) expect_gte(3, sparsity(expl2$alpha[-1])) } }) test_that("Check SLISE predict", { for (i in c(rep(c(4, 8), 2))) { data <- data_create(i * 30, i, floor(i * 0.5), 0.03, 0.3, 0.3) Y2 <- data$Y - min(data$Y) Y2 <- Y2 / max(Y2) expl1 <- slise.explain(data$X, data$Y, 0.2, data$X[1, ], data$clean[1]) expl2 <- slise.explain(data$X, Y2, 0.3, data$X[1, ], Y2[1], logit = TRUE) expl3 <- slise.explain(data$X, Y2, 0.3, 2, logit = TRUE, normalise = TRUE) fit1 <- slise.fit(data$X, data$Y, 0.1, 0.1) Y1 <- predict(expl1, data$X) Y2b <- predict(expl2, data$X) Y2c <- predict(expl3, data$X[2, ]) Y3 <- predict(fit1, data$X) expect_equal(Y1[1], data$clean[1]) expect_equal(Y2[2], c(Y2c)) expect_equal(expl1$subset, c(abs(predict(expl1, data$X) - data$Y) < expl1$epsilon)) expect_equal(expl2$subset, c(abs(predict(expl2, data$X, logit = TRUE) - expl2$Y) < expl2$epsilon)) expect_equal(expl3$subset, c(abs(predict(expl3, data$X, logit = TRUE) - expl3$Y) < expl3$epsilon)) expect_equal(fit1$subset, c(abs(predict(fit1, data$X) - data$Y) < fit1$epsilon)) } }) test_that("Check SLISE unscale", { for (i in c(rep(c(4, 8, 16), 2))) { data <- data_create(i * 30, i, floor(i * 0.3), 0.03, 0.3, 0.3) slise1 <- slise.fit(data$X, data$Y, epsilon = 0.1, normalise = TRUE) data2 <- slise.preprocess(data$X, data$Y, 0.1, intercept = TRUE, normalise = TRUE) subset1 <- mean(abs(predict(slise1, data$X) - data$Y) <= slise1$epsilon) subset2 <- mean(abs(data2$X %*% slise1$normalised_alpha - data2$Y) < slise1$normalised_epsilon) expect_equal(subset1, mean(slise1$subset)) expect_equal(subset2, mean(slise1$subset)) } })
e1ea1a9475676c1e0868310a8e48ed797be460b5
ba892b7dda59a3024307699aaee1d42d4af30e03
/manipulation/7-subsets-for-analysis.R
6715f4540e2779aa1f9a0cd4e31ec28fbe72b14e
[]
no_license
IALSA/longitudinal-response-pattern
5b9d5b3ce292b27e1eaed7b8ed9d6ee8c616fa0d
d293812cb7f0cea8d8e9a4a447bb87843f2ff24f
refs/heads/master
2020-04-09T16:52:07.699990
2016-07-15T20:06:43
2016-07-15T20:06:43
61,064,550
0
0
null
null
null
null
UTF-8
R
false
false
5,673
r
7-subsets-for-analysis.R
## Project title: MAP ## Created on: June 03 2016 ## Author: Jamie Knight ## Data: Creating final subsets for analysis. MAP for use in Thesis ## Summary: ## ---------------------------------------------------------------------- ## options(width=160) rm(list=ls()) cat("\f") # --- load-packages ------ search() # see which pachages are currently attached library(dplyr) library(magrittr) # requireNamespace("dplyr") # ----- load-data ------ getwd() #full version long ds <-readRDS("./data/unshared/derived/ds4.rds") #full version wide # dsw <-readRDS("./data/derived/ds4w.rds") #complete cases for BSIT and niareagansc # ds1 <- readRDS("./data/derived/ds4ls.rds") #complete cases for BSIT # ds2 <- readRDS("./data/derived/ds4ls2.rds") str(ds) names(ds) # ---- tweak-data ------------------- ds <- ds %>% dplyr::mutate( id = as.integer(projid) ) # ---- subset-variables-cdx-1 --------------------------------- t <- table(ds$fu_year, ds$cdx, useNA = "always"); t[t==0] <- "."; t names(ds) keep_these_ids <- ds %>% dplyr::select(id, fu_year, cdx) %>% dplyr::filter(fu_year==0, cdx == 1 ) %>% dplyr::select(id) keep_these_ids <- as.integer(keep_these_ids$id) length(unique(keep_these_ids)) # 1236 length(unique(ds$id)) # 1803 ds_subset_1 <- ds %>% dplyr::filter(id %in% keep_these_ids) length(unique(ds_subset_1$id)) ds_subset_1 %>% # dplyr::slice(1:10) dplyr::group_by(cdx) %>% dplyr::summarize(count = n()) t <- table(ds_subset_1$fu_year, ds_subset_1$cdx, useNA = "always"); t[t==0] <- "."; t names(ds) # ---- subset-variables-smell-test-2 --------------------------------- t <- table(ds$fu_year, ds$total_smell_test, useNA = "always"); t[t==0] <- "."; t t <- table(ds_subset_1$fu_year, ds_subset_1$total_smell_test, useNA = "always"); t[t==0] <- "."; t names(ds) keep_these_ids <- ds_subset_1 %>% dplyr::select(id, fu_year, total_smell_test) %>% dplyr::filter(fu_year == 0, !is.na(total_smell_test)) %>% dplyr::select(id) keep_these_ids <- as.integer(keep_these_ids$id) length(unique(keep_these_ids)) # 1054 length(unique(ds$id)) # 1803 ds_subset_2 <- ds_subset_1 %>% dplyr::filter(id %in% keep_these_ids) length(unique(ds_subset_2$id)) ds_subset_2 %>% # dplyr::slice(1:10) dplyr::group_by(total_smell_test) %>% dplyr::summarize(count = n()) t <- table(ds_subset_2$fu_year, ds_subset_2$total_smell_test, useNA = "always"); t[t==0] <- "."; t names(ds) # ---- subset-variables-smell-test-3 --------------------------------- t <- table(ds_subset_2$fu_year, ds_subset_2$total_smell_test, useNA = "always"); t[t==0] <- "."; t keep_these_ids <- ds_subset_2 %>% dplyr::select(id, fu_year, total_smell_test) %>% dplyr::group_by(id) %>% dplyr::summarize(tst_count = n()) %>% dplyr::filter(!tst_count %in% c(1,2)) %>% dplyr::select(id) keep_these_ids <- as.integer(keep_these_ids$id) length(unique(keep_these_ids)) # 890 length(unique(ds$id)) # 1803 ds_subset_3 <- ds_subset_2 %>% dplyr::filter(id %in% keep_these_ids) %>% dplyr::group_by(id) %>% dplyr::mutate(tst_count = n()) %>% dplyr::ungroup() ds_subset_3 %>% # dplyr::slice(1:10) dplyr::group_by(tst_count) %>% dplyr::summarize(count = n()) t <- table(ds_subset_3$fu_year, ds_subset_3$tst_count, useNA = "always"); t[t==0] <- "."; t names(ds) # ---- subset-base ----------------- # # # base subset should only include people who do not have dementia at baseline # #change original file ie. ds to be each of the subsets above. # # sub1<-ds # # #subset to remove any participants with dementia at baseline # #cdx is assesment while alive, 1:normal, 2-3:mild MCI, 4-5:AD # varsREM <- sub1[ which(sub1$fu_year==0 & sub1$cdx != 1),] # # # sub2 <- sub1 # for (rows in varsREM["projid"]) { # for (id in rows) { # sub2 <- sub2[sub2$projid != id, ] # } # } # # dplyr::n_distinct(sub2$projid)#ds: 1239 (564 less)|ds1:392 | ds2:1239 # dplyr::n_distinct(sub1$projid) #ds:1803 subjects | ds1:650 | ds2:1660 # dplyr::n_distinct(varsREM$projid) #ds: #564 | ds1:258 | ds2: 421 # #correct numer was removed # # #sub2 = all people who were cognitively normal at baseline # # # rename the subsets # dsbase <- sub2 # 1239 # dplyr::n_distinct(dsbase$projid) # max(dsbase$fu_year)# NA, why not working? # dsbase$projid %>% unique() %>% length() # # ds1base <- sub2 # 392, people who have BSIT and niareagansc # max(ds1base$fu_year) #17 # dplyr::n_distinct(ds1base$projid) # # ds2base<- sub2 #1239, people who have BSIT # max(ds2base$fu_year) #18 # dplyr::n_distinct(ds2base$projid) #ds and ds2 are the same number of people? #use ds1 for autopsy pathology investigation and ds2 as other # -------reshape data from long to wide------- names(ds1base) max(ds1base$fu_year) #17 measures <- names(ds1base)[c(-1,-2, -4, -6, -7, -9:-16, -28, -32, -33, -36)] measures #time varying measures ds1w <- reshape(ds1base, v.names=measures, timevar='fu_year', idvar='projid', direction="wide") names(ds1w) ####help here#### # sub out people who do not have a BSIT scores at baseline keep_ids <- ds1w[ds1w$total_smell_test.0 != is.na(), "projid"] sub1 <- ds1w %>% dplyr::filter(projid %in% keep_ids) #sub3: people who have 2 or more waves of BSIT or overall? #3sub4: people who have 3 or more waves of BSIT or overall? # ---- save --------- #save subset data saveRDS(dsbase, "./data/derived/COX/dsbase.rds") write.csv(dsbase, "./data/derived/CSV/dsbase.csv") saveRDS(ds1base, "./data/derived/COX/ds1base.rds") write.csv(ds1base, "./data/derived/CSV/ds1base.csv") saveRDS(ds2base, "./data/derived/COX/ds2base.rds") write.csv(ds2base, "./data/derived/CSV/ds2base.csv")
ebbe49ad52ab80e44a748c427cc80ad343d91f42
cdae97e4ecf760987cf8c534f24cb553e5fdf00b
/Liniar vs Multiple Liniar Regression.r
b1b64c1dab82993d22931d60607ba9975491b0e9
[]
no_license
AndraRaco/Statistics-project
4b42de91c5f78ff3085b367c2e6d019f3ad37175
333a88443275100cc27cc231fefb68cad19c1bae
refs/heads/master
2022-06-21T05:59:02.959745
2020-05-09T14:23:51
2020-05-09T14:23:51
255,165,343
0
0
null
null
null
null
UTF-8
R
false
false
5,427
r
Liniar vs Multiple Liniar Regression.r
# Import dataset dataset <- as.data.frame(Seatbelts) View(dataset) #----------------------1---------------------------- # Media penstru fiecare coloana Mean <- apply(dataset, 2, mean) View(Mean) # Dispersia Var <- var(dataset) View(Var) # Quantile Quantile <- apply(dataset, 2, quantile) View(Quantile) # Boxplot #boxplot(DriversKilled~ kms, data = dataset, xlab = "Number of drivers killed", # ylab = "Number of kms", main = "Seatbelts Data") #boxplot(DriversKilled~ drivers, data = dataset, xlab = "Number of drivers killed", # ylab = "Number of kms", main = "Seatbelts Data") #install.packages("tidyverse") boxplot(dataset$DriversKilled, main = "DriversKilled") boxplot(dataset$drivers, main = "drivers") boxplot(dataset$rear, main = "rear") boxplot(dataset$front, main = "front") boxplot(dataset$kms, main = "kms") boxplot(dataset$PetrolPrice, main = "PetrolPrice") boxplot(dataset$VanKilled, main = "VanKilled") #install.packages('ggplot2') library(ggplot2) ggplot(dataset, aes(x = factor(law), y = DriversKilled)) + geom_boxplot(fill = "pink") + ylab ("Monthly Driver Mortality") + xlab("Before and after law introduced") boxplot(dataset$DriversKilled, main = "DriversKilled") boxplot(dataset$drivers, main = "drivers") boxplot(dataset$rear, main = "rear") boxplot(dataset$front, main = "front") boxplot(dataset$kms, main = "kms") boxplot(dataset$PetrolPrice, main = "PetrolPrice") boxplot(dataset$VanKilled, main = "VanKilled") boxplot( dataset$DriversKilled ~ dataset$law, xlab = "law", ylab = "Drivers killed", main = "Drivers killed vs law", las = 1 ) #----------------------2---------------------------- #Simple Linear Regression library(caTools) split = sample.split(dataset$DriversKilled, SplitRatio = 2/3) training_set = subset(dataset, split == TRUE) test_set = subset(dataset, split == FALSE) #Fitting Multiple Linear regression to the Training Set regressor2 = lm(formula = DriversKilled ~ drivers , data = training_set) #Predicting the Test set results y_pred2 = predict(regressor2, newdata = test_set) # Visualising the Training set results library(ggplot2) ggplot() + geom_point(aes(x = training_set$drivers, y = training_set$DriversKilled), colour = 'red') + geom_line(aes(x = training_set$drivers, y = predict(regressor2, newdata = training_set)), colour = 'blue') + ggtitle('DriversKilled vs Drivers (Training set)') + xlab('Drivers') + ylab('DriversKilled') # Visualising the Test set results library(ggplot2) ggplot() + geom_point(aes(x = test_set$drivers, y = test_set$DriversKilled), colour = 'red') + geom_line(aes(x = training_set$drivers, y = predict(regressor2, newdata = training_set)), colour = 'blue') + ggtitle('DriversKilled vs Drivers (Test set)') + xlab('Drivers') + ylab('DriversKilled') #Multiple Linear Regression #Splitting the dataset into the Training set and Test set library(caTools) split = sample.split(dataset$DriversKilled, SplitRatio = 2/3) training_set = subset(dataset, split == TRUE) test_set = subset(dataset, split == FALSE) #Fitting Multiple Linear regression to the Training Set regressor = lm(formula =DriversKilled ~ ., data = training_set) summary(regressor) #Predicting the Test set results y_pred = predict(regressor, newdata = test_set) #Building the optimal model using Backward Elimination regressor=lm(formula=DriversKilled ~ drivers + front + kms + PetrolPrice + VanKilled + law ,data=dataset) summary(regressor) regressor=lm(formula=DriversKilled ~ drivers + kms + PetrolPrice + VanKilled + law ,data=dataset) summary(regressor) regressor=lm(formula=DriversKilled ~ drivers + kms + VanKilled + law ,data=dataset) summary(regressor) regressor=lm(formula=DriversKilled ~ drivers + kms + law ,data=dataset) summary(regressor) regressor=lm(formula=DriversKilled ~ drivers + kms ,data=dataset) summary(regressor) modelSummary <- summary(regressor) # capture model summary as an object for multiple liniar regression modelSummary2 <- summary(regressor2) # capture model summary as an object for simple liniar regression #R squared test modelSummary2$r.squared modelSummary$r.squared #Adjusted R squared test modelSummary2$adj.r.squared modelSummary$adj.r.squared #AIC test AIC(regressor2) AIC(regressor) #BIC test BIC(regressor2) BIC(regressor) #F statistic test modelSummary2$fstatistic[1] modelSummary$fstatistic[1] #Standard error modelCoeffs2 <- modelSummary2$coefficients # model coefficients SLR(simple liniar regression) beta.estimate2 <- modelCoeffs2["drivers", "Estimate"] # get beta estimate for DriversKilled std.error2 <- modelCoeffs2["drivers", "Std. Error"] # get std.error for DriversKilled std.error2 modelCoeffs <- modelSummary$coefficients # model coefficients MLR(multiple liniar regression) beta.estimate <- modelCoeffs["drivers", "Estimate"] # get beta estimate for DriversKilled std.error <- modelCoeffs["drivers", "Std. Error"] # get std.error for DriversKilled std.error #----------------------3---------------------------- library(DiscreteLaplace) # The Probability mass function p<-0.7 q<-0.45 x<--15:15 prob<-ddlaplace(x, p, q) plot(x, prob, type="h", main="The Probability mass function") # The cumulative distribution function cmd<-pdlaplace(x, p, q) plot(x,cmd,main="The cumulative distribution function")
4311de60d85fc663f3111b3a00dd6d6619c8f73b
56e22dd051b4ecc6bf96a7fa93d6dcecc74eebcb
/man/install_goldman_sans.Rd
78c9e3ed88db649154cf8e47588b988fd25f5fa5
[ "MIT" ]
permissive
yjunechoe/hrbragg
44337b14d1a23b3d3757ac5dae3c2899913ff01b
8f8b1f098d02329632fff26a89083237fa8cc75f
refs/heads/master
2023-06-14T13:32:21.889462
2021-07-10T12:36:19
2021-07-10T12:36:19
null
0
0
null
null
null
null
UTF-8
R
false
true
829
rd
install_goldman_sans.Rd
% Generated by roxygen2: do not edit by hand % Please edit documentation in R/install-fonts.R \name{install_goldman_sans} \alias{install_goldman_sans} \alias{install_goldman_sans_condensed} \title{Install Goldman Sans} \usage{ install_goldman_sans() install_goldman_sans_condensed() } \description{ Goldman Sans is a clean, modern typeface designed for dense data-rich environments. From open letter shapes, enlarged x-height, and optical balancing of individual letterforms, we designed Goldman Sans with clarity in mind. Both normal and condensed versions are provided. } \note{ \href{https://design.gs.com/d/legal/goldman-sans-license}{Goldman Sans Restricted Font License} } \examples{ install_goldman_sans() install_goldman_sans_condensed() } \references{ \href{https://design.gs.com/d/story/goldman-sans/}{Goldman Sans} }
ed4a92b285a9ca4c091a56e6a0773dc27d301fa9
b53beb0e3daa03b1d5aca5d8c0737737ebd919b5
/aggregateSummary.R
7be31dc6735e1944e9fabc76ca501538842241b9
[ "MIT" ]
permissive
manning-lab/aggregateAssociation
0fa3d102dd9621bd4dbd95d54af0cbe2aba2c54c
6897d7f4b42cc8898b3f2a06e93d081562f0bfe2
refs/heads/master
2021-07-10T23:45:20.904315
2018-09-21T16:34:03
2018-09-21T16:34:03
125,053,850
1
1
MIT
2018-03-22T15:47:14
2018-03-13T13:13:06
R
UTF-8
R
false
false
5,279
r
aggregateSummary.R
# summary.R # Description: Generate a summary of association results including quantile-quantile and manhattan plots for all groups. Also generates CSV files of all associations. # Inputs: # label : prefix for output filename (string) # assoc.files : comma separated list of association results, output of aggAssocTest (string) # Check if required packages are installed packages <- c("qqman","data.table","stringr") to_install <- packages[!(packages %in% installed.packages()[,"Package"])] if(length(to_install)) install.packages(to_install,repos='http://cran.us.r-project.org') # Load packages lapply(packages, library, character.only = TRUE) # Parse inputs input_args <- commandArgs(trailingOnly=T) label <- input_args[1] assoc.files <- unlist(strsplit(input_args[2],",")) minmac <- as.numeric(input_args[3]) var.info <- list() # remove any empty files because R apparently can't handle loading an empty file. info = file.info(assoc.files) assoc.files = rownames(info[!(info$size == 0), ]) if (length(assoc.files) == 0){ fwrite(list(),paste(label, ".assoc.csv", sep=""),sep=",",row.names=F) fwrite(list(), paste(label, ".topassoc.csv", sep=""),row.names=F) png(filename = paste(label,".association.plots.png",sep=""),width = 11, height = 11, units = "in", res=800, type = "cairo") dev.off() } else { # Prep for association files assoc.compilation <- c() # Loop through association files for (i in seq(1,length(assoc.files))) { load(assoc.files[i]) # get group results res <- assoc$results # get variant info for each group var.list <- list() for (g in names(assoc$variantInfo)){ df <- assoc$variantInfo[[g]] if (NROW(df) == 0){ next } df$group <- g df$pval <- res[rownames(res) == g,"pval_0"] var.list[[g]] <- df } var.df <- do.call(rbind,var.list) var.info[[i]] <- var.df if (!is.na(res)[1]){ print(dim(res)) res <- res[!is.na(res[,"pval_0"]),] # add chromosome and minimum position to results chrs <- c() pos <- c() for (g in rownames(res)){ chrs <- c(chrs,var.df[var.df$group == g,]$chr[1]) pos <- c(pos,min(var.df[var.df$group == g,]$pos)) } res$chr <- chrs res$pos <- pos assoc.compilation <- rbind(assoc.compilation, res) if (i == 1) { write.table(res,paste(label, ".assoc.csv", sep=""),sep=",",row.names=F) } else { write.table(res,paste(label, ".assoc.csv", sep=""),col.names=FALSE,sep=",",row.names=F, append=TRUE) } } } } assoc.compilation <- assoc.compilation[!is.na(assoc.compilation$pval_0),] assoc.compilation$chr <- ifelse(assoc.compilation$chr == "X", 23, as.numeric(assoc.compilation$chr)) # Calculate genomic control lam = function(x,p=.5){ x = x[!is.na(x)] chisq <- qchisq(1-x,1) round((quantile(chisq,p)/qchisq(p,1)),2) } png(filename = paste(label,".association.plots.png",sep=""),width = 11, height = 22, units = "in", res=800, type = "cairo") par(mfrow=c(2,1)) # qq plot qq(as.numeric(assoc.compilation[,"pval_0"]),main=label) legend('topleft',c(paste0("GC = ", lam(assoc.compilation[,"pval_0"])))) manhattan(assoc.compilation,chr="chr",bp="pos",p="pval_0", main=label) dev.off() assoc.compilation$MarkerName <- rownames(assoc.compilation) write.csv(assoc.compilation, paste(label, ".groupAssoc.csv", sep=""),row.names=FALSE,quote=FALSE) var.df = do.call(rbind,var.info) fwrite(var.df, file = paste(label, ".all.variants.groupAssoc.csv", sep=""), row.names = F) # now make the mac thresholded plots var.df$mac <- 2*var.df$n.obs*var.df$freq cummac <- data.frame(group = row.names(assoc.compilation), cummac = NA, stringsAsFactors = F) # get cum mac per group for (gind in seq(1,nrow(assoc.compilation))){ g <- row.names(assoc.compilation)[gind] cummac[cummac$group == g, ]$cummac <- sum(var.df[var.df$group == g,]$mac) } assoc.compilation$group <- row.names(assoc.compilation) assoc.compilation <- merge(assoc.compilation, cummac, by.x = "group", by.y = "group", all.x = T) assoc.compilation <- assoc.compilation[assoc.compilation$cummac > minmac,] if (nrow(assoc.compilation) == 0 ){ png(filename = paste(label,".cummac.",as.character(minmac),".association.plots.png",sep=""),width = 11, height = 22, units = "in", res=800, type = "cairo") dev.off() write.csv(list(), paste(label,".cummac.",as.character(minmac), ".groupAssoc.csv", sep="")) fwrite(list(), file = paste(label,".cummac.",as.character(minmac), ".all.variants.groupAssoc.csv", sep=""), row.names = F) } else { png(filename = paste(label,".cummac.",as.character(minmac),".association.plots.png",sep=""),width = 11, height = 22, units = "in", res=800, type = "cairo") par(mfrow=c(2,1)) # qq plot qq(as.numeric(assoc.compilation[,"pval_0"]),main=label) legend('topleft',c(paste0("GC = ", lam(assoc.compilation[,"pval_0"])))) manhattan(assoc.compilation,chr="chr",bp="pos",p="pval_0", main=label) dev.off() write.csv(assoc.compilation, paste(label,".cummac.",as.character(minmac), ".groupAssoc.csv", sep="")) # var.df = do.call(rbind,var.info) fwrite(var.df, file = paste(label,".cummac.",as.character(minmac), ".all.variants.groupAssoc.csv", sep=""), row.names = F) }
c63e75be15b96511ac5cb0bd4d3299035b63cd3b
918e582aa9c88bfd261af310d56b79ace2bd328a
/R/random_walk.R
568e1b1c71c7ac134c6e28c11bee6c86f83d714e
[]
no_license
cran/SteinerNet
bba40d0d6a96aae8f5c6e623df07903f04fbbdc0
7133431c232fc5ed73ec7fa697043dd3cf704d1c
refs/heads/master
2021-01-20T22:28:58.947559
2020-09-07T08:50:08
2020-09-07T08:50:08
17,718,267
3
10
null
2018-06-25T17:57:04
2014-03-13T17:01:45
R
UTF-8
R
false
false
2,940
r
random_walk.R
gRandWalk <- function (glist, numofterminals, terminalpr) { nodlist <- c() g <- glist[[1]] seed <- sample(1:length(V(g)), 1) i <- 1 while (i < numofterminals) { seed <- sample(unlist(neighborhood(g, 1, nodes = seed, mode = "all")), 1) prob <- runif(1, min = 0, max = 1) if (prob < terminalpr) { nodlist <- c( nodlist, as.numeric(V(g)[seed]) ) nodlist <- unique(nodlist) i <- length(nodlist) } } return(nodlist) } ####--------------------------------------- Documentation ---------------------------------------#### #' Select terminals #' #' @description Provides random walk procedure. Starting from the randomly selected node, choose a neighbour node uniformly #' randomly, until given number of terminals won't be found. #' #' @usage generate_st_samples(graph, ter_number, prob) #' #' @param graph an igraph graph; should be undirected, otherwise it is converted to undirected. #' @param ter_number a numeric vector; each element indicates the number of terminals to be selected and length of vector #' indicates the number of terminal sets to be picked. #' @param prob a numeric vector of the same length as ter_number; prob[i] defines a probability with which each #' next node accepted or rejected while selecting ter_number[i] terminals. #' #' @return A list of the same length as ter_number. Each element of list contains a vector of ids of selected vertices. #' #' @examples #' generate_st_samples(graph = graph("Zachary"), #' ter_number = c(3, 4), #' prob = c(0.1, 0.2)) #' #' @references 1. Afshin Sadeghi and Holger Froehlich, "Steiner tree methods for optimal sub-network #' identification: an empirical study", BMC Bioinformatics 2013 14:144 #' #' @export ####------------------------------------- End Documentation -------------------------------------#### generate_st_samples <- function (graph, ter_number, prob) { ter_list <- c() glist <- c() glist[[1]] <- as.undirected(graph) if (length(ter_number) != length(prob)) stop("The length of ter_number is not equal to the length of prob") for (i in 1:length(ter_number)) { if (ter_number[i] >= length(V(glist[[1]]))) stop("Number of terminals to be selected is greater than number of vertices in graph") if ( !((prob[i] > 0) & (prob[i] <= 1)) ) stop("prob doesn't belong to (0, 1]") ter_list[[i]] <- gRandWalk(glist = glist, numofterminals = ter_number[i], terminalpr = prob[i]) } return(ter_list) }
cf35e41d2c67c3dffa696a302592de818cd02d6f
97a6fb83ad026cbedd48b0f1493b3837876ffebe
/RE_level_simulation/Translocation/scripts/translocation.r
70786d84fdfe850b04550f84f1d5c7b74b1e7471
[]
no_license
ay-lab/AveSim
039d22791bda9ab8208af4d3f06c52cd1d9a1d4b
e4e47e90d643f04f9212fb2a9d64d964c8bfdf5f
refs/heads/master
2021-01-20T12:21:38.997584
2019-11-28T04:38:10
2019-11-28T04:38:10
101,714,230
3
1
null
null
null
null
UTF-8
R
false
false
2,559
r
translocation.r
library(BSgenome.Hsapiens.UCSC.hg19) args <- commandArgs(trailingOnly = TRUE) #Rscript insertion.r chr1 chr2 150000000 240000000 3000000 3000001 chr = read.table("../scripts/chr.list",header=F) if (as.character(args[6]) == "yes"){ j = 1 while (j <= length(chr$V1)){ if (as.character(args[1]) != as.character(chr$V1[j]) & as.character(args[2]) != as.character(chr$V1[j])){ x.a = getSeq(Hsapiens, as.character(chr$V1[j])) sequence = as.character(x.a) name = paste(">",chr$V1[j],sep="") fileConn <- file(as.character(paste("Normal.",chr$V1[j],".genome.fasta",sep=""))) header = as.character(paste(name,sequence,sep="\n")) writeLines(header,fileConn) close(fileConn) } j = j+1 } } if (as.character(args[1]) != as.character(args[2])){ full.A = getSeq(Hsapiens, as.character(args[1])) a = getSeq(Hsapiens, as.character(args[1]),start=start(full.A)[[1]],end=as.numeric(args[3])-1) b = getSeq(Hsapiens, as.character(args[1]),start=as.numeric(args[3]), end=as.numeric(args[4])) c = getSeq(Hsapiens, as.character(args[1]),start=as.numeric(args[4])+1, end=end(full.A)[[1]]) a = as.character(a) b = as.character(b) c = as.character(c) fileConn <- file(as.character(paste("Normal.",args[1],".genome.fasta",sep=""))) sequence = as.character(full.A) name = paste(">",args[1],sep="") header = as.character(paste(name,sequence,sep="\n")) writeLines(header,fileConn) close(fileConn) fileConn <- file(as.character(paste("Translocation_Donor.",args[1],".genome.fasta",sep=""))) sequence = as.character(paste(a,c,sep="")) name = paste(">",args[1],sep="") header = as.character(paste(name,sequence,sep="\n")) writeLines(header,fileConn) close(fileConn) full.B = getSeq(Hsapiens, as.character(args[2])) fileConn <- file(as.character(paste("Normal.",args[2],".genome.fasta",sep=""))) sequence = as.character(full.B) name = paste(">",args[2],sep="") header = as.character(paste(name,sequence,sep="\n")) writeLines(header,fileConn) close(fileConn) d = getSeq(Hsapiens, as.character(args[2]),start=start(full.B)[[1]],end=as.numeric(args[5])) e = getSeq(Hsapiens, as.character(args[2]),start=as.numeric(args[5])+1, end=end(full.B)[[1]]) fileConn <- file(as.character(paste("Translocation_Receiver.",args[2],".genome.fasta",sep=""))) sequence = as.character(paste(b,e,sep="")) name = paste(">",args[2],sep="") header = as.character(paste(name,sequence,sep="\n")) writeLines(header,fileConn) close(fileConn) }
5964f844139768af509715439fb89e333e2bb803
f7c205369b307ef300fabbeb59bfd9043c73bad8
/pl1 d.R
97376d024cc7ae8273c531a095654845c98e4679
[]
no_license
b62ropaa/R
26ba444f38cd00ef9ab7ee33692df00d662e92ca
218fa8327a8bb234fc4b47e2b3951b7a39da8a6b
refs/heads/master
2020-04-13T03:20:36.251013
2019-09-09T10:54:14
2019-09-09T10:54:14
162,928,557
0
0
null
null
null
null
UTF-8
R
false
false
200
r
pl1 d.R
print("Introduzca el cateto1") cat1<-scan(n=1) print("Introduzca el cateto 2") cat2<-scan(n=1) hip<-sqrt(cat1^2+cat2^2) cat("La hipotenusa del triangulo de cateto 1=",cat1,"y cateto 2=",cat2,"es",hip)
f1527b90d7d23e156ce17101c6581f2643516d64
19040283cd6c4468a7537a912c0c2d0fcca76a92
/parse-corpus-coma.R
4479e2389e43c6317cbd7af1c7d95385818c5035
[]
no_license
daniel-jettka/corpus-analytics-with-R
9a2d8b757879495f0a954b4bac5cf15c4d8a1515
13ba506c7af51985ef61a139766f2d374f2b396d
refs/heads/main
2023-03-08T08:56:52.591582
2021-03-02T18:41:33
2021-03-02T18:41:33
311,933,042
1
0
null
null
null
null
UTF-8
R
false
false
1,624
r
parse-corpus-coma.R
library(xml2) ############ Samples of Parameters ############ # Base directory of EXMARaLDA corpus (local) # base_directory <- c("C:/Users/Daniel/Desktop/demo-corpus/") # # Name of coma file (path from base directory) # coma_file <- "EXMARaLDA_DemoKorpus.coma" # # XPath to find paths to content files (here: EXS files) # c_xpath <- ".//*[local-name()='Transcription' and *[local-name()='Description']/*[local-name()='Key' and @Name='segmented']='true']/*[local-name()='NSLink']" ################################################ ### Sample call of function (read into list) ### # # 1. read EXS from Coma file (for EXMARaLDA corpus downloaded to local directory) # content <- parse_coma("C:/Users/Daniel/Desktop/demo-corpus/", "EXMARaLDA_DemoKorpus.coma", ".//*[local-name()='Transcription' and *[local-name()='Description']/*[local-name()='Key' and @Name='segmented']='true']/*[local-name()='NSLink']") # # 2. read EXB from Coma file (for EXMARaLDA corpus downloaded to local directory) # content <- parse_coma("C:/Users/Daniel/Desktop/demo-corpus/", "EXMARaLDA_DemoKorpus.coma", ".//*[local-name()='Transcription' and *[local-name()='Description']/*[local-name()='Key' and @Name='segmented']='false']/*[local-name()='NSLink']") # ################################################ parse_coma <- function(base_directory, coma_file, c_xpath){ xml <- read_xml(paste(base_directory, coma_file, sep="")) # read content into list content <- list() content_files <- xml_text(xml_find_all(xml, c_xpath)) for (c in content_files) { content[[c]] <- read_xml(paste(base_directory, c, sep="")) } return(content) }
4d053393fed49b3ff7f4587b9bbf3f38b5f0e85b
aeadfadb984277409faf5bde4f9544f47b82a2cb
/man/createConsoleAppender.Rd
6ad3bca8a8ea072e3cf49678d3a42ef3df099f5d
[ "Apache-2.0" ]
permissive
cran/ParallelLogger
500d886d83b5853d127660ad05336ac5593ad42c
358c0c66e91e258dc1c3a86c99bd15a073185e54
refs/heads/master
2023-09-01T00:42:14.391609
2023-08-22T14:50:02
2023-08-22T16:34:27
145,897,044
1
0
null
null
null
null
UTF-8
R
false
true
836
rd
createConsoleAppender.Rd
% Generated by roxygen2: do not edit by hand % Please edit documentation in R/Appenders.R \name{createConsoleAppender} \alias{createConsoleAppender} \title{Create console appender} \usage{ createConsoleAppender(layout = layoutSimple) } \arguments{ \item{layout}{The layout to be used by the appender.} } \description{ Create console appender } \details{ Creates an appender that will write to the console. } \examples{ appender <- createConsoleAppender(layout = layoutTimestamp) logger <- createLogger(name = "SIMPLE", threshold = "INFO", appenders = list(appender)) registerLogger(logger) logTrace("This event is below the threshold (INFO)") logInfo("Hello world") unregisterLogger("SIMPLE") }
b3775b02a158b24774c401ffeeae549d71585f41
160fa6790946d4a704b580de3030ec9f6c14949d
/cachematrix.R
a9f699608cf0ac1ad3a995267989ea41dde6d3f3
[]
no_license
Sarac96/ProgrammingAssignment2
6f972ac4f934a2700ce98c2ee9d3fb24f4093b94
7944c8ba6cd2905c0a802af0de776fd5df0c78c3
refs/heads/master
2022-12-24T21:24:30.129217
2020-09-22T08:10:10
2020-09-22T08:10:10
296,848,717
0
0
null
2020-09-19T11:01:05
2020-09-19T11:01:03
null
UTF-8
R
false
false
1,213
r
cachematrix.R
## Computing the cache of a matrix can be a costly operation. ## This function creates a matrix whose inverse can be retrieved from a cache. ## makeCacheMatrix creates "special" matrix, which is a list containing: ## set the value of the matrix ## get the value of the matrix ## set the value of the inverse ## get the value of the inverse makeCacheMatrix <- function(x = matrix()) { inv_matrix <- NULL set <- function(y) { x <<- y inv_matrix <<- NULL } get <- function() x setinverse <- function(inverse) inv_matrix <<- inverse getinverse <- function() inv_matrix list( set = set, get = get, setinverse = setinverse, getinverse = getinverse ) } ## cacheSolve computes the inverse of the matrix created through makeCacheMatrix. ## If the inverse was already computed, it only retrieves the cached value cacheSolve <- function(x, ...) { ## Return a matrix that is the inverse of 'x' inv_matrix <- x$getinverse() if (!is.null(inv_matrix)) { message("getting cached data") return(inv_matrix) } data <- x$get() inv_matrix <- solve(data, ...) x$setinverse(inv_matrix) inv_matrix }
0a0df98e945e49698211c2bf9bae4ff5da527a47
f5502bea857396ec669339f268f37c77f0ceb805
/R/get_geo.R
e57879ded26197113f48aed717663cbca06ad58c
[ "MIT" ]
permissive
roboton/covid-covariates
0646191e20596db2a4f5b9f7fa9fde7ab281c159
b7e962017e5e71a78d1eb8ed9eaa379d9db401b3
refs/heads/master
2022-11-22T06:43:04.250917
2020-07-27T11:35:56
2020-07-27T11:35:56
262,303,342
0
0
null
null
null
null
UTF-8
R
false
false
2,262
r
get_geo.R
##' .. content for \description{} (no empty lines) .. ##' ##' .. content for \details{} .. ##' ##' @title ##' @param level ##' @param country ##' @param subregion1 ##' @param subregion2 ##' @return ##' @author roboton ##' @export ##' get_geo <- function(level, country, subregion1, subregion2, sr_lookup) { if (all(is.na(level))) { # guess level from missing values level <- case_when( is.na(subregion1) ~ "country", is.na(subregion2) ~ "state", TRUE ~ "county") } country <- norm_geo_name(country, "country") country_code <- countrycode(country, "country.name", "iso2c") country_code <- coalesce(country_code, country) subregion1 <- norm_geo_name(subregion1, "subregion1") subregion1_code <- sr_lookup %>% filter(level == "state") %>% right_join(tibble(country, subregion1), by = c("country", "subregion1")) %>% mutate(subregion1_code = coalesce(subregion1_code, subregion1)) %>% pull(subregion1_code) subregion2 <- norm_geo_name(subregion2, "subregion2") subregion2_code <- sr_lookup %>% right_join(tibble(country, subregion1, subregion2), by = c("country", "subregion1", "subregion2")) %>% mutate(subregion2_code = coalesce(subregion2_code, subregion2)) %>% pull(subregion2_code) geocode <- tibble(country_code, subregion1_code, subregion2_code) %>% rowwise() %>% mutate(geocode = paste(na.omit(c(country_code, subregion1_code, subregion2_code)), collapse = "-")) %>% pull(geocode) return(geocode) } norm_geo_name <- function(geo, type) { # only handle US right now which is # states: abbreviation # country: US # counties: fips? names? case_when( type == "subregion2" ~ geo %>% str_remove(" city$") %>% str_remove(" Municipality$") %>% str_remove(" Census Area$") %>% str_remove(" City and Borough$") %>% str_remove(" Borough$") %>% str_replace("LaSalle Parish", "La Salle Parish") %>% str_replace("Kenai Peninsula", "Kenai Peninsula Borough") %>% str_replace("Oglala Lakota County", "Shannon County"), type == "subregion1" ~ geo, type == "country" ~ geo, TRUE ~ geo ) %>% return() }
9cbf07387b6b40e5a4e71b59b87a038f72710693
c06f1619dbd2007837f73cc184fdef6d821ad981
/R/useless_functions.R
6e974444a20c4125ffbeb767a982c132afdf2007
[]
no_license
BenGriff42/useless
34cba60dada4e01324cd418e38e5c8fa0cad8f2d
ef3686ae6cbe4095ad0bdd3ac7ed97f4785c2a35
refs/heads/main
2023-08-14T11:45:09.814151
2021-10-07T12:28:32
2021-10-07T12:28:32
414,521,717
0
0
null
null
null
null
UTF-8
R
false
false
988
r
useless_functions.R
#' Return input #' #' Function to return whatever you put in #' #' @param x Anything #' #' @return What you input #' @export #' #' @examples #' same(1) #' same("same") same = function(x){ return(x) } #' Nothing #' #' A function that always returns 0 #' #' @param x Anything #' #' @return zero #' @export #' #' @examples #' nothing(1000) #' nothing("nothing") nothing = function(x){ return(0) } #' No #' #' A function that rejects everything #' #' @param x Anything #' #' @return Wrong input #' @export #' #' @examples #' no(-20) #' no("no") no = function(x){ print("Wrong input") } #' Bad linear model #' #' Finds LS solution of parameters for linear model. Much less efficient than lm command, would not recommend using. #' #' @param y response variable #' @param X0 explanatory variable #' #' @return fitted parameters #' @export #' #' @examples bad.lm = function(y,X0){ d = length(X0[1,]) X = as.matrix(cbind(rep(1,length(y)),X0)) solve(t(X) %*% X) %*% t(X) %*% y }
e527b1e0c5f75214c4849b99dbcaf66ed54185ca
99cba6b0ed163c7b82b846e148d92d9ec16a0fba
/density_plot.r
21dac392011ca53d551cbf048afa5f7ce0d30ca6
[]
no_license
Xudeh/Predixcan-fw-brca
f777f5876317e5aaad564c40ff569d741704aec5
d57f5bff5ec976c52549689d5f31a4d952cb4432
refs/heads/master
2022-02-12T10:21:24.310269
2017-10-24T22:09:36
2017-10-24T22:09:36
null
0
0
null
null
null
null
UTF-8
R
false
false
500
r
density_plot.r
cor.table=read.csv("R and p value in Tumor(420) and Normal(36).csv") ###density plot plot (density(cor.table$R.in.tumor), col="red", lwd=2) lines(density(cor.table$R.in.normal), col="green", lwd=2) plot (density(cor.table$R.square.in.tumor), col="red", lwd=2) lines(density(cor.table$R.square.in.normal), col="green", lwd=2) ###scatter plot plot(cor.table$R.square.in.tumor, cor.table$R.square.in.normal, pch=19,cex=.5) abline(lm(cor.table$R.square.in.tumor~cor.table$R.square.in.normal))
c935d92df6774c09fdaafaa4f4d9d22eefb75a99
db12b990924703cd74748d8585cd9c11fafa6746
/h2o-r/tests/testdir_munging/unop/runit_cor.R
db76e446370bb3428751160764d6fcafeff8c725
[ "Apache-2.0" ]
permissive
h2oai/h2o-3
919019a8f297eec676011a9cfd2cc2d97891ce14
d817ab90c8c47f6787604a0b9639b66234158228
refs/heads/master
2023-08-17T18:50:17.732191
2023-08-17T16:44:42
2023-08-17T16:44:42
17,371,412
6,872
2,345
Apache-2.0
2023-09-14T18:05:40
2014-03-03T16:08:07
Jupyter Notebook
UTF-8
R
false
false
1,231
r
runit_cor.R
setwd(normalizePath(dirname(R.utils::commandArgs(asValues=TRUE)$"f"))) source("../../../scripts/h2o-r-test-setup.R") ## # Test out the cor() functionality # If H2O dataset x, get back cor data frame with dimension ncol(x) # If NAs in the frame, they are skipped in calculation unless na.rm = F # If any categorical columns, throw an error ## test.cor <- function() { hex <- as.h2o(iris) Log.info("Slice out iris[,1] and get the correlation: ") Log.info(paste("R:", cor(as.matrix(iris[,1])), "\tH2O:", cor(hex[,1]))) cor_R = cor(as.matrix(iris[,1])) cor_h2o = cor(hex[,1]) expect_equal(cor_h2o, cor_R[1,1]) Log.info("Slice iris[,1:4] and get the correlation: ") Log.info("The correlation of iris[,1:4] when read into R is: ") iris_Rcor <- cor(iris[,1:4]) print(iris_Rcor) Log.info("The correlation of iris[,1:4] when asking H2O is: ") iris_H2Ocor <- as.data.frame(cor(hex[,1:4])) print(iris_H2Ocor) h2o_vec <- as.vector(unlist(iris_H2Ocor)) r_vec <- as.vector(unlist(iris_Rcor)) expect_equal(h2o_vec, r_vec, tol=1e-6) for (i in c(1e1,1e2,1e3,1e4,1e5,1e6,1e7,1e8,1e9)) { expect_equal(h2o.cor(as.h2o(c(i,1+i,10+i))), 1); } } doTest("Test out the cor() functionality", test.cor)
ed74c4e5fd7c269f7606409909c16f3e7c8eb6dd
2d34708b03cdf802018f17d0ba150df6772b6897
/googlecomputealpha.auto/man/TargetPoolsScopedList.warning.data.Rd
129a6bbec68da9254c57a747a353ab79a675b04b
[ "MIT" ]
permissive
GVersteeg/autoGoogleAPI
8b3dda19fae2f012e11b3a18a330a4d0da474921
f4850822230ef2f5552c9a5f42e397d9ae027a18
refs/heads/master
2020-09-28T20:20:58.023495
2017-03-05T19:50:39
2017-03-05T19:50:39
null
0
0
null
null
null
null
UTF-8
R
false
true
617
rd
TargetPoolsScopedList.warning.data.Rd
% Generated by roxygen2: do not edit by hand % Please edit documentation in R/compute_objects.R \name{TargetPoolsScopedList.warning.data} \alias{TargetPoolsScopedList.warning.data} \title{TargetPoolsScopedList.warning.data Object} \usage{ TargetPoolsScopedList.warning.data() } \value{ TargetPoolsScopedList.warning.data object } \description{ TargetPoolsScopedList.warning.data Object } \details{ Autogenerated via \code{\link[googleAuthR]{gar_create_api_objects}} No description } \seealso{ Other TargetPoolsScopedList functions: \code{\link{TargetPoolsScopedList.warning}}, \code{\link{TargetPoolsScopedList}} }
2df43d8fda9ebcfe93321802542ddc934d3b2b92
406eb4f67e4f0ffe607dcaf39763f44418a78bff
/man/dcmEvidence.Rd
d6e2307ae62912db72ae1af8bfeaf403ccc221e2
[]
no_license
cran/FIAR
6af5007096986cef711b287691bd000d90183a3c
25e7b6c1fa023da58578bdd3c7e6d9c52e388899
refs/heads/master
2021-01-19T06:43:30.247772
2018-06-05T10:48:21
2018-06-05T10:48:21
17,717,505
0
0
null
null
null
null
UTF-8
R
false
false
540
rd
dcmEvidence.Rd
\name{dcmEvidence} \alias{dcmEvidence} \title{modelfit} \description{Compute AIC and BIC of a DCM } \usage{ dcmEvidence(DCM, ts) } \arguments{ \item{DCM}{DCM object.} \item{ts}{Timeseries to fit the model to.} } \value{Creates 2 extra fields DCM$AIC and DCM$BIC} \seealso{spm.dcm.estimate} \author{Bjorn Roelstraete} \examples{ # Compute how well the model DCMex fits the timeseries DCMex$sim ts <- dcmGenerate(DCMex, SNR=1, ar=.2, names=c('V1','V2','V3')) DCMex <- dcmEvidence(DCMex, ts) DCMex$AIC DCMex$BIC } \keyword{ ~DCM }
d8bfb493a228b49a35ebab6bdb964a4713af4e2f
0e269aab5f27deb9da70f53a839facdd99e0f692
/scripts/plot_summ_2.R
cfbf997e15862c45781d48339aafc96a20cf4e78
[]
no_license
kichacko/MSH-Resistance-Map
b5ec21657bcf468753e330e6b0ed9183da228c26
512a5937026f29e128b49908a0aa2bcc78e7ab59
refs/heads/master
2021-10-26T14:52:50.320905
2019-04-13T05:15:55
2019-04-13T05:15:55
112,489,522
0
0
null
null
null
null
UTF-8
R
false
false
1,849
r
plot_summ_2.R
function_plot_summ_2 = function(input_data, subset_pathogen, subset_procedure, subset_year){ ################# LOAD DATA ###################### df_01 = input_data subset_year = as.numeric(as.character(subset_year)) ################# SUBSET ###################### # Subset df_01 = subset(df_01, df_01$Pathogen %in% subset_pathogen) df_01 = subset(df_01, df_01$Procedure %in% subset_procedure) df_01 = df_01[df_01$Year == subset_year, ] df_01 = df_01[row.names(unique(df_01[ , c("Isolate.ID", "Pathogen", "Procedure", "Year")])),] ################# CALCULATIONS ###################### matrix_01 = do.call( data.frame, aggregate( formula = Isolate.ID ~ Pathogen + Procedure + Unit, data = df_01, FUN = length ) ) names(matrix_01) = c("Pathogen", "Procedure", "Unit", "Count") matrix_01$Count = as.numeric(as.character(matrix_01$Count)) ################# PLOT ###################### # plot plot_01 = ggplot( data = matrix_01, aes( x = Unit, y = Count, fill = Unit ) ) + geom_bar( position = "dodge", stat = "identity", color = "white" ) + theme( axis.title.x = element_blank(), axis.text.x = element_text(size = 6, angle = 90), axis.line.x = element_line(color="black"), axis.line.y = element_line(color="black"), panel.background = element_blank(), panel.grid = element_line(color = "gray"), strip.text.x = element_text(size = 8), legend.position = "none" ) + ylab("Number of isolates") plot_01 = ggplotly(plot_01, tooltip = c("x", "fill","y"), pdf(file = NULL)) return(plot_01) }
31fc0412598d31fa0e6daa008a537fc2f6656946
8e52cfdf2db46054104efc466320b4ad0217ea7f
/man/do_feature_selection_by_random_forest.Rd
53c90e70676bad9b89ebffe66cbef2e197dbf432
[]
no_license
jfontestad/hospital-readmission
82469e9e60203e11e7fe8d40452a3087ec4adad6
67f50933b54cfa22a69e1b2cb7a5a00168f2625e
refs/heads/master
2023-03-17T00:33:29.619647
2019-08-30T03:17:49
2019-08-30T03:17:49
null
0
0
null
null
null
null
UTF-8
R
false
true
360
rd
do_feature_selection_by_random_forest.Rd
% Generated by roxygen2: do not edit by hand % Please edit documentation in R/utilities.R \name{do_feature_selection_by_random_forest} \alias{do_feature_selection_by_random_forest} \title{Title} \usage{ do_feature_selection_by_random_forest(data_df, data_vars, outcome, data_dir, output_pattern) } \arguments{ \item{output_pattern}{} } \description{ Title }
b410129f59a4c0b43674eda954ae781ce23c77f5
69cb42388719a7137ff3afbef869e6d45fcef4d5
/Classification/mmm.R
f5e31b56a1146df0f51da31dc29b61968192f9fb
[ "MIT" ]
permissive
Deekerubo/AccidentPrediction
660ad1e28585a2d09f253712d73f20be0e7b0c0a
e2e9739a7c1be3a48947107c0e42468b8331e92e
refs/heads/master
2020-03-26T02:10:48.346321
2019-06-04T11:10:35
2019-06-04T11:10:35
144,400,039
0
1
MIT
2023-05-10T21:18:31
2018-08-11T16:14:31
R
UTF-8
R
false
false
703
r
mmm.R
#perfome linear regression on training data reg<- lm(Accident_Severity~.,data=train_data) #predicttestdata using liner modelling predict<- predict(reg,newdata=test_data) predict plot(predict) #testing the posibility of accident severity with values less than Tab<- table(test_data$Accident_Severity, predict>2.8 ) Tab #calculate the miscalculation error mcrate<- 1-sum(diag(Tab))/sum(Tab) mcrate View(mcrate) plot(mcrate) #............rpart decison tree....... library(rpart) #library(plyr) #library(dplyr) #training model1 model1<- rpart(Accident_Severity~., train_data, method ="class") model1<-predict(model1, test_data,type ="class") View(model1) summary(model1) plot(model1)
f04310f8b39659390601affc263a74b5431a18c7
1d821994bcabecfbb2b5d10feca107ede2f95bc3
/R/inverse.logit.r
57ce2e452733b3204ac26d3704553953b41d7f9a
[ "MIT" ]
permissive
jae0/carstm
1ca3c10790edf39abc938cadc4599839f92fd206
3fdfe0b6d8bf601acaf8b1732274d2ff217731ed
refs/heads/master
2023-08-16T23:48:09.986292
2023-08-16T23:02:38
2023-08-16T23:02:38
117,303,833
0
0
MIT
2018-11-09T15:04:41
2018-01-13T01:27:33
R
UTF-8
R
false
false
146
r
inverse.logit.r
inverse.logit = function( x ) { # x should be the log odds ratio oddsratio = exp(x) prob = oddsratio / (1 + oddsratio ) return (prob) }
94a3279678a5f03602e225e80005745bd3097ad2
2080044625e70fbe2407d923d1b3727da9ced1b2
/glassKNNnw.R
8bece9f789ceac4e8e017b6085e9d69255bb6670
[]
no_license
kurla-sreevalli/DS_Rcode
01a26929ed49f239fdf1b7d7eff50633ec857758
7d527816715954c993112ce1dcabd1a30fc26a1e
refs/heads/master
2023-01-29T07:40:32.493397
2020-12-08T11:04:02
2020-12-08T11:04:02
294,662,354
1
0
null
null
null
null
UTF-8
R
false
false
1,916
r
glassKNNnw.R
library(readr) glass <- read_csv("C:/Users/sreevalli kurla ksv/Downloads/Excelr Data-20190131T150000Z-001/Excelr Data/Data Sets/KNN/glass.csv") View(glass) str(glass) #table of type table(glass$Type) glassdf <- as.data.frame(glass) # Replace types column names for 1,2,3,4,5,6,7 as type1,type2,type3,type4,type5,type6,type7. type is factor with 7 levels that is 1,2,3,4,5,6 and 7. We also replacing these seven enteries. glassdf$Type <- factor(glassdf$Type, levels = c("1","2","3","4","5","6","7"), labels = c("type1","type2","type3","type4","type5","type6","type7")) # table or proportation of enteries in the datasets. What % of entry is type1,type2,type3,type4,type5,type6 and type7 round(prop.table(table(glassdf$Type))*100,10) summary(glassdf[c("RI","Na","Mg")]) #Create a function to normalize the data norm <- function(x){ return((x-min(x))/(max(x)-min(x))) } #test normalization norm(c(1,2,3,4,5)) norm(c(10,20,30,40,50)) #Apply the normalization function to wbcd dataset glass_n <- as.data.frame(lapply(glassdf[1:9], norm)) View(glass_n) #create training and test datasets glass_train <- glass_n[1:149,] glass_test <- glass_n[150:214,] #Get labels for training and test datasets glass_train_labels <- glassdf[1:149,10] glass_test_labels <- glassdf[150:214,10] # Build a KNN model on taining dataset library("class") library("caret") # Building the KNN model on training dataset and also need labels which we are including c1. Once we build the preduction model # we have to test on test dataset glass_pred <- knn(train = glass_train, test = glass_test, cl = glass_train_labels, k=21) class(glass_train) class(glass_test) ## Now evualuation the model performance # install package gmodels install.packages("gmodels") library("gmodels") # Create cross table of predicted and actual CrossTable( x = glass_test_labels, y = glass_pred)
0a9002a3d7ea62a8c74eacee499c53b50169e2c2
67565703b258987307a8c51a12c4c9b24ee3f7ca
/R/geom-colh.R
238d36f309496e045ea81548d11b441ae9a12596
[]
no_license
lionel-/ggstance
2c049629963e4aac01a3a49f115f56e3936e560c
7e303d755624d3764d4543a18c9abdbd410e2767
refs/heads/master
2023-04-03T17:08:36.786110
2023-03-14T16:59:59
2023-03-14T16:59:59
50,201,421
202
24
null
2023-03-14T17:00:02
2016-01-22T19:04:00
R
UTF-8
R
false
false
1,258
r
geom-colh.R
#' @rdname geom_barh #' @eval rd_aesthetics("geom", "colh") #' @export geom_colh <- function(mapping = NULL, data = NULL, position = "stackv", ..., width = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) { layer( data = data, mapping = mapping, stat = "identity", geom = GeomColh, position = position, show.legend = show.legend, inherit.aes = inherit.aes, params = list( width = width, na.rm = na.rm, ... ) ) } #' @rdname ggstance-ggproto #' @format NULL #' @usage NULL #' @export GeomColh <- ggproto("GeomColh", ggplot2::GeomRect, required_aes = c("y", "x"), setup_data = function(data, params) { data$width <- data$width %||% params$width %||% (resolution(data$y, FALSE) * 0.9) transform(data, xmin = pmin(x, 0), xmax = pmax(x, 0), ymin = y - width / 2, ymax = y + width / 2, width = NULL ) }, draw_panel = function(self, data, panel_params, coord, width = NULL) { # Hack to ensure that height is detected as a parameter ggproto_parent(ggplot2::GeomRect, self)$draw_panel(data, panel_params, coord) } )
c8ba20fa86e63a9bc6ec99bae21a85c1c02a2f4d
1e800858d0d3130be58458b284f31cc196f48f10
/int.R
380590988da804f95cdeb8912b0857cd9b878bf3
[]
no_license
ShanYu3393/fusionFLM
6f1ac495e680b10ac193abfdbff59b28c83cb12f
e216f63d2ff9adc86b64a1c78568966af22a92df
refs/heads/master
2022-11-09T12:46:23.769244
2020-06-23T15:17:42
2020-06-23T15:17:42
273,521,201
0
0
null
null
null
null
UTF-8
R
false
false
101
r
int.R
int <- function(func, time, X, t.range) { sum(X * func(time) * (c(time[-1], t.range[2]) - time)) }
adc89d7c8a405bf536b349e52bde97a52c7bb6a2
ffdea92d4315e4363dd4ae673a1a6adf82a761b5
/data/genthat_extracted_code/KMsurv/examples/bmt.Rd.R
7280a17ad67b3e25d67a17d1b9fc7183a2d0f3e2
[]
no_license
surayaaramli/typeRrh
d257ac8905c49123f4ccd4e377ee3dfc84d1636c
66e6996f31961bc8b9aafe1a6a6098327b66bf71
refs/heads/master
2023-05-05T04:05:31.617869
2019-04-25T22:10:06
2019-04-25T22:10:06
null
0
0
null
null
null
null
UTF-8
R
false
false
136
r
bmt.Rd.R
library(KMsurv) ### Name: bmt ### Title: data from Section 1.3 ### Aliases: bmt ### Keywords: datasets ### ** Examples data(bmt)
de458da2deac405246e67efdfcba7d51c1d325ef
135bfc3f68e44689cb31b9c321f5c6cfe860d614
/BS_compiled_OutputsAnalysis.R
1b79175bf0af64fdaf8a5a5ef09bfac1bac9b2a4
[]
no_license
siminl/Project-Coupon
16601669c54c681bbcbc21527b127d0561d03b2b
c49eceeabe52916bd0d89a5e724662aeff7f77f5
refs/heads/master
2021-07-20T13:54:49.284769
2021-02-21T16:40:58
2021-02-21T16:40:58
87,201,129
0
0
null
null
null
null
UTF-8
R
false
false
105,744
r
BS_compiled_OutputsAnalysis.R
industries_to_check <- c(2,5,11,10,1) # bs_outputs_df <- vector() # bs_outputs_df <- sapply(bs_outputs_stored, function(x) sapply(x,function(xx) cbind(bs_outputs_df,c(xx$par,xx$convergence,xx$value)))) # # # bs_outputs_compile <- (t(rep(0,dim(bs_outputs_df[[1]])[1]+2))) # colnames(bs_outputs_compile) <- c("ch","thetaalpha","thetaT","thetad","betad","theta0","beta0","conv","funvalue","mase_dfremain","type") # # for(i in industries_to_check){ # tmp <- data.frame(t(bs_outputs_df[[i]]), # mase_dfremain = t(t(mase_remain[[i]])),type=i) # colnames(tmp) <- c("ch","thetaalpha","thetaT","thetad","betad","theta0","beta0","conv","funvalue","mase_dfremain","type") # bs_outputs_compile <- rbind(bs_outputs_compile,tmp) # } # bs_outputs_compile <- bs_outputs_compile[-1,] # bs_outputs_compile <- bs_outputs_compile # # save(bs_outputs_compile,file= "bs_out_compile.Rdata") # # the sales estimates during holiday time # Scoef <- data.frame(type = c(2,5,11,10,1), # Salpha = c(-4.47,-1.40,-3.01,-1.40,-3.20), # Sd = c(3.36,6.33,1.0,0.01,0.04), # ST = c(2.60,0.88,2.8,0.69,1.03)) # save(compiled_results,file = "compiled_results.Rdata") # save(compiled_results_ls,file = "compiled_results_ls.Rdata") compiled_results <- vector() compiled_results_ls <- vector(mode = "list",length=11) for(i in industries_to_check){ if(i == 2){ nonhol_data <- dealsfull%>%filter(is.na(holiday)==1,type%in%c(2,3))%>%{.->>dealsfull_type}%>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95)))%>% filter(original_price>quantile(dealsfull_type$original_price,c(0.4)), original_price<quantile(dealsfull_type$original_price,c(0.6)))%>% {.->>sdopph}%>% mutate(original_price = original_price/sd(original_price)) hol_data <- dealsfull%>%filter(is.na(holiday)==0,type%in%c(2,3),prep.period>0,offering_duration<=40)%>%{.->>dealsfull_type}%>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95)))%>% filter(original_price>quantile(dealsfull_type$original_price,c(0.4)), original_price<quantile(dealsfull_type$original_price,c(0.6)))%>% {.->>sdop}%>% mutate(original_price = original_price/sd(original_price)) # set.seed(100) # rs <-list() # for(b in 1:6){ # rs[[b]] <- sample(dim(hol_data)[1],dim(hol_data)[1],replace = T) # } # hol_data <- hol_data[rs[[1]],] }else if(i %in% c(10)){ nonhol_data <- dealsfull%>%filter(is.na(holiday)==1,type==i)%>%{.->>dealsfull_type}%>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95)))%>%{.->>sdopph}%>% mutate(original_price = original_price/sd(original_price)) hol_data <- dealsfull%>%filter(is.na(holiday)==0,type==i,prep.period>0,offering_duration<=25)%>%{.->>dealsfull_type}%>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95)))%>% {.->>sdop}%>% mutate(original_price = original_price/sd(original_price)) # set.seed(200) # rs <-list() # for(b in 1:1){ # rs[[b]] <- sample(dim(hol_data)[1],dim(hol_data)[1],replace = T) # } # hol_data <- hol_data[rs[[1]],] # }else if(i %in% c(11,1)){ nonhol_data <- dealsfull%>%filter(is.na(holiday)==1,type==i)%>%{.->>dealsfull_type}%>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95)))%>%{.->>sdopph}%>% mutate(original_price = original_price/sd(original_price)) hol_data <- dealsfull%>%filter(is.na(holiday)==0,type==i,prep.period>0,offering_duration<40)%>%{.->>dealsfull_type}%>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9)))%>% {.->>sdop}%>% mutate(original_price = original_price/sd(original_price)) # set.seed(200) # rs <-list() # for(b in 1:1){ # rs[[b]] <- sample(dim(hol_data)[1],dim(hol_data)[1],replace = T) # } # hol_data <- hol_data[rs[[1]],] }else{ nonhol_data <- dealsfull%>%filter(is.na(holiday)==1,type==i)%>%{.->>dealsfull_type}%>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95)))%>%{.->>sdopph}%>% mutate(original_price = original_price/sd(original_price)) hol_data <- dealsfull%>%filter(is.na(holiday)==0,type==i,prep.period>0,offering_duration<=40)%>%{.->>dealsfull_type}%>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95)))%>% {.->>sdop}%>% mutate(original_price = original_price/sd(original_price)) } if(i == 2){ hol_data <- hol_data%>%filter(city!="XA") }else if(i %in% c(10)){ hol_data <- hol_data%>%filter(platform!="ww") }else if(i %in% c(5)){ #hol_data <- hol_data%>%filter(platform!="ww",city!="GZ") } rt <- getPerformance(hol_data,sdop, nonhol_data, sdopph, output_ls=bs_outputs[[i]], type=i,mleout_preh,mleout_h ) compiled_results_ls[[i]] <- rt compiled_results <- rbind(compiled_results, data.frame(type.x=i,dsidx2 = rt$dsidx2vec, dsidx = rt$dsidxvec, alterD = rt$alterDvec,alterDsigvec = rt$alterDsigvec, deltaD = rt$deltaDvec,alterP = rt$alterP,deltaDvec = rt$deltaDvec, mch = rt$mchs, mcnh = rt$mcnhs,mucp = rt$mucpvec,mucpnh=rt$mucpnhvec, D1h = rt$D1hvec, D2h = rt$D2hvec, D2nh = rt$D2nhvec, ratio = rt$ratiovec, thetaalphahat = rt$thetaalpha, thetaThat = rt$thetaT, thetadhat = rt$thetad, betadhat = rt$betad) ) } # ------- Start of displaying the estimators ------------- out_ls_name <- vector(mode="list",length=11) bs_sample <- c(0,0) for(i in industries_to_check){ root_path_base <- "/Users/siminli/Documents/GitHub/Project-Coupon/Deals_bootstrap_outputs/" root_path_folder <- paste("output_type",i,"/",sep="") root_path <- paste(root_path_base,root_path_folder,sep="") if(i %in% c(10,11)){ out_ls_name[[i]] <- paste(root_path,list.files(path=root_path, pattern="out\\_[[:digit:]][[:digit:]]\\_[[:digit:]].*\\.rda"),sep="") }else{ out_ls_name[[i]] <- paste(root_path,list.files(path=root_path,pattern="out\\_[[:digit:]]\\_[[:digit:]].*\\.rda"),sep="") } if(i %in% c(2) ){ bs_sample <- rbind(bs_sample,data.frame(type = i, sample_number = word(str_extract(pattern="out\\_[[:digit:]]\\_[[:digit:]].*\\.rda", out_ls_name[[i]]), 3, sep = "_"))) }else if(i %in% c(1)){ bs_sample <- rbind(bs_sample,data.frame(type = i, sample_number = word(str_extract(pattern="out\\_[[:digit:]]\\_[[:digit:]].*\\.rda", out_ls_name[[i]]), 2, sep = "_"))) }else if (i %in% c(5)){ bs_sample <- rbind(bs_sample,data.frame(type = i, sample_number = word(word(str_extract(pattern="out\\_[[:digit:]]\\_[[:digit:]].*\\.rda", out_ls_name[[i]]), 4, sep = "_"),1, sep="\\."))) }else{ bs_sample <- rbind(bs_sample,data.frame(type = i, sample_number = word(word(str_extract(pattern="out\\_[[:digit:]][[:digit:]]\\_[[:digit:]].*\\.rda", out_ls_name[[i]]), 4, sep = "_"),1, sep="\\."))) } } bs_sample <- bs_sample[-1,] compiled_results <- cbind(compiled_results,bs_sample) bs_outputs_compile <- cbind(bs_outputs_compile,compiled_results)%>% filter(conv==0,mase_dfremain>0.55) picked <- rep(0, dim(bs_outputs_compile)[1]) picked[c(1,13,23,38,66)] <- 1 estimates_sd <- (merge(unique(compiled_results), bs_outputs_compile %>% sl(funvalue,mase_dfremain,mch,D1h) %>% mt(picked = picked), by=c("mch","D1h"), all.y=TRUE) %>% fl(is.na(funvalue)==0)) %>% arrange(type) estimates_sd[-c(24,25,26,27,28,seq(15,20),40,seq(59,64),32,33,34,36,37,39,45,44,47,48,49,50,4,5,10,3,7,9,56,70),] %>% mutate(mcratio = mucp/mucpnh) %>% # gb(type, sample_number) %>% # mt(minfuncval = (funvalue==min(funvalue))) %>% # fl(minfuncval == 1) %>% gb(type) %>% mt(mumch = mean(mch), mumcnh = mean(mcnh), mumcratio = mean(mcratio), mudeltaDvec = mean(deltaDvec), mualterD = mean(alterD), mudsidx2 = mean(dsidx2), muthetaalpha= mean(thetaalphahat), muthetaT = mean(thetaThat), muthetad = mean(thetadhat), mubetad = mean(betadhat), muratio = mean(ratio), mualterP = mean(alterP), muD1h = mean(D1h), muD2h = mean(D2h), muD2nh = mean(D2nh)) %>% gb(type) %>% summarise(ssize = n(),semch = sqrt(sum((mch-mumch)^2)/ssize), semcnh = sqrt(sum((mcnh-mumcnh)^2)/ssize), semcratio = sqrt(sum((mcratio-mumcratio)^2)/ssize), sedeltaDvec = sqrt(sum((deltaDvec-mudeltaDvec)^2)/ssize), sealterD = sqrt(sum((alterD-mualterD)^2)/ssize), sedsidx2 = sqrt(sum((dsidx2-mudsidx2)^2)/ssize), sethetaalpha = sqrt(sum((thetaalphahat-muthetaalpha)^2)/ssize), sethetaT = sqrt(sum((thetaThat-muthetaT)^2)/ssize), sethetad = sqrt(sum((thetadhat-muthetad)^2)/ssize), sebetad = sqrt(sum((betadhat-mubetad)^2)/ssize), seratio = sqrt(sum((ratio-muratio)^2)/ssize), sealterP = sqrt(sum((alterP-mualterP)^2)/ssize), seD1h = sqrt(sum((D1h-muD1h)^2)/ssize), seD2h = sqrt(sum((D2h-muD2h)^2)/ssize), seD2nh = sqrt(sum((D2nh-muD2nh)^2)/ssize)) -> se_df se_df <- se_df[c(2,3,5,4,1),] save("se_df", file = "se_df.Rdata") #36,37 estimates_sd[-c(24,25,26,27,28,seq(15,20),seq(59,64),32,33,34,39,45,40,44,47,46,48,49,51,3,4,5,7,10,9,56,70),] %>% mutate(mcratio = mucp/mucpnh) %>% # gb(type, sample_number) %>% # mt(minfuncval = (funvalue==min(funvalue))) %>% # fl(minfuncval == 1) %>% gb(type) %>% mt(mumch = mean(mch), mumcnh = mean(mcnh), mumcratio = mean(mcratio), mudeltaDvec = mean(deltaDvec), mualterD = mean(alterD), mudsidx2 = mean(dsidx2), muthetaalpha= mean(thetaalphahat), muthetaT = mean(thetaThat), muthetad = mean(thetadhat), mubetad = mean(betadhat), muratio = mean(ratio), mualterP = mean(alterP), muD1h = mean(D1h), muD2h = mean(D2h), muD2nh = mean(D2nh)) %>% gb(type) %>% summarise(ssize = n(),semch = sqrt(sum((mch-mumch)^2)/ssize), semcnh = sqrt(sum((mcnh-mumcnh)^2)/ssize), semcratio = sqrt(sum((mcratio-mumcratio)^2)/ssize), sedeltaDvec = sqrt(sum((deltaDvec-mudeltaDvec)^2)/ssize), sealterD = sqrt(sum((alterD-mualterD)^2)/ssize), sedsidx2 = sqrt(sum((dsidx2-mudsidx2)^2)/ssize), sethetaalpha = sqrt(sum((thetaalphahat-muthetaalpha)^2)/ssize), sethetaT = sqrt(sum((thetaThat-muthetaT)^2)/ssize), sethetad = sqrt(sum((thetadhat-muthetad)^2)/ssize), sebetad = sqrt(sum((betadhat-mubetad)^2)/ssize), seratio = sqrt(sum((ratio-muratio)^2)/ssize), sealterP = sqrt(sum((alterP-mualterP)^2)/ssize), seD1h = sqrt(sum((D1h-muD1h)^2)/ssize), seD2h = sqrt(sum((D2h-muD2h)^2)/ssize), seD2nh = sqrt(sum((D2nh-muD2nh)^2)/ssize)) -> tt # 69/66, 38/37, 13/16 (bs_outputs_compile[c(1,16,23,38,66),]%>%mutate(mcratio = mucp/mucpnh)%>% select(type,mch,mcnh,thetaalphahat,thetaThat,thetadhat,betadhat,dsidx,dsidx2,mcratio,mucp,alterD,alterP,deltaDvec,D1h,D2h,D2nh,ratio)) -> pest_df #thetaThat = -0.87 for 5, # S_alpha, S_T, S_d -------- Scoef_se <- c(0,0,0,0) for(i in industries_to_check){ hol_data <- dealsfull%>%filter(is.na(holiday)==0,type==i,prep.period>0,offering_duration<=40)%>%{.->>dealsfull_type}%>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95)))%>% mutate(original_price = original_price/sd(original_price)) if(i == 2){ hol_data <- hol_data%>%filter(city!="XA") }else if(i %in% c(10)){ hol_data <- hol_data%>%filter(platform!="ww") }else if(i %in% c(5)){ #hol_data <- hol_data%>%filter(platform!="ww",city!="GZ") } summary(lm(data=hol_data%>%mutate(discprice = (1-discount)*original_price, # = price/partysize logvol = log(total_volume), perperson = original_price/partysize, competitors_ct = (competitors/sd(competitors)), logcomp = ifelse(competitors!=0,log(competitors),0), fixlength = ifelse(offering_duration==15,1, ifelse(offering_duration==30,2, ifelse(offering_duration==45,3,0)))), logvol~log(offering_duration)+I(log(offering_duration)^2)+ discprice+I(discprice^2)+ log(prep.period) + I((log(prep.period))^2) + #log(discprice)+I(log(discprice)^2)+ I((original_price))+I(1/log(original_price))+I(1/(log(original_price)^2))+ logcomp+weekends+platform:weekends+ platform+city ) ) -> lm_S Scoef_se <- rbind(Scoef_se,data.frame(type = i, t(coef(lm_S)[c(2,4,6),2]))) } Scoef_se <- Scoef_se[-1,] # the MASE and MAPE table -------- digs <- 4 rbind(Industry = c("Casual Dine","Fine Dine","Photography","Outdoor","Body Care"), cbind(round(mase_ls[[2]][-1,][1,],digs),round(mase_ls[[5]][-1,][5,],digs),round(mase_ls[[11]][-1,][8,],digs), round(mase_ls[[10]][-1,][6,],digs),round(mase_ls[[1]][-1,][26,],digs)), cbind(round(mape_ls[[2]][-1,][1,],digs),round(mape_ls[[5]][-1,][5,],digs),round(mape_ls[[11]][-1,][8,],digs), round(mape_ls[[10]][-1,][6,],digs),round(mape_ls[[1]][-1,][26,],digs))) -> err_table rownames(err_table) <- c("Industry", "MASE (discount, $\\alpha$)","MASE (launch day to holiday, $T$)","MASE (duration, $d$)", "MAPE (discount, $\\alpha$)","MAPE (launch day to holiday, $T$)","MAPE (duration, $d$)") print(xtable(err_table[,c(4,1,2,5,3)]), only.contents=TRUE, include.rownames=T, include.colnames=T, floating=T, sanitize.rownames.function = identity, file = 'err_table.tex') # estimated structural parameters table ----- rbind(Industry = c("Casual Dine","Fine Dine","Photography","Outdoor","Body Care"), # type = industries_to_check, # c = signif(cvec,2), # cnh = signif(cnhvec,2), thetaalpha = format(round(pest_df$thetaalphahat,2)), thetaalphasig = paste("(",format(round(se_df$sethetaalpha,2)),")",sep=""), thetaT = format(round(pest_df$thetaThat,2)), thetaTsig = paste("(",format(round(se_df$sethetaT,2)),")",sep=""), thetad = format(round(pest_df$thetadhat,2)), thetadsig = paste("(",format(round(se_df$sethetad,2)),")",sep=""), betad = format(round(pest_df$betadhat,2)), betadsig = paste("(",format(round(se_df$sebetad,2)),")",sep=""), Salpha = format(round(Scoef$Salpha,2)), Salphasig = paste("(",format(round(Scoef_se$discprice,2)),")",sep=""), ST = format(round(Scoef$ST,2)), STsig = paste("(",format(round(Scoef_se$log.prep.period.,2)),")",sep=""), Sd = format(round(Scoef$Sd,2)), Sdsig = paste("(",format(round(Scoef_se$log.offering_duration.,2)),")",sep=""), # betad_nh=round(betad_nh,2), # betaalpha_nh=round(betaalpha_nh,2), sigma = format(round(gamma_h[industries_to_check,1],2)), sigmasig = paste("(",format(round(gamma_h_sig[industries_to_check,1],2)),")",sep=""), gamma = format(round(gamma_h[industries_to_check,2],2)), gammasig = paste("(",format(round(gamma_h_sig[industries_to_check,2],2)),")",sep=""), mch = format(round(pest_df$mch,2)), mchsig = paste("(",format(round(se_df$semch,2)),")",sep=""), mcnh = format(round(pest_df$mcnh,2)), mcnhsig = paste("(",format(round(se_df$semcnh,2)),")",sep=""), mcratiovec = format(round(pest_df$mcratio,2)), mcratiovecsig = paste("(",format(round(se_df$semcratio,2)),")",sep=""), ratiovec = format(round(pest_df$ratio,2)), ratiosig = paste("(",format(round(se_df$seratio,2)),")",sep=""), D1hvec = format(round(pest_df$D1h,0)), D1hsigvec = paste("(",format(round(se_df$seD1h,0)),")",sep=""), D2hvec = format(round(pest_df$D2h,2)), D2hsigvec = paste("(",format(round(se_df$seD2h,2)),")",sep=""), D2nhvec = format(round(pest_df$D2nh,2)), D2nhsigvec = paste("(",format(round(se_df$seD2nh,2)),")",sep=""), # mucpvec = signif(mucpvec,2), # sigcpvec = signif(sigcpvec,2), #dsidxvec = round(dsidxvec,2), #dsidxsigvec = round(dsidxsigvec,2), deltaDvec = format(round(pest_df$deltaDvec,2)), deltaDsigvec = paste("(",format(round(se_df$sedeltaDvec,2)),")",sep=""), # Varidxvec = round(Varidxvec,2), dsidx2vec = format(round(pest_df$dsidx2,2)) , dsidx2sigvec = paste("(",format(round(se_df$sedsidx2,2)),")",sep=""), alterDvec = format(round(pest_df$alterD,2)), alterDsigvec = paste("(",format(round(se_df$sealterD,2)),")",sep=""), alterPvec = format(round(pest_df$alterP,2)), alterPsigvec = paste("(",format(round(se_df$sealterP,2)),")",sep="") ) -> StructEstTable # StructEstTable <- StructEstTable[,c(4,1,2,5,3)] # rownames(StructEstTable) <- c("Industry", # # "Holiday cost parameter, $c_{h}$","Non-holiday cost parameter, $c_{nh}$", # "Discount sensitivity in deal demand allocation, $\\widehat{\\theta}_{\\alpha}$", # "s.e., discount sensitivity in demand allocation, $\\sigma_{\\theta_{\\alpha}}$", # "Launch time sensitivity in deal demand allocation, $\\widehat{\\theta}_T$", # "s.e., launch time sensitivity in demand allocation, $\\sigma_{\\theta_T}$", # "Duration sensitivity in deal demand allocation, $\\widehat{\\theta}_d$", # "s.e., duration sensitivity in demand allocation, $\\sigma_{\\theta_d}$", # "Duration sensitivity, holiday full price customers, $\\widehat{\\beta}_d$", # "s.e., duration sensitivity, holiday full price customers, $\\sigma_{\\beta_d}$", # "Discount sensitivity in deal sales volume, $\\widehat{\\theta}_{S,\\alpha}$", # "s.e., discount sensitivity in deal sales volume, $\\sigma_{\\theta_{S,\\alpha}}$", # "Launch time sensitivity in deal sales volume, $\\widehat{\\theta}_{S,T}$", # "s.e., launch time sensitivity in deal sales volume, $\\sigma_{\\theta_{S,T}}$", # "Duration sensitivity in deal sales volume, $\\widehat{\\theta}_{S,d}$", # "s.e., duration sensitivity in deal sales volume, $\\sigma_{\\theta_{S,d}}$", # # "Duration sensitivity, non-holiday full price customers, $\\beta_{d,nh}$", # # "Discount sensitivity, non-holiday full price customers,$\\beta_{\\alpha,nh}$", # "Baseline holiday demand variance, $\\widehat{\\sigma}_h$", # "Launch time sensitivity in demand variance, $\\widehat{\\gamma}_h$", # "Holiday marginal service costs, $\\widehat{mc}_h$", # "s.e., holiday marginal service costs, $\\sigma_{mc_{h}}$", # "Non-holiday marginal service costs, $\\widehat{mc}_{nh}$", # "s.e., non-holiday marginal service costs, $\\sigma_{mc_{nh}}$", # "Ratio of marginal cost price ratio, $\\widehat{R}_c \\triangleq \\frac{\\widehat{mc}_{h}}{p_h}/\\frac{\\widehat{mc}_{nh}}{p_{nh}}$", # "s.e., Ratio of marginal cost price ratio, $\\sigma_{R_c}$", # "Holidays redemption ratio, $\\widehat{r}$", # "s.e., holidays redemption ratio, $\\sigma_{r}$", # "Holiday discount demand, $\\widehat{D}_{r,h}$", # "s.e., holiday discount demand, $\\sigma_{D_{r,h}}$", # "Holiday full price demand, $\\widehat{D}_{nr,h}$", # "s.e., holiday full price demand, $\\sigma_{D_{nr,h}}$", # "Non-holiday full price demand, $\\widehat{D}_{nr,nh}$", # "s.e., non-holiday full price demand, $\\sigma_{D_{nr,nh}}$", # # "Holiday margianl cost price ratio, $\\widehat{\\frac{mc_{h}}{p}}$", # # "$\\sigma_{\\frac{mc_{h}}{p}}$", # "Holiday demand swings, $\\widehat{\\delta}(\\omega')$", # "s.e., holiday demand swings, $\\sigma_{\\delta(\\omega')}$", # # "Variance reduction index, $\\mathcal{R}$", # "Demand smoothing index, $\\mathcal{B}(\\omega',\\omega)$", # "s.e., demand smoothing index, $\\sigma_{\\mathcal{B}(\\omega',\\omega)}$", # "Percentage total demand change, $\\widehat{\\mathcal{M}}(\\omega,\\omega')$", # "s.e., percentage total demand change, $\\sigma_{\\mathcal{M}(\\omega,\\omega')}$", # "Total profit change, $\\widehat{\\mathcal{P}}(\\omega,\\omega')$", # "s.e., total profit change, $\\sigma_{\\mathcal{P}(\\omega,\\omega')}$") rownames(StructEstTable) <- c("Industry", # "Holiday cost parameter, $c_{h}$","Non-holiday cost parameter, $c_{nh}$", "Discount sensitivity in deal demand allocation, $\\widehat{\\theta}_{\\alpha}$", "$\\sigma_{\\theta_{\\alpha}}$", "Launch time sensitivity in deal demand allocation, $\\widehat{\\theta}_T$", "$\\sigma_{\\theta_T}$", "Duration sensitivity in deal demand allocation, $\\widehat{\\theta}_d$", "$\\sigma_{\\theta_d}$", "Duration sensitivity, holiday full price customers, $\\widehat{\\beta}_d$", "$\\sigma_{\\beta_d}$", "Discount sensitivity in deal sales volume, $\\widehat{\\theta}_{S,\\alpha}$", "$\\sigma_{\\theta_{S,\\alpha}}$", "Launch time sensitivity in deal sales volume, $\\widehat{\\theta}_{S,T}$", "$\\sigma_{\\theta_{S,T}}$", "Duration sensitivity in deal sales volume, $\\widehat{\\theta}_{S,d}$", "$\\sigma_{\\theta_{S,d}}$", # "Duration sensitivity, non-holiday full price customers, $\\beta_{d,nh}$", # "Discount sensitivity, non-holiday full price customers,$\\beta_{\\alpha,nh}$", "Baseline holiday demand variance, $\\widehat{\\sigma}_h$", "$\\sigma_{\\sigma_h}$", "Launch time sensitivity in demand variance, $\\widehat{\\gamma}_h$", "$\\sigma_{\\gamma_h}$", "Holiday marginal service costs, $\\widehat{mc}_h$", "$\\sigma_{mc_{h}}$", "Non-holiday marginal service costs, $\\widehat{mc}_{nh}$", "$\\sigma_{mc_{nh}}$", "Ratio of marginal cost price ratio, $\\widehat{R}_c \\triangleq \\frac{\\widehat{mc}_{h}}{p_h}/\\frac{\\widehat{mc}_{nh}}{p_{nh}}$", "$\\sigma_{R_c}$", "Holidays redemption ratio, $\\widehat{r}$", "$\\sigma_{r}$", "Holiday discount demand, $\\widehat{D}_{r,h}$", "$\\sigma_{D_{r,h}}$", "Holiday full price demand, $\\widehat{D}_{nr,h}$", "$\\sigma_{D_{nr,h}}$", "Non-holiday full price demand, $\\widehat{D}_{nr,nh}$", "$\\sigma_{D_{nr,nh}}$", # "Holiday margianl cost price ratio, $\\widehat{\\frac{mc_{h}}{p}}$", # "$\\sigma_{\\frac{mc_{h}}{p}}$", "Holiday demand swings, $\\widehat{\\delta}(\\omega')$", "$\\sigma_{\\delta(\\omega')}$", # "Variance reduction index, $\\mathcal{R}$", "Demand smoothing index, $\\widehat{\\mathcal{B}}(\\omega^*,\\omega')$", "$\\sigma_{\\mathcal{B}(\\omega^*,\\omega')}$", "Percentage total demand change, $\\widehat{\\mathcal{M}}(\\omega^*,\\omega')$", "$\\sigma_{\\mathcal{M}(\\omega^*,\\omega')}$", "Total profit change, $\\widehat{\\mathcal{P}}(\\omega^*,\\omega')$", "$\\sigma_{\\mathcal{P}(\\omega^*,\\omega')}$") print(xtable(StructEstTable[,c(4,1,2,5,3)]),#tabular.environment = "longtable", only.contents=TRUE, include.rownames=T, include.colnames=T, floating=F, sanitize.rownames.function = identity, file = 'table.tex') # end of S_alpha, S_T, S_d -------- # ------- End of displaying the estimators ------------- # View(bs_outputs_compile[c(1,14,23,25,32,40,64,66),]%>%mutate(mcratio = mucp/mucpnh)%>% select(type, dsidx,dsidx2,mcratio,mucp,alterD,alterP,deltaDvec)) #69/66, 38/37 View(bs_outputs_compile[c(1,13,23,38,66),]%>%mutate(mcratio = mucp/mucpnh)%>% select(type,mch,thetaalphahat,thetaThat,thetadhat,betadhat,dsidx,dsidx2,mcratio,mucp,alterD,alterP,deltaDvec)) # pt_est <- (bs_outputs_compile[c(1,13,23,38,66),]%>%mutate(mcratio = mucp/mucpnh)%>% # select(type,thetaalphahat,thetaThat,thetadhat,betadhat,dsidx,dsidx2,mcratio,mucp,alterD,alterP,deltaDvec)) # save(pt_est, file = "point_estimator.Rdata") # View(bs_outputs_compile%>%mutate(mcratio = mucp/mucpnh)%>% # select(type, dsidx,dsidx2,mcratio,mucp,alterD,alterDsigvec,alterP,deltaDvec,mase_dfremain,funvalue,D1h,D2h,mch)) # mean estimators and the standard deviation ----- # demand-boosting ---- flattendemand_df <- rbind(data.frame(type = 1,dsidx2 = compiled_results_ls[[1]]$dsidx2[[29]]), data.frame(type = 2,dsidx2 = compiled_results_ls[[2]]$dsidx2[[1]]), data.frame(type = 5,dsidx2 = compiled_results_ls[[5]]$dsidx2[[5]]), data.frame(type = 10,dsidx2 = compiled_results_ls[[10]]$dsidx2[[6]]), data.frame(type = 11,dsidx2 = compiled_results_ls[[11]]$dsidx2[[8]])) boostdemand_df <- rbind(data.frame(type = 1,changeind = compiled_results_ls[[1]]$dalter[[29]]), data.frame(type = 2,changeind = compiled_results_ls[[2]]$dalter[[1]]), data.frame(type = 5,changeind = compiled_results_ls[[5]]$dalter[[5]]), data.frame(type = 10,changeind = compiled_results_ls[[10]]$dalter[[6]]), data.frame(type = 11,changeind = compiled_results_ls[[11]]$dalter[[8]])) plotdata <- rbind(data.frame(type = 1,totald = pmax(compiled_results_ls[[1]]$Dtotal[[26]],0), totaldpri = compiled_results_ls[[1]]$Dtotalpri[[26]], dalter = compiled_results_ls[[1]]$dalter[[26]]), # data.frame(type = 2,totald = compiled_results_ls[[2]]$Dtotal[[1]][compiled_results_ls[[2]]$D2nhvalpri[[1]]<quantile(compiled_results_ls[[2]]$D2nhvalpri[[1]],0.6)], # totaldpri = compiled_results_ls[[2]]$Dtotalpri[[1]][compiled_results_ls[[2]]$D2nhvalpri[[1]]<quantile(compiled_results_ls[[2]]$D2nhvalpri[[1]],0.6)], # dalter = compiled_results_ls[[2]]$dalter[[1]][compiled_results_ls[[2]]$D2nhvalpri[[1]]<quantile(compiled_results_ls[[2]]$D2nhvalpri[[1]],0.6)]), data.frame(type = 2,totald = compiled_results_ls[[2]]$Dtotal[[1]][compiled_results_ls[[2]]$Dtotalpri[[1]]<quantile(compiled_results_ls[[2]]$Dtotalpri[[1]],0.6)& compiled_results_ls[[2]]$Dtotalpri[[1]]>quantile(compiled_results_ls[[2]]$Dtotalpri[[1]],0.1) ], totaldpri = compiled_results_ls[[2]]$Dtotalpri[[1]][compiled_results_ls[[2]]$Dtotalpri[[1]]<quantile(compiled_results_ls[[2]]$Dtotalpri[[1]],0.6)& compiled_results_ls[[2]]$Dtotalpri[[1]]>quantile(compiled_results_ls[[2]]$Dtotalpri[[1]],0.1)], dalter = compiled_results_ls[[2]]$dalter[[1]][compiled_results_ls[[2]]$Dtotalpri[[1]]<quantile(compiled_results_ls[[2]]$Dtotalpri[[1]],0.6)& compiled_results_ls[[2]]$Dtotalpri[[1]]>quantile(compiled_results_ls[[2]]$Dtotalpri[[1]],0.1)]), data.frame(type = 5,totald =pmax(compiled_results_ls[[5]]$Dtotal[[5]],0), totaldpri = compiled_results_ls[[5]]$Dtotalpri[[5]], dalter = compiled_results_ls[[5]]$dalter[[5]]), data.frame(type = 10,totald = pmax(compiled_results_ls[[10]]$Dtotal[[6]],0), totaldpri = compiled_results_ls[[10]]$Dtotalpri[[6]], dalter = compiled_results_ls[[10]]$dalter[[6]]), data.frame(type = 11,totald = pmax(compiled_results_ls[[11]]$Dtotal[[8]],0), totaldpri = compiled_results_ls[[11]]$Dtotalpri[[8]], dalter = compiled_results_ls[[11]]$dalter[[8]]))%>% group_by(type)%>% mutate(deltad = totald - totaldpri)%>% mutate(q90 = quantile(dalter,0.80),q10 = quantile(dalter,0.2))%>% filter(dalter<q90,dalter>q10)%>% merge(data.frame(type = c(2,5,11,10,1), Industry = c("Casual Dining","Fine Dining","Photography","Outdoor","Body Care")),by="type",all.x = TRUE) colpats <- c("Total Demand (Deals)"= "#66c2a5", "Total Demand (No Deals)" = "#fc8d62") ggplot(data=plotdata%>%filter())+ geom_histogram(aes(x=totaldpri,y = ..density..,fill="Total Demand (No Deals)"),color="grey30",bins = 50)+ #geom_line(aes(x=totaldpri,y = ..density..), stat = 'density', colour = '#fc8d62') + geom_histogram(aes(x=totald,y = ..density..,fill = "Total Demand (Deals)"),color="grey30",bins = 50)+ #blueish # geom_line(aes(x=totaldpri,y = ..density..), stat = 'density', colour = '#fc8d62') #geom_line(aes(x=totald,y = ..density..), stat = 'density', colour = '#66c2a5') + facet_grid(.~Industry,scales = "free")+ scale_fill_manual(values = colpats)+ labs(x="Total Demand (Units)", y = "", fill="")+ theme(legend.position = "bottom")+ coord_flip() -> p1 ggplot(data=plotdata)+ geom_histogram(aes(x=deltad,y = ..density..),fill="grey60",color="grey30",bins = 100)+ facet_grid(.~Industry,scales = "free")+ geom_vline(xintercept=0,linetype=2)+ labs(x="Change in Demand (Units)", y = "")+ coord_flip() -> p2 grid.arrange(p1,p2,nrow=2) mylegend<-g_legend(p1) grid.arrange(arrangeGrob(p1 + theme(legend.position="none"), mylegend, nrow=2,heights=c(16, 2)), p2 + theme(legend.position="none"),nrow=2) -> p_demandboosting # box plots for change in demand ------ ggplot(data=plotdata %>% filter(deltad>-1000))+ geom_boxplot(aes(x=Industry,y=deltad))+ # facet_grid(.~Industry,scales = "free")+ theme_bw(base_size = 18)+ labs(y="Change in Demand (Units)", x = "Industry") -> demanboosting_boxplot library(snpar) cdf_data <- c(0,0,0) for(i in industries_to_check){ plotdata_i <- plotdata %>% fl(type ==i) kde(plotdata_i$dalter, h = bw.nrd0(plotdata_i$dalter)/2,kernel = c("gaus")) -> cdf_plot cdf_data <- rbind(cdf_data,data.frame(Fhat = cdf_plot$Fhat, x = cdf_plot$x, type = i) ) } cdf_data <- cdf_data[-1,] colpats <- c("Demand Increase"= "#66c2a5", "Demand Valley" = "#fc8d62") ggplot(cdf_data %>% #fl(type!=2) %>% mt(DistType=ifelse(type%in%c(2,5),"Demand Increase","Demand Valley")), aes( x = x, y = Fhat, color=DistType, group=as.factor(type)))+ geom_line(aes(colour = DistType,group=as.factor(type)))+ # geom_hline(yintercept = 0, color="#993333")+ # geom_errorbar(aes(ymin=perc_cust_left_mean-1.96*perc_cust_left_sd, ymax=perc_cust_left_mean+1.96*perc_cust_left_sd), width=0.1, colour = 'blue')+ scale_color_manual(values = colpats)+ # xlim(c(-500,500))+ # theme( # axis.line.x = element_line(colour = 'black', size=0.5, linetype='solid'), # axis.line.y = element_line(colour = 'black', size=0.5, linetype='solid'), # panel.grid.minor.y= element_line(colour = "grey", linetype = "dotted"))+ # # scale_y_continuous(breaks = seq(0.3, 0.6, by = 0.05))+ labs(title = "", x = "Percentage of Demand Boosting", y = "Cumulated Percentage of Firms",color ="")+ theme(plot.title = element_text(hjust = 0.8))+ scale_y_continuous(labels = scales::percent)+ # theme(panel.grid.minor.y= element_line(colour = "grey", linetype = "dotted"))+ theme(legend.position = "bottom",legend.title = element_blank()) -> cdf_dalter colpats <- c("Demand Increase"= "grey10", "Demand Valley" = "grey70") ggplot(cdf_data %>% #fl(type!=2) %>% mt(DistType=ifelse(type%in%c(2,5),"Demand Increase","Demand Valley")), aes( x = x, y = Fhat, color=DistType, group=as.factor(type)))+ scale_color_manual(values = colpats)+ geom_line(aes(colour = DistType,group=as.factor(type)))+ labs(title = "", x = "Percentage of Demand Boosting", y = "Cumulated Percentage of Firms",color ="")+ theme_bw(base_size = 18) + theme(legend.position = "top", legend.background = element_rect(fill="grey80", size=0.5, linetype="solid", color="black"))+ scale_y_continuous(labels = scales::percent) -> cdf_dalter_bw mylegend<-g_legend(cdf_dalter_bw) grid.arrange(demanboosting_boxplot, arrangeGrob(mylegend, cdf_dalter_bw + theme(legend.position="none"), nrow=2, heights = c(3, 18)), ncol=2, widths = c(3,2)) -> demandboosting_bpcdf grid.arrange(demanboosting_boxplot,cdf_dalter_bw , ncol=2, widths = c(3,2)) -> demandboosting_bpcdf ggsave("~/Documents/GitHub/Project-Coupon/demandboosting_bpcdf.pdf",demandboosting_bpcdf,width = 18.17 ,height = 7.16,units = "in") # demand-smoothing ------- plotdata <- rbind(data.frame(type = 1,holgap = compiled_results_ls[[1]]$holgap[[26]], nonholgap = compiled_results_ls[[1]]$nonholgap[[26]], dsidx2 = compiled_results_ls[[1]]$dsidx2[[26]]), data.frame(type = 2,holgap = compiled_results_ls[[2]]$holgap[[1]], nonholgap = compiled_results_ls[[2]]$nonholgap[[1]], dsidx2 = compiled_results_ls[[2]]$dsidx2[[1]]), data.frame(type = 5,holgap =(compiled_results_ls[[5]]$holgap[[5]]), nonholgap = compiled_results_ls[[5]]$nonholgap[[5]], dsidx2 = compiled_results_ls[[5]]$dsidx2[[5]]), data.frame(type = 10,holgap = (compiled_results_ls[[10]]$holgap[[6]]), nonholgap = compiled_results_ls[[10]]$nonholgap[[6]], dsidx2 = compiled_results_ls[[10]]$dsidx2[[6]]), data.frame(type = 11,holgap = (compiled_results_ls[[11]]$holgap[[8]][compiled_results_ls[[11]]$dsidx2[[8]]<quantile(compiled_results_ls[[11]]$dsidx2[[8]],0.8)& compiled_results_ls[[11]]$dsidx2[[8]]>quantile(compiled_results_ls[[11]]$dsidx2[[8]],0.2)]), nonholgap = compiled_results_ls[[11]]$nonholgap[[8]][compiled_results_ls[[11]]$dsidx2[[8]]<quantile(compiled_results_ls[[11]]$dsidx2[[8]],0.8)& compiled_results_ls[[11]]$dsidx2[[8]]>quantile(compiled_results_ls[[11]]$dsidx2[[8]],0.2)], dsidx2 = compiled_results_ls[[11]]$dsidx2[[8]][compiled_results_ls[[11]]$dsidx2[[8]]<quantile(compiled_results_ls[[11]]$dsidx2[[8]],0.8)& compiled_results_ls[[11]]$dsidx2[[8]]>quantile(compiled_results_ls[[11]]$dsidx2[[8]],0.2)]))%>% group_by(type)%>% # mutate(smoothed = ifelse(type!=2,holval - nonholval, (nonholval - holval)))%>% mutate(smoothed = (holgap - nonholgap))%>% mutate(q90 = quantile(dsidx2,0.8),q10 = quantile(dsidx2,0.2))%>% filter(dsidx2<q90,dsidx2>q10)%>% merge(data.frame(type = c(2,5,11,10,1), Industry = c("Casual Dining","Fine Dining","Photography","Outdoor","Body Care")),by="type",all.x = TRUE) # tmp <- plotdata%>%filter(type==2) # dsidx2_adj[[2]] <- (tmp$nonholval - tmp$holval)/abs(tmp$holval) # # plotdata <- data.frame(holval =holval, nonholval = nonholval, type = typei)%>% # group_by(type)%>% # mutate(smoothed = ifelse(type!=2,holval - nonholval, ((nonholval) - holval)/holval))%>% # filter(type==2,nonholval>0,holval>0)%>%summarise(mean(smoothed)) colpats <- c("Demand Gap (Deals)"= "#66c2a5", "Demand Gap (No Deals)" = "#fc8d62") ggplot(data=plotdata%>%filter())+ geom_histogram(aes(x=nonholgap,y = ..density..,fill="Demand Gap (No Deals)"),color="grey30",bins = 50)+ #geom_line(aes(x=totaldpri,y = ..density..), stat = 'density', colour = '#fc8d62') + geom_histogram(aes(x=holgap,y = ..density..,fill = "Demand Gap (Deals)"),color="grey30",bins = 50)+ #blueish # geom_line(aes(x=totaldpri,y = ..density..), stat = 'density', colour = '#fc8d62') #geom_line(aes(x=totald,y = ..density..), stat = 'density', colour = '#66c2a5') + facet_grid(.~Industry,scales = "free")+ scale_fill_manual(values = colpats)+ labs(x="Demand Gap: Holiday-Non-holiday (Units Per Day)", y = "", fill="")+ theme(legend.position = "bottom")+ coord_flip() -> p1 ggplot(data=plotdata)+ geom_histogram(aes(x=smoothed,y = ..density..),fill="grey60",color="grey30",bins = 100)+ facet_grid(.~Industry,scales = "free")+ labs(x="Change in Demand Gap (Units Per Day)", y = "")+ geom_vline(xintercept=0,linetype =2)+ coord_flip() -> p2 # box plots for smoothed ------ ggplot(data=plotdata )+ geom_boxplot(aes(x=Industry,y=smoothed))+ # facet_grid(.~Industry,scales = "free")+ theme_bw(base_size = 18)+ labs(y="Change in Demand Gap (Units Per Day)", x = "Industry") -> demandsmoothing_boxplot grid.arrange(p1,p2,nrow=2) mylegend<-g_legend(p1) grid.arrange(arrangeGrob(p1 + theme(legend.position="none"), mylegend, nrow=2,heights=c(16, 2)), p2 + theme(legend.position="none"),nrow=2) -> p_demandsmoothing cdf_data <- c(0,0,0) for(i in c(2,5,11,10,1)){ plotdata_i <- plotdata %>% fl(type ==i) kde(plotdata_i$dsidx2, h = bw.nrd0(plotdata_i$dsidx2)/2,kernel = c("gaus")) -> cdf_plot cdf_data <- rbind(cdf_data,data.frame(Fhat = cdf_plot$Fhat, x = cdf_plot$x, type = i) ) } cdf_data <- cdf_data[-1,] colpats <- c("Large Marginal Cost Surge"= "#66c2a5", "Low Marginal Cost Surge" = "#fc8d62") ggplot(cdf_data %>% #fl(type!=2) %>% mt(DistType=ifelse(type%in%c(1,5,10),"Large Marginal Cost Surge","Low Marginal Cost Surge")), aes( x = x, y = Fhat, color=DistType, group=as.factor(type)))+ geom_line(aes(colour =DistType,group=as.factor(type)))+ # geom_hline(yintercept = 0, color="#993333")+ # geom_errorbar(aes(ymin=perc_cust_left_mean-1.96*perc_cust_left_sd, ymax=perc_cust_left_mean+1.96*perc_cust_left_sd), width=0.1, colour = 'blue')+ scale_color_manual(values = colpats)+ scale_y_continuous(labels = scales::percent)+ # xlim(c(-500,500))+ # theme( # axis.line.x = element_line(colour = 'black', size=0.5, linetype='solid'), # axis.line.y = element_line(colour = 'black', size=0.5, linetype='solid'), # panel.grid.minor.y= element_line(colour = "grey", linetype = "dotted"))+ # # scale_y_continuous(breaks = seq(0.3, 0.6, by = 0.05))+ labs(title = "", x = "Percentage of Demand Flattening", y = "Cumulated Percentage of Firms",color="")+ theme(legend.position = "bottom",legend.title = element_blank())-> cdf_smoothed colpats <- c("Large Marginal Cost Surge"= "grey10", "Low Marginal Cost Surge" = "grey70") ggplot(cdf_data %>% #fl(type!=2) %>% mt(DistType=ifelse(type%in%c(1,5,10),"Large Marginal Cost Surge","Low Marginal Cost Surge")), aes( x = x, y = Fhat, color=DistType, group=as.factor(type)))+ geom_line(aes(colour =DistType,group=as.factor(type)))+ scale_color_manual(values = colpats)+ scale_y_continuous(labels = scales::percent)+ labs(title = "", x = "Percentage of Demand Flattening", y = "Cumulated Percentage of Firms",color="")+ theme_bw(base_size = 18)+ theme(legend.position = "top", legend.background = element_rect(fill="grey80", size=0.5, linetype="solid", color="black")) -> cdf_smoothed_bw grid.arrange(demandsmoothing_boxplot,cdf_smoothed_bw , ncol=2, widths = c(3,2)) -> demandsmoothing_bpcdf ggsave("~/Documents/GitHub/Project-Coupon/demandsmoothing_bpcdf.pdf",demandsmoothing_bpcdf,width = 18.17 ,height = 7.16,units = "in") grid.arrange(cdf_dalter,cdf_smoothed,ncol=2) grid.arrange(p_demandboosting,cdf_dalter,ncol=2,widths = c(2.5,1)) grid.arrange(p_demandsmoothing,cdf_smoothed,ncol=2,widths = c(2.5,1)) mylegend<-g_legend(p1) grid.arrange(arrangeGrob(p1 + theme(legend.position="none"), mylegend, nrow=2,heights=c(16, 2)), p2 + theme(legend.position="none"),nrow=2) # the four quadrants --------- figures_df <- bs_outputs_compile[c(1,13,23,38,66),]%>%mutate(mcratio = mucp/mucpnh) figures_df <- bs_outputs_compile[c(1,16,23,38,66),]%>%mutate(mcratio = mucp/mucpnh) industrynames <- dealsfull%>%filter(type %in% industries_to_check)%>%select(type,detailed_cat_price)%>%unique() catnames <- data.frame(type = industries_to_check, Industry = c("Casual Dine", "Fine Dine", "Photography", "Outdoor", "Body Care")) plotdata <- merge(merge(industrynames, data.frame(type = industries_to_check, figures_df), by="type"),catnames,by="type")%>% mutate(alterlabel = (Industry == "Fine Dine"))%>%{.->>plottmp}%>% mutate(order_alterD = 6-rank(plottmp$alterD), order_dsidx = rank(abs(plottmp$dsidx2)))%>% select(alterlabel,type, Industry,detailed_cat_price, mucp, mcratio, deltaD, alterD, dsidx2, order_alterD, order_dsidx) ggplot(data=plotdata,aes(y=mcratio,x=deltaD))+geom_point(aes(size=order_dsidx,color=order_alterD))+ #geom_errorbarh(aes(xmax=deltad+1*deltadsig,xmin=deltad-1*deltadsig,y=(mcpratio)),size=0.7,height=0.0015) + #geom_errorbar(aes(ymax=mcpratio+1*mcpratiosd,ymin=mcpratio-1*mcpratiosd,x=(deltad)),size=0.7,width=0.15) + # geom_rect(mapping=aes(xmin=deltaD-1*deltaDsig, xmax=deltaD+1*deltaDsig, ymin=mcratio-1*mcratiosd, ymax=mcratio+1*mcaratiosd), # fill="grey70", color="grey30",alpha=0.3)+ geom_label(data=plotdata%>%filter(alterlabel==FALSE), aes(label=Industry),vjust = 1.0, hjust = 0.0 , nudge_x = 0.1)+ geom_label(data=plotdata%>%filter(alterlabel==TRUE), aes(label=Industry),vjust = -0.2, hjust = 1.4, nudge_x = 0.1)+ theme(panel.background = element_rect(fill="grey90",color="grey90"), #axis.title.x = element_blank(),axis.title.y=element_blank(), axis.text.y = element_text(size=10,face="bold"), axis.text.x = element_text(size=12,face="bold"), legend.justification = c("center", "bottom"), legend.text = element_text(size=12), legend.title = element_text(size=12), legend.background = element_rect(size=0.4, linetype="solid", colour ="black"), plot.margin=unit(c(0.5,1.5,0.5,1.0), "cm"))+ ylim(1, 8)+ geom_hline(yintercept=1,linetype=2)+ geom_vline(xintercept=0,linetype=2)+ labs(y=TeX("Ratio of Marginal Cost Price Ratio, $R_c$"), x = TeX("Holiday Demand Swing, $\\widehat{\\delta}(\\omega')$"), size=TeX("Mean-flattening (Order), $\\textit{B}(\\omega^*,\\omega')$"), color = TeX("Mean-boosting (Order), $\\textit{M}(\\omega^*,\\omega')$"))+ theme(legend.text = element_text(size=10),legend.title = element_text(size=10), legend.background = element_rect(color = NA), legend.box = "horizontal", legend.position = "bottom")+ scale_color_continuous(low = "black", high = "grey70") # # the deal parameteres --------- obs_deal_parameters <- c(0,0,0,0,0) obs_deal_parameters_ls <- vector(mode="list",length=11) for(i in industries_to_check){ if(i == 2){ hol_data <- dealsfull%>%filter(is.na(holiday)==0,type%in%c(2,3),prep.period>0,offering_duration<40)%>%{.->>dealsfull_type}%>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95)))%>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.4)), total_volume<quantile(dealsfull_type$total_volume,c(0.6)))%>% {.->>sdop}%>% mutate(original_price = original_price/sd(original_price)) # set.seed(300) # rs <-list() # for(b in 1:6){ # rs[[b]] <- sample(dim(hol_data)[1],dim(hol_data)[1],replace = T) # } # hol_data <- hol_data[rs[[6]],] # }else if(i %in% c(10)){ hol_data <- dealsfull%>%filter(is.na(holiday)==0,type==i,prep.period>0)%>%{.->>dealsfull_type}%>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95)))%>% {.->>sdop}%>% mutate(original_price = original_price/sd(original_price)) # set.seed(200) # rs <-list() # for(b in 1:1){ # rs[[b]] <- sample(dim(hol_data)[1],dim(hol_data)[1],replace = T) # } # hol_data <- hol_data[rs[[1]],] # }else if(i %in% c(11,1)){ hol_data <- dealsfull%>%filter(is.na(holiday)==0,type==i,prep.period>0,offering_duration<40)%>%{.->>dealsfull_type}%>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9)))%>% {.->>sdop}%>% mutate(original_price = original_price/sd(original_price)) # set.seed(200) # rs <-list() # for(b in 1:1){ # rs[[b]] <- sample(dim(hol_data)[1],dim(hol_data)[1],replace = T) # } # hol_data <- hol_data[rs[[1]],] }else{ hol_data <- dealsfull%>%filter(is.na(holiday)==0,type==i,prep.period>0,offering_duration<=40)%>%{.->>dealsfull_type}%>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95)))%>% {.->>sdop}%>% mutate(original_price = original_price/sd(original_price)) } obs_deal_parameters <- rbind(obs_deal_parameters,data.frame(type = i, trimeddf[[i]][[1]][,4:6], total_volume = hol_data$total_volume[-jidx_ls[[i]][[1]]], original_price = sdop$original_price[-jidx_ls[[i]][[1]]])) obs_deal_parameters_ls[[i]] <- data.frame(trimeddf[[i]][[1]], total_volume = hol_data$total_volume[-jidx_ls[[i]][[1]]], original_price = sdop$original_price[-jidx_ls[[i]][[1]]]) colnames(obs_deal_parameters_ls[[i]]) <- c("discount","prep.period","offering_duration", "discount","prep.period","offering_duration", "total_volume", "original_price") } obs_deal_parameters <- obs_deal_parameters[-1,] obs_deal_parameters <- obs_deal_parameters %>% mutate(volumebins = total_volume - (total_volume%%20)) ggplot(obs_deal_parameters%>%filter(total_volume<200)) + geom_point(aes(x=as.factor(type),y=prep.period))+ facet_wrap(.~volumebins) # alpha -------- merge(merge(merge(merge(obs_deal_parameters_ls[[10]][,c(4,5,6,7,8)]%>% mutate(volumebins = total_volume - (total_volume%%40))%>% mutate(durationbins = offering_duration - (offering_duration%%3))%>% mutate(preptbins = prep.period - (prep.period%%3))%>% mutate(pricebins = original_price - (original_price%%50))%>% mutate(alphabins = discount - (discount%%0.2))%>% rename(disc10 = discount, T10 = prep.period), obs_deal_parameters_ls[[2]][,c(4,5,6,7,8)]%>% mutate(volumebins = total_volume - (total_volume%%40))%>% mutate(durationbins = offering_duration - (offering_duration%%3))%>% mutate(preptbins = prep.period - (prep.period%%3))%>% mutate(pricebins = original_price - (original_price%%50))%>% mutate(alphabins = discount - (discount%%0.2))%>% rename(disc2 = discount, T2 = prep.period), by=c("preptbins","volumebins"),all=TRUE)%>% # group_by(volumebins,preptbins)%>% # summarise(disc10mu=mean(disc10,na.rm = TRUE),disc2mu=mean(disc2,na.rm = TRUE), # disc10sd=sd(disc10,na.rm = TRUE),disc2sd=sd(disc2,na.rm = TRUE))%>% select(volumebins,preptbins,disc2,disc10), obs_deal_parameters_ls[[11]][,c(4,5,6,7,8)]%>% mutate(volumebins = total_volume - (total_volume%%40))%>% mutate(durationbins = offering_duration - (offering_duration%%3))%>% mutate(preptbins = prep.period - (prep.period%%3))%>% mutate(pricebins = original_price - (original_price%%50))%>% mutate(alphabins = discount - (discount%%0.2))%>% rename(disc11 = discount, T11 = prep.period), by=c("preptbins","volumebins"),all=TRUE)%>% select(volumebins,preptbins, disc11,disc2,disc10), obs_deal_parameters_ls[[1]][,c(4,5,6,7,8)]%>% mutate(volumebins = total_volume - (total_volume%%40))%>% mutate(durationbins = offering_duration - (offering_duration%%3))%>% mutate(preptbins = prep.period - (prep.period%%3))%>% mutate(pricebins = original_price - (original_price%%50))%>% mutate(alphabins = discount - (discount%%0.2))%>% rename(disc1 = discount, T1 = prep.period), by=c("preptbins","volumebins"),all=TRUE)%>% select(volumebins,preptbins, disc11,disc2,disc10,disc1), obs_deal_parameters_ls[[5]][,c(4,5,6,7,8)]%>% mutate(volumebins = total_volume - (total_volume%%40))%>% mutate(durationbins = offering_duration - (offering_duration%%3))%>% mutate(preptbins = prep.period - (prep.period%%3))%>% mutate(pricebins = original_price - (original_price%%50))%>% mutate(alphabins = discount - (discount%%0.2))%>% rename(disc5 = discount, T5 = prep.period), by=c("preptbins","volumebins"),all=TRUE)%>% select(volumebins,preptbins, disc11,disc2,disc10,disc1,disc5)%>% group_by(preptbins,volumebins)%>% summarise(disc10mu=mean(disc10,na.rm = TRUE),disc2mu=mean(disc2,na.rm = TRUE),disc11mu=mean(disc11,na.rm = TRUE), disc1mu=mean(disc1,na.rm = TRUE),disc5mu=mean(disc5,na.rm = TRUE), disc10sd = sd(disc10,na.rm = TRUE),disc2sd = sd(disc2,na.rm = TRUE),disc11sd=sd(disc11,na.rm = TRUE), disc1sd=sd(disc1,na.rm = TRUE),disc5sd=sd(disc5,na.rm = TRUE))%>% filter(is.nan(disc10mu)+is.nan(disc2mu)+is.nan(disc11mu)+is.nan(disc1mu)+is.nan(disc5mu)<4) -> disc_cap_prept colpats <- c("#66c2a5", "#fc8d62", "#8da0cb", "#e78ac3", "#a6d854") colpats <- c("Outdoor"= "#66c2a5", "Casual Dine" = "#66c2a5", "Photography"= "#fc8d62", "Fine Dine" ="#66c2a5", "Body Care"= "#fc8d62") ggplot(data=disc_cap_prept)+ geom_point(aes(x=as.factor(volumebins),y=disc10mu,color = "Outdoor"))+ geom_point(aes(x=as.factor(volumebins),y=disc2mu,color = "Casual Dine"))+ geom_point(aes(x=as.factor(volumebins),y=disc11mu,color = "Photography"))+ geom_point(aes(x=as.factor(volumebins),y=disc5mu,color = "Fine Dine"))+ geom_point(aes(x=as.factor(volumebins),y=disc1mu,color = "Body Care"))+ geom_errorbar(aes(x=as.factor(volumebins), ymin = disc10mu-1*disc10sd, ymax = disc10mu+1*disc10sd,color = "Outdoor",collbs = colpats[1]),width=0.1,alpha=0.8)+ geom_errorbar(aes(x=as.factor(volumebins), ymin = disc2mu-1*disc2sd, ymax = disc2mu+1*disc2sd,color="Casual Dine",collbs = colpats[1]),width=0.1,alpha=0.8)+ geom_errorbar(aes(x=as.factor(volumebins), ymin = disc11mu-1*disc11sd, ymax = disc11mu+1*disc11sd,color="Photography",collbs = colpats[2]),width=0.1,alpha=0.8)+ geom_errorbar(aes(x=as.factor(volumebins), ymin = disc5mu-1*disc5sd, ymax = disc5mu+1*disc5sd,color="Fine Dine",collbs = colpats[2]),width=0.1,alpha=0.8)+ geom_errorbar(aes(x=as.factor(volumebins), ymin = disc1mu-1*disc1sd, ymax = disc1mu+1*disc1sd,color = "Body Care",collbs = colpats[2]),width=0.1,alpha=0.8)+ facet_grid(preptbins~.)+ scale_color_manual(values = colpats)+ labs(x="Capacity",y="Discount", color="Industry", facet="Release Date to Holiday")+ theme(legend.position = "bottom",legend.title = element_blank()) -> palpha # Launch day to holiday ------- merge(merge(merge(merge(obs_deal_parameters_ls[[10]][,c(4,5,6,7,8)]%>% filter(offering_duration<40)%>% mutate(volumebins = total_volume - (total_volume%%40))%>% mutate(durationbins = offering_duration - (offering_duration%%3))%>% mutate(preptbins = prep.period - (prep.period%%3))%>% mutate(pricebins = original_price - (original_price%%50))%>% mutate(alphabins = discount - (discount%%0.2))%>% rename(disc10 = discount, T10 = prep.period), obs_deal_parameters_ls[[2]][,c(1,2,3,7,8)]%>% filter(offering_duration<40)%>% mutate(volumebins = total_volume - (total_volume%%40))%>% mutate(durationbins = offering_duration - (offering_duration%%3))%>% mutate(preptbins = prep.period - (prep.period%%3))%>% mutate(pricebins = original_price - (original_price%%50))%>% mutate(alphabins = discount - (discount%%0.2))%>% rename(disc2 = discount, T2 = prep.period), by=c("alphabins","volumebins"),all=TRUE)%>% # group_by(volumebins,preptbins)%>% # summarise(disc10mu=mean(disc10,na.rm = TRUE),disc2mu=mean(disc2,na.rm = TRUE), # disc10sd=sd(disc10,na.rm = TRUE),disc2sd=sd(disc2,na.rm = TRUE))%>% select(volumebins,alphabins,T2,T10), obs_deal_parameters_ls[[11]][,c(4,5,6,7,8)]%>% filter(offering_duration<40)%>% mutate(volumebins = total_volume - (total_volume%%40))%>% mutate(durationbins = offering_duration - (offering_duration%%3))%>% mutate(preptbins = prep.period - (prep.period%%3))%>% mutate(pricebins = original_price - (original_price%%50))%>% mutate(alphabins = discount - (discount%%0.2))%>% rename(disc11 = discount, T11 = prep.period), by=c("alphabins","volumebins"),all=TRUE)%>% select(volumebins,alphabins, T11,T2,T10), obs_deal_parameters_ls[[1]][,c(4,5,6,7,8)]%>% filter(offering_duration<40)%>% mutate(volumebins = total_volume - (total_volume%%40))%>% mutate(durationbins = offering_duration - (offering_duration%%3))%>% mutate(preptbins = prep.period - (prep.period%%3))%>% mutate(pricebins = original_price - (original_price%%50))%>% mutate(alphabins = discount - (discount%%0.2))%>% rename(disc1 = discount, T1 = prep.period), by=c("alphabins","volumebins"),all=TRUE)%>% select(volumebins,alphabins, T11,T2,T10,T1), obs_deal_parameters_ls[[5]][,c(1,2,3,7,8)]%>% filter(offering_duration<40)%>% mutate(volumebins = total_volume - (total_volume%%40))%>% mutate(durationbins = offering_duration - (offering_duration%%3))%>% mutate(preptbins = prep.period - (prep.period%%3))%>% mutate(pricebins = original_price - (original_price%%50))%>% mutate(alphabins = discount - (discount%%0.2))%>% rename(disc5 = discount, T5 = prep.period), by=c("alphabins","volumebins"),all=TRUE)%>% select(volumebins,alphabins, T11,T2,T10,T1,T5)%>% group_by(alphabins,volumebins)%>% summarise(T10mu=mean(T10,na.rm = TRUE),T2mu=mean(T2,na.rm = TRUE),T11mu=mean(T11,na.rm = TRUE), T1mu=mean(T1,na.rm = TRUE),T5mu=mean(T5,na.rm = TRUE), T10sd = sd(T10,na.rm = TRUE),T2sd = sd(T2,na.rm = TRUE),T11sd=sd(T11,na.rm = TRUE), T1sd=sd(T1,na.rm = TRUE),T5sd=sd(T5,na.rm = TRUE))%>% filter(is.nan(T10mu)+is.nan(T2mu)+is.nan(T11mu)+is.nan(T1mu)+is.nan(T5mu)<3) -> T_cap_prept colpats <- c("#66c2a5", "#fc8d62", "#8da0cb", "#e78ac3", "#a6d854") colpats <- c("Outdoor"= "#66c2a5", "Casual Dine" = "#66c2a5", "Photography"= "#66c2a5", "Fine Dine" = "#fc8d62", "Body Care"= "#fc8d62") collabs <- c("Late Release"= "#66c2a5", "Early Release" = "#fc8d62") ggplot(data=T_cap_prept)+ geom_point(aes(x=as.factor(volumebins),y=T10mu,color = "Outdoor"))+ geom_point(aes(x=as.factor(volumebins),y=T2mu,color = "Casual Dine"))+ geom_point(aes(x=as.factor(volumebins),y=T11mu,color = "Photography"))+ geom_point(aes(x=as.factor(volumebins),y=T5mu,color = "Fine Dine"))+ geom_point(aes(x=as.factor(volumebins),y=T1mu,color = "Body Care"))+ geom_errorbar(aes(x=as.factor(volumebins), ymin = T10mu-0.5*T10sd, ymax = T10mu+0.5*T10sd,color = "Outdoor",collabs="Late Release"),width=0.1,alpha=0.8)+ geom_errorbar(aes(x=as.factor(volumebins), ymin = T2mu-0.5*T2sd, ymax = T2mu+0.5*T2sd,color = "Casual Dine",collabs="Early Release"),width=0.1,alpha=0.8)+ geom_errorbar(aes(x=as.factor(volumebins), ymin = T11mu-0.5*T11sd, ymax = T11mu+0.5*T11sd,color = "Photography",collabs="Early Release"),width=0.1,alpha=0.8)+ geom_errorbar(aes(x=as.factor(volumebins), ymin = T5mu-0.5*T5sd, ymax = T5mu+0.5*T5sd,color = "Fine Dine",collabs="Late Release"),width=0.1,alpha=0.8)+ geom_errorbar(aes(x=as.factor(volumebins), ymin = T1mu-0.5*T1sd, ymax = T1mu+0.5*T1sd,color = "Body Care",collabs="Early Release"),width=0.1,alpha=0.8)+ facet_grid(alphabins~.)+ scale_color_manual(values = colpats)+ labs(x="Capacity",y="Launch Date to Holiday", color="Industry", facet="Discount")+ theme(legend.position = "bottom",legend.title = element_blank()) -> pT # can add in another metric, the % of cover or higher than the other x <- seq(4.1,50,0.1) K <- 0.8 y1 <- (1+0.88*K)*(x/(1+x)) - (x/(1+x)) y2 <- (1+6.33*K)*((x-3.74)/(1+x-3.74)) - (x/(1+x)) ggplot()+ geom_line(aes(x=x,y=y1),color="red")+ geom_line(aes(x=x,y=y2),color="blue") # duration ---------- merge(merge(merge(merge(obs_deal_parameters_ls[[10]][,c(4,5,6,7,8)]%>% #filter(offering_duration<40)%>% mutate(offering_duration = offering_duration-prep.period)%>% mutate(volumebins = total_volume - (total_volume%%40))%>% mutate(durationbins = offering_duration - (offering_duration%%3))%>% mutate(preptbins = prep.period - (prep.period%%3))%>% mutate(pricebins = original_price - (original_price%%50))%>% mutate(alphabins = discount - (discount%%0.2))%>% rename(disc10 = discount, T10 = prep.period, d10 = offering_duration), obs_deal_parameters_ls[[2]][,c(1,2,3,7,8)]%>% #filter(offering_duration<40)%>% mutate(offering_duration = offering_duration-prep.period)%>% mutate(volumebins = total_volume - (total_volume%%40))%>% mutate(durationbins = offering_duration - (offering_duration%%3))%>% mutate(preptbins = prep.period - (prep.period%%3))%>% mutate(pricebins = original_price - (original_price%%50))%>% mutate(alphabins = discount - (discount%%0.2))%>% rename(disc2 = discount, T2 = prep.period, d2 = offering_duration), by=c("alphabins","volumebins"),all=TRUE)%>% # group_by(volumebins,preptbins)%>% # summarise(disc10mu=mean(disc10,na.rm = TRUE),disc2mu=mean(disc2,na.rm = TRUE), # disc10sd=sd(disc10,na.rm = TRUE),disc2sd=sd(disc2,na.rm = TRUE))%>% select(volumebins,alphabins,d2,d10), obs_deal_parameters_ls[[11]][,c(4,5,6,7,8)]%>% # filter(offering_duration<40)%>% mutate(offering_duration = offering_duration-prep.period)%>% mutate(volumebins = total_volume - (total_volume%%40))%>% mutate(durationbins = offering_duration - (offering_duration%%3))%>% mutate(preptbins = prep.period - (prep.period%%3))%>% mutate(pricebins = original_price - (original_price%%50))%>% mutate(alphabins = discount - (discount%%0.2))%>% rename(disc11 = discount, T11 = prep.period, d11 = offering_duration), by=c("alphabins","volumebins"),all=TRUE)%>% select(volumebins,alphabins, d11,d2,d10), obs_deal_parameters_ls[[1]][,c(4,5,6,7,8)]%>% # filter(offering_duration<40)%>% mutate(offering_duration = offering_duration-prep.period)%>% mutate(volumebins = total_volume - (total_volume%%40))%>% mutate(durationbins = offering_duration - (offering_duration%%3))%>% mutate(preptbins = prep.period - (prep.period%%3))%>% mutate(pricebins = original_price - (original_price%%50))%>% mutate(alphabins = discount - (discount%%0.2))%>% rename(disc1 = discount, T1 = prep.period, d1 = offering_duration), by=c("alphabins","volumebins"),all=TRUE)%>% select(volumebins,alphabins, d11,d2,d10,d1), obs_deal_parameters_ls[[5]][,c(1,2,3,7,8)]%>% #filter(offering_duration<40)%>% mutate(offering_duration = offering_duration-prep.period)%>% mutate(volumebins = total_volume - (total_volume%%40))%>% mutate(durationbins = offering_duration - (offering_duration%%3))%>% mutate(preptbins = prep.period - (prep.period%%3))%>% mutate(pricebins = original_price - (original_price%%50))%>% mutate(alphabins = discount - (discount%%0.2))%>% rename(disc5 = discount, T5 = prep.period, d5 = offering_duration), by=c("alphabins","volumebins"),all=TRUE)%>% select(volumebins,alphabins, d11,d2,d10,d1,d5)%>% group_by(alphabins,volumebins)%>% summarise(d10mu=mean(d10,na.rm = TRUE),d2mu=mean(d2,na.rm = TRUE),d11mu=mean(d11,na.rm = TRUE), d1mu=mean(d1,na.rm = TRUE),d5mu=mean(d5,na.rm = TRUE), d10sd = sd(d10,na.rm = TRUE),d2sd = sd(d2,na.rm = TRUE),d11sd=sd(d11,na.rm = TRUE), d1sd=sd(d1,na.rm = TRUE),d5sd=sd(d5,na.rm = TRUE))%>% filter(is.nan(d10mu)+is.nan(d2mu)+is.nan(d11mu)+is.nan(d1mu)+is.nan(d5mu)<3) -> d_cap_prept colpats <- c("#66c2a5", "#fc8d62", "#8da0cb", "#e78ac3", "#a6d854") colpats <- c("Outdoor"= "#fc8d62", "Casual Dine" = "#fc8d62", "Photography"= "#66c2a5", "Fine Dine" ="#66c2a5", "Body Care"= "#66c2a5") ggplot(data=d_cap_prept)+ geom_point(aes(x=as.factor(volumebins),y=d10mu,color = "Outdoor"))+ geom_point(aes(x=as.factor(volumebins),y=d2mu,color = "Casual Dine"))+ geom_point(aes(x=as.factor(volumebins),y=d11mu,color = "Photography"))+ geom_point(aes(x=as.factor(volumebins),y=d5mu,color = "Fine Dine"))+ geom_point(aes(x=as.factor(volumebins),y=d1mu,color = "Body Care"))+ geom_errorbar(aes(x=as.factor(volumebins), ymin = d10mu-0.5*d10sd, ymax = d10mu+0.5*d10sd,color = "Outdoor",collbs = colpats[1]),width=0.1,alpha=0.8)+ geom_errorbar(aes(x=as.factor(volumebins), ymin = d2mu-0.5*d2sd, ymax = d2mu+0.5*d2sd,color="Casual Dine",collbs = colpats[1]),width=0.1,alpha=0.8)+ geom_errorbar(aes(x=as.factor(volumebins), ymin = d11mu-0.5*d11sd, ymax = d11mu+0.5*d11sd,color="Photography",collbs = colpats[2]),width=0.1,alpha=0.8)+ geom_errorbar(aes(x=as.factor(volumebins), ymin = d5mu-0.5*d5sd, ymax = d5mu+0.5*d5sd,color="Fine Dine",collbs = colpats[2]),width=0.1,alpha=0.8)+ geom_errorbar(aes(x=as.factor(volumebins), ymin = d1mu-0.5*d1sd, ymax = d1mu+0.5*d1sd,color = "Body Care",collbs = colpats[2]),width=0.1,alpha=0.8)+ facet_grid(alphabins~.)+ scale_color_manual(values = colpats)+ labs(x="Capacity",y="Duration", color="Industry", facet="Discount")+ theme(legend.position = "bottom",legend.title = element_blank()) -> pd grid.arrange(palpha,pT,pd,ncol=3) ### data description -------- # t test ------- datadim_h <- vector() datadim_nh <- vector() data_h_ls <- vector(mode = "list", length = 11) data_nh_ls <- vector(mode = "list", length = 11) predays_t <- 20 pre.windows_t <- c(seq(21-predays_t,21),seq(44-predays_t,44),seq(92-predays_t,92)) for (i in industries_to_check){ print(i) if(i == 2){ data_h <- dealsfull%>%filter(is.na(holiday)==0,type%in%c(2,3)) %>% fl(prep.period>0,prep.period<40) %>%{.->>dealsfull_type}%>% filter(original_price>quantile(dealsfull_type$original_price,c(0.4)), original_price<quantile(dealsfull_type$original_price,c(0.6))) %>% {.->>sdop} %>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) data_h_ls[[i]] <- data_h print(dim(sdop)) datadim_h <- c(datadim_h,dim(sdop)[1]) data_nh <- dealsfull%>% filter(type%in%c(2,3)) %>% mutate(end_dow_dm = launch_dow_dm+offering_duration)%>% filter(is.na(holiday)==1,type==i,end_dow_dm%in%pre.windows_t)%>%{.->>dealsfull_type}%>%{.->>sdop} %>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) # data_nh <- dealsfull%>%filter(is.na(holiday)==1,type%in%c(2)) %>% # {.->>dealsfull_type}%>% # # filter(total_volume>quantile(dealsfull_type$total_volume,c(0.4)), total_volume<quantile(dealsfull_type$total_volume,c(0.6))) %>% # {.->>sdop} %>% # filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95))) data_nh_ls[[i]] <- data_nh datadim_nh <- c(datadim_nh,dim(sdop)[1]) }else{ data_h <- dealsfull%>%filter(is.na(holiday)==0,type==i)%>% {.->>sdop}%>%{.->>dealsfull_type} %>% fl(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) data_h_ls[[i]] <- data_h datadim_h <- c(datadim_h,dim(sdop)[1]) data_nh <- dealsfull%>% mutate(end_dow_dm = launch_dow_dm+offering_duration)%>% filter(is.na(holiday)==1,type==i,end_dow_dm%in%pre.windows_t)%>%{.->>dealsfull_type}%>%{.->>sdop} %>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) # data_nh <- dealsfull%>%filter(is.na(holiday)==1,type==i)%>% # {.->>sdop}%>%{.->>dealsfull_type} %>% # fl(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95))) data_nh_ls[[i]] <- data_nh datadim_nh <- c(datadim_nh,dim(sdop)[1]) } print(dim(sdop)) datasanalysis <- c(datasanalysis,dim(sdop)[1]) } alphat <- vector() Tt <- vector() dt <- vector() salest <- vector() pt <- vector() alphaks <- vector() Tks <- vector() dks <- vector() salesks <- vector() pks <- vector() for(i in industries_to_check){ alphat <- c(alphat,t.test((1-data_nh_ls[[i]]$discount)*data_nh_ls[[i]]$original_price_sd, (1-data_h_ls[[i]]$discount)*data_h_ls[[i]]$original_price_sd)$p.value) # Tt <- c(Tt,t.test(data_nh_ls[[i]]$prep.period, data_h_ls[[i]]$prep.period)$p.value) dt <- c(dt,t.test(data_nh_ls[[i]]$offering_duration, data_h_ls[[i]]$offering_duration)$p.value) salest <- c(salest,t.test(data_nh_ls[[i]]$total_volume, data_h_ls[[i]]$total_volume)$p.value) pt <- c(pt,t.test(data_nh_ls[[i]]$original_price, data_h_ls[[i]]$original_price)$p.value) alphaks <- c(alphaks,ks.test((1-data_nh_ls[[i]]$discount)*data_nh_ls[[i]]$original_price_sd, (1-data_h_ls[[i]]$discount)*data_h_ls[[i]]$original_price_sd)$p.value) # Tks <- c(Tks,ks.test(data_nh_ls[[i]]$prep.period, data_h_ls[[i]]$prep.period)$p.value) dks <- c(dks,ks.test(data_nh_ls[[i]]$offering_duration, data_h_ls[[i]]$offering_duration)$p.value) salesks <- c(salesks,ks.test(data_nh_ls[[i]]$total_volume, data_h_ls[[i]]$total_volume)$p.value) pks <- c(pks,ks.test(data_nh_ls[[i]]$original_price, data_h_ls[[i]]$original_price)$p.value) } ## ks test -------- datadim_h <- vector() datadim_nh <- vector() data_h_ls <- vector(mode = "list", length = 11) data_nh_ls <- vector(mode = "list", length = 11) predays_t <- 15 pre.windows_t <- c(seq(21-predays_t,21),seq(44-predays_t,44),seq(92-predays_t,92)) for (i in industries_to_check){ print(i) if(i == 2){ data_h <- dealsfull%>%filter(is.na(holiday)==0,type%in%c(2,3)) %>% fl(offering_duration<40) %>% {.->>dealsfull_type}%>% filter(original_price>quantile(dealsfull_type$original_price,c(0.4)), original_price<quantile(dealsfull_type$original_price,c(0.6))) %>% {.->>sdop} %>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) data_h_ls[[i]] <- data_h print(dim(sdop)) datadim_h <- c(datadim_h,dim(sdop)[1]) data_nh <- dealsfull%>% filter(type%in%c(2,3)) %>% mutate(end_dow_dm = launch_dow_dm+offering_duration)%>% filter(is.na(holiday)==1,type==i,end_dow_dm%in%pre.windows_t)%>%{.->>dealsfull_type}%>%{.->>sdop} %>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) # data_nh <- dealsfull%>%filter(is.na(holiday)==1,type%in%c(2)) %>% # {.->>dealsfull_type}%>% # # filter(total_volume>quantile(dealsfull_type$total_volume,c(0.4)), total_volume<quantile(dealsfull_type$total_volume,c(0.6))) %>% # {.->>sdop} %>% # filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95))) data_nh_ls[[i]] <- data_nh datadim_nh <- c(datadim_nh,dim(sdop)[1]) }else{ data_h <- dealsfull%>%filter(is.na(holiday)==0,type==i)%>% fl(offering_duration<40) %>% {.->>sdop}%>%{.->>dealsfull_type} %>% fl(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) data_h_ls[[i]] <- data_h datadim_h <- c(datadim_h,dim(sdop)[1]) data_nh <- dealsfull%>% mutate(end_dow_dm = launch_dow_dm+offering_duration)%>% filter(is.na(holiday)==1,type==i,end_dow_dm%in%pre.windows_t)%>%{.->>dealsfull_type}%>%{.->>sdop} %>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) # data_nh <- dealsfull%>%filter(is.na(holiday)==1,type==i)%>% # {.->>sdop}%>%{.->>dealsfull_type} %>% # fl(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95))) data_nh_ls[[i]] <- data_nh datadim_nh <- c(datadim_nh,dim(sdop)[1]) } print(dim(sdop)) datasanalysis <- c(datasanalysis,dim(sdop)[1]) } alphat_i <- matrix(rep(0,5^2), ncol= 5,byrow=T) Tt_i <- matrix(rep(0,5^2), ncol= 5,byrow=T) dt_i <- matrix(rep(0,5^2), ncol= 5,byrow=T) alphaks_i <- matrix(rep(0,5^2), ncol= 5,byrow=T) Tks_i <- matrix(rep(0,5^2), ncol= 5,byrow=T) dks_i <- matrix(rep(0,5^2), ncol= 5,byrow=T) iidx <- 1 jidx <- 1 for(i in industries_to_check){ jidx <- 1 for(j in industries_to_check){ alphat_i[iidx,jidx] <- t.test((1-data_h_ls[[i]]$discount)*data_h_ls[[i]]$original_price_sd, (1-data_h_ls[[j]]$discount)*data_h_ls[[j]]$original_price_sd)$p.value Tt_i[iidx,jidx]<- t.test(data_h_ls[[i]]$prep.period, data_h_ls[[j]]$prep.period)$p.value dt_i[iidx,jidx]<- t.test(data_h_ls[[i]]$offering_duration, data_h_ls[[j]]$offering_duration)$p.value alphaks_i[iidx,jidx] <- ks.test((1-data_h_ls[[i]]$discount)*data_h_ls[[i]]$original_price_sd, (1-data_h_ls[[j]]$discount)*data_h_ls[[j]]$original_price_sd)$p.value Tks_i[iidx,jidx] <- ks.test(data_h_ls[[i]]$prep.period, data_h_ls[[j]]$prep.period)$p.value dks_i[iidx,jidx] <- ks.test(data_h_ls[[i]]$offering_duration, data_h_ls[[j]]$offering_duration)$p.value jidx <- jidx + 1 } iidx <- iidx +1 } rbind(Industry = c("Casual Dine","Fine Dine","Photography","Outdoor","Body Care"), # type = industries_to_check, # c = signif(cvec,2), # cnh = signif(cnhvec,2), alphaks = format(signif(alphaks,2)), alphat = format(signif(alphat,2)), dks = format(signif(dks,2)), dt = format(signif(dt,2)), pks = format(signif(pks,2)), pt = format(signif(pt,2))) -> testrestuls alphaks_i <- format(signif(alphaks_i,2)) alphat_i <- format(signif(alphat_i,2)) Tks_i <- format(signif(Tks_i,2)) Tt_i <- format(signif(Tt_i,2)) dks_i <- format(signif(dks_i,2)) dt_i <- format(signif(dt_i,2)) alphaks_i[lower.tri(alphaks_i,diag=TRUE)] <- NA alphat_i[lower.tri(alphat_i,diag=TRUE)] <- NA Tks_i[lower.tri(Tks_i,diag=TRUE)] <- NA Tt_i[lower.tri(Tt_i,diag=TRUE)] <- NA dks_i[lower.tri(dks_i,diag=TRUE)] <- NA dt_i[lower.tri(dt_i,diag=TRUE)] <- NA # rbind(c(c("Casual Dine","Fine Dine","Photography","Outdoor","Body Care"), # c("Casual Dine","Fine Dine","Photography","Outdoor","Body Care")), # cbind((alphaks_i),alphat_i), # cbind((Tks_i),Tt_i), # cbind((dks_i),dt_i)) -> indtestresults # rownames(indtestresults) <- c("Industry", # "Casual Dine, $(1-\\alpha)p$","Fine Dine, $(1-\\alpha)p$", # "Photography, $(1-\\alpha)p$","Outdoor, $(1-\\alpha)p$","Body Care, $(1-\\alpha)p$", # "Casual Dine, $T$","Fine Dine, $T$","Photography, $T$", # "Outdoor, $T$","Body Care, $T$", # "Casual Dine, $d$","Fine Dine, $d$","Photography, $d$", # "Outdoor, $d$","Body Care, $d$") rbind(c("Casual Dine","Fine Dine","Photography","Outdoor","Body Care"), (alphaks_i),alphat_i, (Tks_i),Tt_i, (dks_i),dt_i) -> indtestresults rownames(indtestresults) <- c("Industry", "Casual Dine, ks test, $(1-\\alpha)p$","Fine Dine, ks test, $(1-\\alpha)p$", "Photography, ks test, $(1-\\alpha)p$","Outdoor, ks test, $(1-\\alpha)p$","Body Care, ks test, $(1-\\alpha)p$", "Casual Dine, t test, $(1-\\alpha)p$","Fine Dine, t test, $(1-\\alpha)p$", "Photography, t test, $(1-\\alpha)p$","Outdoor, t test, $(1-\\alpha)p$","Body Care, t test, $(1-\\alpha)p$", "Casual Dine, ks test, $T$","Fine Dine, ks test, $T$","Photography, ks test, $T$", "Outdoor, ks test, $T$","Body Care, ks test, $T$", "Casual Dine, t test, $T$","Fine Dine, t test, $T$","Photography, t test, $T$", "Outdoor, t test, $T$","Body Care, t test, $T$", "Casual Dine, ks test, $d$","Fine Dine, ks test, $d$","Photography, ks test, $d$", "Outdoor, ks test, $d$","Body Care, ks test, $d$", "Casual Dine, t test, $d$","Fine Dine, t test, $d$","Photography, t test, $d$", "Outdoor, t test, $d$","Body Care, t test, $d$") print(xtable(indtestresults),#tabular.environment = "longtable", only.contents=TRUE, include.rownames=T, include.colnames=T, floating=F, sanitize.rownames.function = identity, file = 'indtestresultstable1.tex') # multivariate test, cramer test ------- datadim_h <- vector() datadim_nh <- vector() data_h_ls <- vector(mode = "list", length = 11) data_nh_ls <- vector(mode = "list", length = 11) predays_t <- 15 pre.windows_t <- c(seq(21-predays_t,21),seq(44-predays_t,44),seq(92-predays_t,92)) for (i in industries_to_check){ print(i) if(i == 2){ data_h <- dealsfull%>%filter(is.na(holiday)==0,type%in%c(2,3)) %>% fl(offering_duration<40) %>% {.->>dealsfull_type}%>% # filter(original_price>quantile(dealsfull_type$original_price,c(0.4)), original_price<quantile(dealsfull_type$original_price,c(0.6))) %>% {.->>sdop} %>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) data_h_ls[[i]] <- data_h print(dim(sdop)) datadim_h <- c(datadim_h,dim(sdop)[1]) data_nh <- dealsfull%>% filter(type%in%c(2,3)) %>% mutate(end_dow_dm = launch_dow_dm+offering_duration)%>% filter(is.na(holiday)==1,type==i,end_dow_dm%in%pre.windows_t)%>%{.->>dealsfull_type}%>%{.->>sdop} %>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) # data_nh <- dealsfull%>%filter(is.na(holiday)==1,type%in%c(2)) %>% # {.->>dealsfull_type}%>% # # filter(total_volume>quantile(dealsfull_type$total_volume,c(0.4)), total_volume<quantile(dealsfull_type$total_volume,c(0.6))) %>% # {.->>sdop} %>% # filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95))) data_nh_ls[[i]] <- data_nh datadim_nh <- c(datadim_nh,dim(sdop)[1]) }else{ data_h <- dealsfull%>%filter(is.na(holiday)==0,type==i)%>% fl(offering_duration<40) %>% {.->>sdop}%>%{.->>dealsfull_type} %>% fl(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) data_h_ls[[i]] <- data_h datadim_h <- c(datadim_h,dim(sdop)[1]) data_nh <- dealsfull%>% mutate(end_dow_dm = launch_dow_dm+offering_duration)%>% filter(is.na(holiday)==1,type==i,end_dow_dm%in%pre.windows_t)%>%{.->>dealsfull_type}%>%{.->>sdop} %>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) # data_nh <- dealsfull%>%filter(is.na(holiday)==1,type==i)%>% # {.->>sdop}%>%{.->>dealsfull_type} %>% # fl(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95))) data_nh_ls[[i]] <- data_nh datadim_nh <- c(datadim_nh,dim(sdop)[1]) } print(dim(sdop)) datasanalysis <- c(datasanalysis,dim(sdop)[1]) } set.seed(123) data_h_ls[[11]] <- data_h_ls[[11]][sample(dim(data_h_ls[[11]])[1],200,replace = T),] library(cramer) cramertestresult1 <- matrix(rep(0,5^2), ncol= 5,byrow=T) cramertestresult_ls1 <- vector(mode="list",length=25) iidx <- 1 jidx <- 1 ct <- 1 for(i in industries_to_check){ jidx <- iidx+1 for(j in industries_to_check[(iidx+1):5]){ cramer_holi <- cbind((1-data_h_ls[[i]]$discount)*data_h_ls[[i]]$original_price_sd, data_h_ls[[i]]$prep.period, data_h_ls[[i]]$offering_duration) cramer_holj <- cbind((1-data_h_ls[[j]]$discount)*data_h_ls[[j]]$original_price_sd, data_h_ls[[j]]$prep.period, data_h_ls[[j]]$offering_duration) cramertestresult_ls1[[ct]] <- cramer.test(cramer_holi,cramer_holj,conf.level=0.95,replicates=500,sim="permutation") # print(cramertestresult_ls1[[ct]]$p.value) cramertestresult1[iidx,jidx] <- cramertestresult_ls1[[ct]]$p.value jidx <- jidx + 1 ct <- ct + 1 print(ct) } iidx <- iidx +1 } cramertestresult1[4,5] <- cramer.test(cbind((1-data_h_ls[[10]]$discount)*data_h_ls[[10]]$original_price_sd, data_h_ls[[10]]$prep.period, data_h_ls[[10]]$offering_duration), cbind((1-data_h_ls[[1]]$discount)*data_h_ls[[1]]$original_price_sd, data_h_ls[[1]]$prep.period, data_h_ls[[1]]$offering_duration), conf.level=0.95,replicates=500,sim="permutation")$p.value cramertestresult1 <- format(signif(cramertestresult1,2)) cramertestresult1[lower.tri(cramertestresult1,diag=TRUE)] <- NA rbind(c("Casual Dining","Fine Dining","Photography","Outdoor","Body Care"), cramertestresult1) -> cramertable rownames(cramertable) <- c("Industry", "Casual Dining","Fine Dining", "Photography","Outdoor","Body Care") print(xtable(cramertable),#tabular.environment = "longtable", only.contents=TRUE, include.rownames=T, include.colnames=T, floating=F, sanitize.rownames.function = identity, file = 'cramertable.tex') rbind(c("Casual Dine","Fine Dine","Photography","Outdoor","Body Care"), (alphaks_i), (Tks_i), (dks_i), cramertestresult1) -> cramer_kstable rownames(cramer_kstable) <- c("Industry", "Casual Dining, $(1-\\alpha)p$","Fine Dining, $(1-\\alpha)p$", "Photography, $(1-\\alpha)p$","Outdoor, $(1-\\alpha)p$","Body Care, $(1-\\alpha)p$", "Casual Dining, $T$","Fine Dining, $T$","Photography, $T$", "Outdoor, $T$","Body Care, $T$", "Casual Dining, $d$","Fine Dining, $d$","Photography, $d$", "Outdoor, $d$","Body Care, $d$", "Casual Dining, Cramer","Fine Dining, Cramer", "Photography, Cramer","Outdoor, Cramer","Body Care, Cramer") print(xtable(cramer_kstable),#tabular.environment = "longtable", only.contents=TRUE, include.rownames=T, include.colnames=T, floating=F, sanitize.rownames.function = identity, file = 'cramer_kstable.tex') ## multivariate ks test ------- # # library(GSAR) # multikstestresult <- matrix(rep(0,5^2), ncol= 5,byrow=T) # multikstestresult_ls <- vector(mode="list",length=25) # iidx <- 1 # jidx <- 1 # ct <- 1 # for(i in industries_to_check){ # jidx <- iidx+1 # # for(j in industries_to_check[(iidx+1):5]){ # # multiks_holi <- cbind((1-data_h_ls[[i]]$discount)*data_h_ls[[i]]$original_price_sd, data_h_ls[[i]]$prep.period, data_h_ls[[i]]$offering_duration) # multiks_holj <- cbind((1-data_h_ls[[j]]$discount)*data_h_ls[[j]]$original_price_sd, data_h_ls[[j]]$prep.period, data_h_ls[[j]]$offering_duration) # # multikstestresult_ls[[ct]] <- GSAR::KStest(object = cbind(t(multiks_holi),t(multiks_holj)), # group = c(rep(1,dim(multiks_holi)[1]),rep(2,dim(multiks_holj)[1])), nperm = 1000) # # multikstestresult[iidx,jidx] <- multikstestresult_ls[[ct]]$p.value # # jidx <- jidx + 1 # ct <- ct + 1 # print(ct) # } # iidx <- iidx +1 # } # cramertestresult1[4,5] <- cramer.test(cbind((1-data_h_ls[[10]]$discount)*data_h_ls[[10]]$original_price_sd, data_h_ls[[10]]$prep.period, data_h_ls[[10]]$offering_duration), # cbind((1-data_h_ls[[1]]$discount)*data_h_ls[[1]]$original_price_sd, data_h_ls[[1]]$prep.period, data_h_ls[[1]]$offering_duration), # conf.level=0.95,replicates=500,sim="permutation")$p.value # # # # plot alpha, t, d in different industries ---- datadim_h <- vector() datadim_nh <- vector() data_h_ls <- vector(mode = "list", length = 11) data_nh_ls <- vector(mode = "list", length = 11) predays_t <- 15 pre.windows_t <- c(seq(21-predays_t,21),seq(44-predays_t,44),seq(92-predays_t,92)) for (i in industries_to_check){ print(i) if(i == 2){ data_h <- dealsfull%>%filter(is.na(holiday)==0,type%in%c(2,3)) %>% # fl(offering_duration<40) %>% {.->>dealsfull_type}%>% # filter(original_price>quantile(dealsfull_type$original_price,c(0.4)), original_price<quantile(dealsfull_type$original_price,c(0.6))) %>% {.->>sdop} %>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) data_h_ls[[i]] <- data_h print(dim(sdop)) datadim_h <- c(datadim_h,dim(sdop)[1]) data_nh <- dealsfull%>% filter(type%in%c(2,3)) %>% mutate(end_dow_dm = launch_dow_dm+offering_duration)%>% filter(is.na(holiday)==1,type==i,end_dow_dm%in%pre.windows_t)%>%{.->>dealsfull_type}%>%{.->>sdop} %>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) # data_nh <- dealsfull%>%filter(is.na(holiday)==1,type%in%c(2)) %>% # {.->>dealsfull_type}%>% # # filter(total_volume>quantile(dealsfull_type$total_volume,c(0.4)), total_volume<quantile(dealsfull_type$total_volume,c(0.6))) %>% # {.->>sdop} %>% # filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95))) data_nh_ls[[i]] <- data_nh datadim_nh <- c(datadim_nh,dim(sdop)[1]) }else{ data_h <- dealsfull%>%filter(is.na(holiday)==0,type==i)%>% # fl(offering_duration<40) %>% {.->>sdop}%>%{.->>dealsfull_type} %>% fl(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) data_h_ls[[i]] <- data_h datadim_h <- c(datadim_h,dim(sdop)[1]) data_nh <- dealsfull%>% mutate(end_dow_dm = launch_dow_dm+offering_duration)%>% filter(is.na(holiday)==1,type==i,end_dow_dm%in%pre.windows_t)%>%{.->>dealsfull_type}%>%{.->>sdop} %>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) # data_nh <- dealsfull%>%filter(is.na(holiday)==1,type==i)%>% # {.->>sdop}%>%{.->>dealsfull_type} %>% # fl(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95))) data_nh_ls[[i]] <- data_nh datadim_nh <- c(datadim_nh,dim(sdop)[1]) } print(dim(sdop)) datasanalysis <- c(datasanalysis,dim(sdop)[1]) } meanalpha <- vector() sdalpha <- vector() meanT <- vector() sdT <- vector() meand <- vector() sdd <- vector() for(i in industries_to_check){ tmp <- ((1-data_h_ls[[i]]$discount)*data_h_ls[[i]]$original_price_sd) tmp <- tmp[tmp<quantile(tmp, 0.8)&tmp>quantile(tmp, 0.2)] meanalpha <- c(meanalpha,mean(((1-data_h_ls[[i]]$discount)*data_h_ls[[i]]$original_price_sd))) sdalpha <- c(sdalpha,sd(tmp)) tmp <- (data_h_ls[[i]]$prep.period) tmp <- tmp[tmp<quantile(tmp, 0.65)&tmp>quantile(tmp, 0.35)] meanT <- c(meanT,mean( (data_h_ls[[i]]$prep.period))) sdT <- c(sdT,sd(tmp)) tmp <- (data_h_ls[[i]]$offering_duration) tmp <- tmp[tmp<quantile(tmp, 0.65)&tmp>quantile(tmp, 0.35)] meand <- c(meand,mean((data_h_ls[[i]]$offering_duration))) sdd <- c(sdd,sd(tmp)) } plotdata <- data.frame(Industry = c("Casual Dine","Fine Dine","Photography","Outdoor","Body Care"), meanalpha=meanalpha,sdalpha=sdalpha, meanT=meanT,sdT=sdT, meand=meand,sdd=sdd) ggplot(data = plotdata)+ geom_point(aes(x=Industry,y=meanalpha),color="grey70")+ geom_errorbar(aes(x=Industry,ymin=meanalpha-sdalpha,ymax=meanalpha+sdalpha),color="grey70",width=0.2)+ geom_point(aes(x=Industry,y=meanT),color="grey50")+ geom_errorbar(aes(x=Industry,ymin=meanT-sdT,ymax=meanT+sdT),color="grey50",width=0.2)+ geom_point(aes(x=Industry,y=meand),color="grey30")+ geom_errorbar(aes(x=Industry,ymin=meand-sdd,ymax=meand+sdd),color="grey30",width=0.2) plotdata <- data.frame(Industry = rep(c("Casual Dine","Fine Dine","Photography","Outdoor","Body Care"),3), meanValues = c(meanalpha, meanT, meand), sdValues = c(sdalpha, sdT, sdd), Parameter = c(rep("Discount price",5),rep("Launch day to holiday",5),rep("Offering_duration",5))) ggplot(data = plotdata)+ geom_point(aes(x=Industry, y = meanValues),width=0.2)+ geom_errorbar(aes(x=Industry, ymin = meanValues-sdValues, ymax = meanValues+sdValues),width=0.2)+ facet_grid(Parameter~.,scales = "free") # placebo test -------- # randomly select 10 days set.seed(123) pseudoholidays <- sample(seq(7,95)[-holidays.doy],10,replace = FALSE) pseudoholidays_idx_table <- data.frame(holiday_idx = seq(1,length(pseudoholidays),1), h_first_day = pseudoholidays[order(pseudoholidays)], h_last_day = pseudoholidays[order(pseudoholidays)]) merge(merge(dealsfull%>% mt(end_dow_dm = launch_dow_dm + offering_duration), pseudoholidays_idx_table,all = TRUE) %>% mt(pseudoholidayind = (launch_dow_dm<=h_last_day)*(end_dow_dm>=h_first_day)) %>% mt(prep.periodtmp = h_first_day - launch_dow_dm) %>% mt(prep.periodtmp1 = pmax(prep.periodtmp,0)) %>% gb(event_id) %>% sm(pseudoholiday=sum(pseudoholidayind,na.rm=TRUE)>0, pre.period = (min(prep.periodtmp1))),dealsfull,by="event_id") -> dealsfull_pseudo datadim_h <- vector() datadim_nh <- vector() data_h_ls <- vector(mode = "list", length = 11) data_nh_ls <- vector(mode = "list", length = 11) for (i in industries_to_check){ print(i) if(i == 2){ data_h <- dealsfull%>%filter(is.na(holiday)==0,type%in%c(2,3)) %>% #fl(offering_duration<40) %>% {.->>dealsfull_type}%>% filter(original_price>quantile(dealsfull_type$original_price,c(0.4)), original_price<quantile(dealsfull_type$original_price,c(0.6))) %>% {.->>sdop} %>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) data_h_ls[[i]] <- data_h print(dim(sdop)) datadim_h <- c(datadim_h,dim(sdop)[1]) data_nh <- dealsfull_pseudo%>%filter((pseudoholiday)==1,type%in%c(2,3)) %>% # fl(prep.period>0,prep.period<40) %>% {.->>dealsfull_type}%>% filter(original_price>quantile(dealsfull_type$original_price,c(0.4)), original_price<quantile(dealsfull_type$original_price,c(0.6))) %>% {.->>sdop} %>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) # data_nh <- dealsfull%>%filter(is.na(holiday)==1,type%in%c(2)) %>% # {.->>dealsfull_type}%>% # # filter(total_volume>quantile(dealsfull_type$total_volume,c(0.4)), total_volume<quantile(dealsfull_type$total_volume,c(0.6))) %>% # {.->>sdop} %>% # filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95))) data_nh_ls[[i]] <- data_nh datadim_nh <- c(datadim_nh,dim(sdop)[1]) }else{ data_h <- dealsfull%>%filter(is.na(holiday)==0,type==i)%>% {.->>sdop}%>%{.->>dealsfull_type} %>% #fl(offering_duration<40) %>% fl(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) data_h_ls[[i]] <- data_h datadim_h <- c(datadim_h,dim(sdop)[1]) data_nh <- dealsfull_pseudo%>%filter((pseudoholiday)==1,type==i)%>% {.->>sdop}%>%{.->>dealsfull_type} %>% fl(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) # data_nh <- dealsfull%>%filter(is.na(holiday)==1,type==i)%>% # {.->>sdop}%>%{.->>dealsfull_type} %>% # fl(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95))) data_nh_ls[[i]] <- data_nh datadim_nh <- c(datadim_nh,dim(sdop)[1]) } print(dim(sdop)) datasanalysis <- c(datasanalysis,dim(sdop)[1]) } alphat <- vector() Tt <- vector() dt <- vector() salest <- vector() pt <- vector() alphaks <- vector() Tks <- vector() dks <- vector() salesks <- vector() pks <- vector() for(i in industries_to_check){ alphat <- c(alphat,t.test((1-data_nh_ls[[i]]$discount)*data_nh_ls[[i]]$original_price_sd, (1-data_h_ls[[i]]$discount)*data_h_ls[[i]]$original_price_sd)$p.value) Tt <- c(Tt,t.test(data_nh_ls[[i]]$prep.period, data_h_ls[[i]]$prep.period)$p.value) print(t.test(data_nh_ls[[i]]$prep.period, data_h_ls[[i]]$prep.period)$estimate) dt <- c(dt,t.test(data_nh_ls[[i]]$offering_duration, data_h_ls[[i]]$offering_duration)$p.value) print(t.test(data_nh_ls[[i]]$offering_duration, data_h_ls[[i]]$offering_duration)$estimate) salest <- c(salest,t.test(data_nh_ls[[i]]$total_volume, data_h_ls[[i]]$total_volume)$p.value) pt <- c(pt,t.test(data_nh_ls[[i]]$original_price, data_h_ls[[i]]$original_price)$p.value) alphaks <- c(alphaks,ks.test((1-data_nh_ls[[i]]$discount)*data_nh_ls[[i]]$original_price_sd, (1-data_h_ls[[i]]$discount)*data_h_ls[[i]]$original_price_sd)$p.value) Tks <- c(Tks,ks.test(data_nh_ls[[i]]$prep.period, data_h_ls[[i]]$prep.period)$p.value) dks <- c(dks,ks.test(data_nh_ls[[i]]$offering_duration, data_h_ls[[i]]$offering_duration)$p.value) salesks <- c(salesks,ks.test(data_nh_ls[[i]]$total_volume, data_h_ls[[i]]$total_volume)$p.value) pks <- c(pks,ks.test(data_nh_ls[[i]]$original_price, data_h_ls[[i]]$original_price)$p.value) } rbind(Industry = rep(c("Casual Dine","Fine Dine","Photography","Outdoor","Body Care"),2), # type = industries_to_check, # c = signif(cvec,2), # cnh = signif(cnhvec,2), c(format(signif(alphaks,2)), format(signif(alphat,2))), c(format(signif(Tks,2)), format(signif(Tt,2))), c(format(signif(dks,2)), format(signif(dt,2))), c(format(signif(pks,2)), format(signif(pt,2)))) -> testrestuls rownames(testrestuls) <- c("Industry", "Discount price, $(1-\\alpha)p$", "Launch day to holiday, $T$", "Duration, $d$", "Original price, $p$") # rbind(Industry = rep(c("Casual Dine","Fine Dine","Photography","Outdoor","Body Care"),2), # # type = industries_to_check, # # c = signif(cvec,2), # # cnh = signif(cnhvec,2), # cbind(alphaks = format(signif(alphaks,2)), # alphat = format(signif(alphat,2))), # cbind(Tks = format(signif(Tks,2)), # Tt = format(signif(Tt,2))), # cbind(dks = format(signif(dks,2)), # dt = format(signif(dt,2))), # cbind(pks = format(signif(pks,2)), # pt = format(signif(pt,2)))) -> testrestuls # rownames(testrestuls) <- c("Industry", "ks test: discount price, $(1-\\alpha)p$", # "t test: discount price, $(1-\\alpha)p$", # "ks test: launch day to holiday, $T$", # "t test: launch day to holiday, $T$", # "ks test: duration, $d$", "t test: duration, $d$", # "ks test: original price, $p$", "t test: original price, $p$") print(xtable(testrestuls),#tabular.environment = "longtable", only.contents=TRUE, include.rownames=T, include.colnames=T, floating=F, sanitize.rownames.function = identity, file = 'testresultstable.tex') # multivariate, placebo ------ set.seed(123) pseudoholidays <- sample(seq(7,95)[-holidays.doy],10,replace = FALSE) pseudoholidays_idx_table <- data.frame(holiday_idx = seq(1,length(pseudoholidays),1), h_first_day = pseudoholidays[order(pseudoholidays)], h_last_day = pseudoholidays[order(pseudoholidays)]) merge(merge(dealsfull%>% mt(end_dow_dm = launch_dow_dm + offering_duration), pseudoholidays_idx_table,all = TRUE) %>% mt(pseudoholidayind = (launch_dow_dm<=h_last_day)*(end_dow_dm>=h_first_day)) %>% mt(prep.periodtmp = h_first_day - launch_dow_dm) %>% mt(prep.periodtmp1 = pmax(prep.periodtmp,0)) %>% gb(event_id) %>% sm(pseudoholiday=sum(pseudoholidayind,na.rm=TRUE)>0, pre.period = (min(prep.periodtmp1))),dealsfull,by="event_id") -> dealsfull_pseudo datadim_h <- vector() datadim_nh <- vector() data_h_ls <- vector(mode = "list", length = 11) data_nh_ls <- vector(mode = "list", length = 11) for (i in industries_to_check){ print(i) if(i == 2){ data_h <- dealsfull%>%filter(is.na(holiday)==0,type%in%c(2,3)) %>% fl(offering_duration<40) %>% {.->>dealsfull_type}%>% # filter(original_price>quantile(dealsfull_type$original_price,c(0.4)), original_price<quantile(dealsfull_type$original_price,c(0.6))) %>% {.->>sdop} %>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) data_h_ls[[i]] <- data_h print(dim(sdop)) datadim_h <- c(datadim_h,dim(sdop)[1]) data_nh <- dealsfull_pseudo%>%filter((pseudoholiday)==1,type%in%c(2,3)) %>% fl(prep.period>0,prep.period<40) %>% {.->>dealsfull_type}%>% # filter(original_price>quantile(dealsfull_type$original_price,c(0.4)), original_price<quantile(dealsfull_type$original_price,c(0.6))) %>% {.->>sdop} %>% filter(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) # data_nh <- dealsfull%>%filter(is.na(holiday)==1,type%in%c(2)) %>% # {.->>dealsfull_type}%>% # # filter(total_volume>quantile(dealsfull_type$total_volume,c(0.4)), total_volume<quantile(dealsfull_type$total_volume,c(0.6))) %>% # {.->>sdop} %>% # filter(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95))) data_nh_ls[[i]] <- data_nh datadim_nh <- c(datadim_nh,dim(sdop)[1]) }else{ data_h <- dealsfull%>%filter(is.na(holiday)==0,type==i)%>% {.->>sdop}%>%{.->>dealsfull_type} %>% fl(offering_duration<40) %>% fl(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) data_h_ls[[i]] <- data_h datadim_h <- c(datadim_h,dim(sdop)[1]) data_nh <- dealsfull_pseudo%>%filter((pseudoholiday)==1,type==i)%>% {.->>sdop}%>%{.->>dealsfull_type} %>% fl(total_volume>quantile(dealsfull_type$total_volume,c(0.1)), total_volume<quantile(dealsfull_type$total_volume,c(0.9))) %>% mutate(original_price_sd = original_price/sd(original_price)) # data_nh <- dealsfull%>%filter(is.na(holiday)==1,type==i)%>% # {.->>sdop}%>%{.->>dealsfull_type} %>% # fl(total_volume>quantile(dealsfull_type$total_volume,c(0.05)), total_volume<quantile(dealsfull_type$total_volume,c(0.95))) data_nh_ls[[i]] <- data_nh datadim_nh <- c(datadim_nh,dim(sdop)[1]) } print(dim(sdop)) datasanalysis <- c(datasanalysis,dim(sdop)[1]) } set.seed(123) # data_h_ls[[11]] <- data_h_ls[[11]][sample(dim(data_h_ls[[11]])[1],200,replace = T),] ct <- 1 cramernholvshol_ls <- vector(mode="list",length = 5) cramernholvsholtest <- vector() for(i in industries_to_check){ cramer_nhol <- cbind((1-data_nh_ls[[i]]$discount)*data_nh_ls[[i]]$original_price_sd, data_nh_ls[[i]]$prep.period, data_nh_ls[[i]]$offering_duration) cramer_hol <- cbind((1-data_h_ls[[i]]$discount)*data_h_ls[[i]]$original_price_sd, data_h_ls[[i]]$prep.period, data_h_ls[[i]]$offering_duration) cramernholvshol_ls[[ct]] <- cramer.test(cramer_nhol,cramer_hol,conf.level=0.95,replicates=500,sim="permutation") cramernholvsholtest <- c(cramernholvsholtest,cramernholvshol_ls[[ct]]$p.value) ct <- ct + 1 print(ct) }
3613e44be16f0fcdaa9f28bf3a60ae4a53dc6680
2defb970de80008d3a5f77728bf3f896832fe2e1
/R-proj/kc_read_data.R
2a6f9700a5a45111091b8982d54c0aa9d2e57d57
[]
no_license
FredHutch/COVID_modeling_schools
bd211844ebd00c5977ac6ad0ef8b298aa7d6a8f2
98c1a879e1685b78a21427780f0f34941c309034
refs/heads/master
2023-08-31T14:37:46.365370
2021-10-06T16:36:47
2021-10-06T16:36:47
413,988,503
1
0
null
null
null
null
UTF-8
R
false
false
5,713
r
kc_read_data.R
# this file reads in the data used to fit the model and processes it into the required format require(lubridate) require(dplyr) # Original sources #### # data file downloaded from the DOH site uses data from King County downloaded on Oct 9th (cut down to 9-30) # this is the data used to calibrate the model # # tests, cases, deaths and hospitalizations are daily and by age gropu (0-19,20-49,50-69,70+) # dates must be saved in the format year-mo-day (ex. 2020-08-31) # To get more recent: refilter IDM raw data from sft.wa.gov (PRIVATE!) into IDM_king_county.csv (checked in) run the # script select_data.sh in the data directory (change input file if you have a new one) then... # # get tests, hosp & deaths separately using the following scripts: # tally_tests.R, tally_hosp.R and tally_deaths.R # sort and tally for each date using the following scripts: # sort_test_data.sh, sort_hosp_data.sh and sort_death_data.sh # then merge into one file using "merge_files.R" # # The file is "king_county_by_age.csv". Its header is shown here: #date,tests1,tests2,tests3,tests4,pos1,pos2,pos3,pos4,daily pos,cases,hosps1,hosps2,hosps3,hosps4,Hospitalizations,tot hosp,deaths1,deaths2,deaths3,deaths4,daily deaths,deaths # # Make sure the 1st date is 2/26 (not 1/14) and replace "NA"s with 0s before proceeding (except cumulative deaths!) # The NAs come from joins of the files by date on days when there were no deaths! # kc_data = read.csv("../data/king_county_by_age.csv", stringsAsFactors = FALSE) kc_data$date = ymd(kc_data$date) # calculate negative tests kc_data = cbind(kc_data, kc_data[,paste0("tests", 1:4)] - kc_data[,paste0("pos", 1:4)]) names(kc_data)[(ncol(kc_data) - 3):ncol(kc_data)] = paste0("neg", 1:4) # do the moving average on the full data as it will be more accurate that way kc_data = kc_data %>% mutate_at(vars(contains("tests")), .funs = list(ma = ~moving_avg(.))) %>% mutate_at(vars(contains("hosps")), .funs = list(ma = ~moving_avg(.))) %>% mutate_at(vars(contains("pos")), .funs = list(ma = ~moving_avg(.))) %>% mutate_at(vars(contains("neg")), .funs = list(ma = ~moving_avg(.))) %>% mutate_at(vars(contains("deaths")), .funs = list(ma = ~moving_avg(.))) %>% rename_at( vars( contains( "_ma") ), list( ~paste("ma", gsub("_ma", "", .), sep = "_") ) ) # new data off for calibration is Dec 31th end_date = ymd("2020-12-31") kc_data_calib = filter(kc_data, date <= end_date) mean_tests = function(date){ start = yday(ymd(kc_data$date[1])) now = yday(ymd(date)) range = seq(-3,3) + (now - start + 1) mean(kc_data$tests[range]) } # these are the mid moth dates used for tests and other calculated parameters test_dates = c("2020-03-15", "2020-04-15", "2020-05-15", "2020-06-15", "2020-07-15", "2020-08-15", "2020-09-15", "2020-10-15") # this is the calculated data from DOH data kc_data_monthly = list( # number of tests performed tests = data.frame( date = ymd(test_dates), value = sapply(test_dates, mean_tests)), # Days at which to capture daily testing avg to use for the month # TODO for now these monthly values are copy/pasted, but could move calculation to R like the tests? # fractions based fraction of tests in each age group # obtained by running "./get_tests_by_age.sh" on "IDM_king_county.csv" age_test_frac = data.frame(date = ymd(test_dates), value = matrix(c(c(0.0740358,0.509446,0.294448,0.12207), # based on tests taken 2/1/20 - 3/31/20 c(0.0640876,0.521905,0.297245,0.116763), # based on tests taken during April c(0.0715118,0.471296,0.299394,0.157798), # based on tests taken during May c(0.0594408,0.569942,0.245141,0.125476), # based on tests taken during June c(0.100093,0.597033,0.220479,0.0823942), # based on tests taken during July c(0.121455,0.559161,0.22471,0.0946729), # based on tests taken during Aug c(0.13549,0.54648,0.226248,0.0917822), # based on tests taken during Sept c(0.13058,0.562911,0.232331,0.0741788)), ncol = 4, byrow = TRUE)), # based on tests taken during Oct # fractions based percent in an age group that are hospitalized (based on date of hospital admission) # obtained by running "./get_hosp_data.sh" on "IDM_king_county.csv" hosp_frac = data.frame(date = ymd(test_dates), value = matrix(c(c(0.0833333,0.0870359,0.233359,0.614841), # based on hospital admissions during 2/1/20 - 3/31/20 c(0.0185185,0.0938338,0.236869,0.531697), # based on hospital admissions during April c(0.0206186,0.065389,0.198324,0.435185), # based on hospital admissions during May c(0.0108696,0.030285,0.130631,0.358974), # based on hospital admissions during June c(0.00858896,0.030137,0.122622,0.318493), # based on hospital admissions during July c(0.00256082,0.0264188,0.122503,0.377193), # based on hospital admissions during Aug c(0.0105448,0.02547,0.102041,.333333), # based on hospital admissions during Sept c(0.00735294,0.0158991,0.0797546,0.372694)), ncol = 4, byrow = TRUE)) # based on hospital admissions during Oct ) # Set global starting parameters #### source("kc_globalparams.R")
1017a60f09328a6f27cc264fa7d035bd8e9ff6bd
bde39c3923798ffd37486ca60532b8f3006a36b0
/misc R scripts/QC computed indicators boxplots.R
23ad8e60b72ac66183c9543b5dae282f6c6157c3
[]
no_license
usubuglab/AIM_2016
0baa6eacb579e98ce9f2dc615bfa0647324200c2
c634d37263ec4a8bd7ee1cf27d38edace4806b5a
refs/heads/master
2021-07-19T21:18:38.268763
2021-03-24T19:51:43
2021-03-24T19:51:43
49,015,002
2
0
null
null
null
null
UTF-8
R
false
false
10,405
r
QC computed indicators boxplots.R
#QC computed indicators by looking at boxplots by indicator and ecoregion IndicatorsFinal=read.csv("Z:\\buglab\\Research Projects\\AIM\\Analysis\\QC\\2017\\AK\\IndicatorsAK8feb2018_Alldata_boxplots_for_workshop.csv") IndicatorsFinal=read.csv("Z:\\buglab\\Research Projects\\AIM\\Analysis\\QC\\2017\\AK\\IndicatorsAK8feb2018_Alldata_boxplots_for_workshop.csv") #IndicatorsFinal=read.csv("Z:\\buglab\\Research Projects\\AIM\\Analysis\\QC\\2017\\AK\\AK_points_ecoregions.csv") #IndicatorsFinal$NAMC_Benchmark=IndicatorsFinal$US_L3NAME str(IndicatorsFinal) library (ggplot2) IndicatorsFinalnum=IndicatorsFinalnum[,c(56:57,1:55)] #for indicator by ecoregion & targeted ecoregions=unique(unlist(IndicatorsFinal$EcoregionHybrid10)) for (s in 2:length(ecoregions)) { Ecoregionsubset=subset(IndicatorsFinal,EcoregionHybrid10==ecoregions[s]) nums=sapply(Ecoregionsubset,is.numeric) IndicatorsFinalnum=Ecoregionsubset[,nums] IndicatorsFinalnum$EcoregionHybrid10=Ecoregionsubset$EcoregionHybrid10 IndicatorsFinalnum$Targeted=Ecoregionsubset$Targeted for (f in 10:length(colnames(IndicatorsFinalnum))-2){ png(file=paste(ecoregions[s], colnames(IndicatorsFinalnum[f]),".png"), width=2000,height=700,pointsize=15) boxplot(IndicatorsFinalnum[,f]~Targeted, data=IndicatorsFinalnum,xlab=paste(colnames(IndicatorsFinalnum[f]),names=paste0(Indicato$names, " (n=",b$n,")"))),lwd=3,cex.lab=2) dev.off() } } nums=sapply(IndicatorsFinal,is.numeric) IndicatorsFinalnum=Ecoregionsubset[,nums] IndicatorsFinalnum$EcoregionHybrid10=Ecoregionsubset$EcoregionHybrid10 IndicatorsFinalnum$Targeted=Ecoregionsubset$Targeted #for indicator by ecoregion/stream size for (f in 10:length(colnames(IndicatorsFinalnum))-2){ png(file=paste("boxplot",colnames(IndicatorsFinalnum[f]),".png"), width=2000,height=700,pointsize=10) boxplot(IndicatorsFinalnum[,f]~Targeted, data=IndicatorsFinalnum,xlab=paste(colnames(IndicatorsFinalnum[f])),lwd=3,cex.lab=2) dev.off() } #for indicator by ecoregion/stream size for (f in 10:length(colnames(IndicatorsFinalnum))){ png(file=paste("boxplot",colnames(IndicatorsFinalnum[f]),".png"), width=2000,height=700,pointsize=10) boxplot(IndicatorsFinalnum[,f]~NAMC_Benchmark, data=IndicatorsFinalnum,xlab=paste(colnames(IndicatorsFinalnum[f])),lwd=3,cex.lab=2) dev.off() } #for all indicators for (f in 10:length(colnames(IndicatorsFinalnum))){ png(file=paste("boxplot",colnames(IndicatorsFinalnum[f]),".png"), width=1000,height=700,pointsize=24) boxplot(IndicatorsFinalnum[,f],xlab=paste(colnames(IndicatorsFinalnum[f])),lwd=3,cex.lab=2) dev.off() } f <- function(x) { r <- quantile(x, probs = c(0.05, 0.25, 0.5, 0.75, 0.95)) names(r) <- c("ymin", "lower", "middle", "upper", "ymax") r } # define outlier as you want o <- function(x) { subset(x, x < quantile(x)[2] | quantile(x)[4] < x) } library(ggplot2) #####works!!!! IndicatorsFinal=read.csv("Z:\\buglab\\Research Projects\\AIM\\Workshops\\NAMF Data Analysis\\AK_2018\\BenchmarkScreeningDevelopment\\ALL_AK_data_for_workshop_16Feb2018_benchmark_boxplots_JC_exploration.csv") IndicatorsFinal=subset(IndicatorsFinal, IndicatorsFinal$Targeted=='Random') Indicators=c("NAMC_Benchmark","EcoregionHybrid10","OtherEcoregion","Targeted","BankCover","BankStability","BnkCover_Stab","BankfullWidth","BankOverheadCover","InstreamHabitatComplexity","FloodplainConnectivity","LWD_Freq","PctOverheadCover","pH","Slope","SpecificConductance","VegComplexity","PctFines","ThalwegDepthCV","Entrench") IndicatorsFinalsub=IndicatorsFinal[,Indicators] IndicatorsFinalsub=subset(IndicatorsFinalsub, EcoregionHybrid10 %in% c('Alaska Range','Interior Highlands','Arctic Coastal Plain',"Interior Forested Lowlands and Uplands")) IndicatorsFinalsub=subset(IndicatorsFinalsub, EcoregionHybrid10 %in% c('Interior Highlands','Arctic Coastal Plain')) #IndicatorsFinalsub$EcoregionHybrid10=factor(IndicatorsFinalsub$EcoregionHybrid10, levels=levels(IndicatorsFinalsub$EcoregionHybrid10)[c(1,2,6,7)]) IndicatorsFinalsub$NAMC_Benchmark=droplevels(IndicatorsFinalsub$NAMC_Benchmark) levels(IndicatorsFinalsub$NAMC_Benchmark) ('Beaufort Coastal Plain','Alaska Range','Yukon-Tanana Uplands','Ray Mountains') for (s in 5:length(colnames(IndicatorsFinalsub))){ png(file=paste("boxplot",colnames(IndicatorsFinalsub[s]),".png"), width=2000,height=700,pointsize=20) b=boxplot(IndicatorsFinalsub[,s]~NAMC_Benchmark*Targeted, data=IndicatorsFinalsub,xlab=paste(colnames(IndicatorsFinalsub[s])),lwd=3,cex.lab=2) boxplot(IndicatorsFinalsub[,s]~NAMC_Benchmark*Targeted, data=IndicatorsFinalsub,xlab=paste(colnames(IndicatorsFinalsub[s])),names=paste0(b$names,"\n(n=",b$n,")"),lwd=3,cex.lab=2) dev.off() } ########### for (s in 4:length(Indicators)) { ggplot(IndicatorsFinal, aes(EcoregionHybrid10,IndicatorsFinalsub[,5]))+ stat_summary(fun.data=f,geom="boxplot",fill='lightgray',colour="darkslategray") + stat_summary(fun.y = o, geom="point")+ labs(x="", y = colnames(IndicatorsFinalsub[,5]))+ ylim(0.0,2.5)+ theme_classic()+ theme(axis.text=element_text(size=12),axis.title=element_text(size=12,face="bold") )#see http://ggplot2.tidyverse.org/reference/theme.html for more info on changing spacing and text size } #example new boxplot for vegComplexity #create paired reference and targeted boxplot png('VegComplex.png',width=1500, height=700, size=15) IndicatorsFinal=subset(IndicatorsFinal,OtherEcoregion %in% c('Beaufort Coastal Plain','Alaska Range','Yukon-Tanana Uplands','Ray Mountains')) ggplot(IndicatorsFinal, aes(OtherEcoregion,VegComplexity))+ stat_summary(fun.data=f,geom="boxplot",fill='lightgray',colour="darkslategray") + stat_summary(fun.y = o, geom="point")+ labs(x="", y = "VegComplexity")+ ylim(0.0,2.5)+ theme_classic()+ theme(axis.text=element_text(size=12),axis.title=element_text(size=12,face="bold") )#see http://ggplot2.tidyverse.org/reference/theme.html for more info on changing spacing and text size dev.off() png('FloodplainConnect.png',width=1500, height=700, size=15) ggplot(IndicatorsFinal, aes(OtherEcoregion,FloodplainConnectivity))+ stat_summary(fun.data=f,geom="boxplot",fill='lightgray',colour="darkslategray") + stat_summary(fun.y = o, geom="point")+ labs(x="", y = "Floodplain Connectivity")+ #ylim(0.0,0.5)+ theme_classic()+ theme(axis.text=element_text(size=12),axis.title=element_text(size=12,face="bold"),axis.text.x=element_blank(),axis.ticks.x=element_blank(),axis.title.x=element_blank() )#see http://ggplot2.tidyverse.org/reference/theme.html for more info on changing spacing and text size dev.off() png('Entrench.png',width=1500, height=700, size=15) ggplot(IndicatorsFinal, aes(OtherEcoregion,Entrench))+ stat_summary(fun.data=f,geom="boxplot",fill='lightgray',colour="darkslategray") + stat_summary(fun.y = o, geom="point")+ labs(x="", y = "Entrench")+ #ylim(0.0,0.5)+ theme_classic()+ theme(axis.text=element_text(size=12),axis.title=element_text(size=12,face="bold") )#see http://ggplot2.tidyverse.org/reference/theme.html for more info on changing spacing and text size dev.off() png('LWD_freq.png',width=1500, height=700, size=15) ggplot(IndicatorsFinal, aes(OtherEcoregion,LWD_Freq))+ stat_summary(fun.data=f,geom="boxplot",fill='lightgray',colour="darkslategray") + stat_summary(fun.y = o, geom="point")+ labs(x="", y = "LWD_Freq")+ #ylim(0.0,0.5)+ theme_classic()+ theme(axis.text=element_text(size=12),axis.title=element_text(size=12,face="bold") )#see http://ggplot2.tidyverse.org/reference/theme.html for more info on changing spacing and text size dev.off() png('PctFines.png',width=1500, height=700, size=15) ggplot(IndicatorsFinal, aes(OtherEcoregion,PctFines))+ stat_summary(fun.data=f,geom="boxplot",fill='lightgray',colour="darkslategray") + stat_summary(fun.y = o, geom="point")+ labs(x="", y = "PctFines")+ ylim(0.0,2.5)+ theme_classic()+ theme(axis.text=element_text(size=12),axis.title=element_text(size=12,face="bold") )#see http://ggplot2.tidyverse.org/reference/theme.html for more info on changing spacing and text size dev.off() png('PctOverheadCover.png',width=1500, height=700, size=15) ggplot(IndicatorsFinal, aes(OtherEcoregion,PctOverheadCover))+ stat_summary(fun.data=f,geom="boxplot",fill='lightgray',colour="darkslategray") + stat_summary(fun.y = o, geom="point")+ labs(x="", y = "PctOverheadCover")+ #ylim(0.0,0.5)+ theme_classic()+ theme(axis.text=element_text(size=12),axis.title=element_text(size=12,face="bold"),axis.text.x=element_blank(),axis.ticks.x=element_blank(),axis.title.x=element_blank() )#see http://ggplot2.tidyverse.org/reference/theme.html for more info on changing spacing and text size dev.off() png(file='boxplotpH.png', width=1500,height=700,pointsize=15) ggplot(IndicatorsFinal, aes(OtherEcoregion,pH))+ stat_summary(fun.data=f,geom="boxplot",fill='lightgray',colour="darkslategray") + stat_summary(fun.y = o, geom="point")+ labs(x="", y = "pH")+ #ylim(0.0,0.5)+ theme_classic()+ theme(axis.text=element_text(size=12),axis.title=element_text(size=12,face="bold") )#see http://ggplot2.tidyverse.org/reference/theme.html for more info on changing spacing and text size dev.off() png('Slope.png',width=1500, height=700, size=15) ggplot(IndicatorsFinal, aes(OtherEcoregion,Slope))+ stat_summary(fun.data=f,geom="boxplot",fill='lightgray',colour="darkslategray") + stat_summary(fun.y = o, geom="point")+ labs(x="", y = "Slope")+ #ylim(0.0,0.5)+ theme_classic()+ theme(axis.text=element_text(size=12),axis.title=element_text(size=12,face="bold") )#see http://ggplot2.tidyverse.org/reference/theme.html for more info on changing spacing and text size dev.off() dev.off() boxplot(FloodplainConnectivity~NAMC_Benchmark,data=IndicatorsFinal) # # boxplot of Cal vs. Val OE scores: # b = boxplot(OE.assess.cal$OE.scores$OoverE, OE.assess.vld$OE.scores$OoverE,names=c("calibration","validation"),border=c("red", "blue"),ylab="O/E") # # boxplot(OE.assess.cal$OE.scores$OoverE, OE.assess.vld$OE.scores$OoverE,border=c("red", "blue"),ylab="O/E",names=paste0(b$names, " (n=",b$n,")")) # abline(h=1.0,col=8,lty=3) # # png(file=paste("boxplot",".png"), width=1000,height=700,pointsize=10) # par(mfrow=c(10,10)) # for (f in 10:length(colnames(IndicatorsFinalnum))){ # boxplot(IndicatorsFinalnum[,f],xlab=paste(colnames(IndicatorsFinalnum[f])),lwd=3,cex.lab=2) # } # dev.off()
6b66448dae67deac16d8dc1e3c7af19b465fc7e2
29af718d33105bceddd488326e53dab24e1014ef
/Satisfiability/Transformers/Generators/Queens/GenericSAT/data/exp_files/ExpQueens/ExperimentR2.R
d8c68e54c2a4dcc8084f6cf4f56b42f11b2c186a
[]
no_license
OKullmann/oklibrary
d0f422847f134705c0cd1eebf295434fe5ffe7ed
c578d0460c507f23b97329549a874aa0c0b0541b
refs/heads/master
2023-09-04T02:38:14.642785
2023-09-01T11:38:31
2023-09-01T11:38:31
38,629
21
64
null
2020-10-30T17:13:04
2008-07-30T18:20:06
C++
UTF-8
R
false
false
6,209
r
ExperimentR2.R
# ExpQueens: Version: 0.3.4, parameter r 0 ... 10 # run on csverify # Remark OK 3.3.2019: used old version of shuffle, leaving first field untouched N sol nds h munds msnds hts t 1 1 1 0 0 1 0 0.00 2 0 3 1 3 0 1 0.00 3 0 7 3 7 0 1 0.00 4 2 15 5 3 1 2 0.00 5 10 43 7 3 1 2 0.00 6 4 133 20 25 1 3 0.00 7 40 443 29 17 1 4 0.00 8 92 1479 37 169 3 4 0.00 9 352 6039 50 73 5 5 0.00 10 724 23821 61 221 5 6 0.02 11 2680 129345 78 477 11 7 0.08 12 14200 745781 89 1237 7 8 0.50 13 73712 4083199 123 975 11 9 2.59 14 365596 28673645 139 3171 11 10 19.33 15 2279184 153365233 171 7395 21 10 108.91 16 14772512 1033823919 189 6587 25 11 782.58 17 95815104 7876738773 226 15911 23 12 6184.95 18 666090624 68209557525 252 26307 33 13 55625.92 1 1 1 0 0 1 0 0.00 2 0 3 1 3 0 1 0.00 3 0 7 3 7 0 1 0.00 4 2 15 6 5 1 2 0.00 5 10 35 11 3 3 2 0.00 6 4 123 18 15 1 3 0.00 7 40 371 25 13 5 4 0.00 8 92 1375 38 49 5 4 0.00 9 352 6977 46 99 5 5 0.00 10 724 31091 64 313 5 6 0.02 11 2680 147207 79 431 5 7 0.10 12 14200 728543 105 1099 7 7 0.45 13 73712 4140313 124 1075 11 8 2.63 14 365596 27744423 141 3475 11 10 18.43 15 2279184 186933711 169 5419 15 10 129.43 16 14772512 1078230347 194 5079 17 11 805.62 17 95815104 8314998945 216 7445 21 12 6420.68 18 666090624 58027247941 258 23495 29 13 46911.63 1 1 1 0 0 1 0 0.00 2 0 3 1 3 0 1 0.00 3 0 7 3 7 0 1 0.00 4 2 13 5 3 1 2 0.00 5 10 43 9 3 1 2 0.00 6 4 97 16 17 1 3 0.00 7 40 449 29 25 3 4 0.00 8 92 1445 38 33 3 4 0.00 9 352 6445 55 97 5 5 0.00 10 724 25273 63 347 5 6 0.01 11 2680 143971 78 401 7 7 0.08 12 14200 712297 97 835 7 8 0.46 13 73712 3706699 118 939 13 8 2.38 14 365596 25139381 144 2047 11 9 16.75 15 2279184 143018573 162 3091 19 10 99.73 16 14772512 1128099237 187 7947 17 11 832.31 17 95815104 8418562963 219 9753 25 12 6483.94 18 666090624 51962386657 250 17061 31 13 42128.04 1 1 1 0 0 1 0 0.00 2 0 3 1 3 0 1 0.00 3 0 5 2 5 0 1 0.00 4 2 15 5 3 1 2 0.00 5 10 41 11 3 3 2 0.00 6 4 111 19 23 1 3 0.00 7 40 455 24 15 3 3 0.00 8 92 1681 39 63 3 4 0.00 9 352 6583 46 125 5 5 0.00 10 724 24561 66 169 5 6 0.02 11 2680 137981 89 1181 5 7 0.09 12 14200 781677 108 719 7 8 0.51 13 73712 3406445 121 1237 13 8 2.17 14 365596 28400221 139 3203 11 10 18.81 15 2279184 175478833 173 5391 15 10 121.55 16 14772512 986388265 189 7545 19 11 736.46 17 95815104 8598694069 220 16125 27 12 6611.98 18 666090624 67956000687 254 33341 31 13 55139.13 1 1 1 0 0 1 0 0.00 2 0 3 1 3 0 1 0.00 3 0 5 2 5 0 1 0.00 4 2 17 6 3 1 2 0.00 5 10 35 10 1 1 2 0.00 6 4 131 19 33 1 3 0.00 7 40 413 26 19 3 4 0.00 8 92 1079 32 31 3 4 0.00 9 352 7191 47 113 5 6 0.00 10 724 29071 65 297 5 6 0.02 11 2680 121663 82 463 5 7 0.08 12 14200 720313 104 799 9 7 0.48 13 73712 3862429 128 1237 11 8 2.48 14 365596 25002437 129 1877 13 9 16.65 15 2279184 140578465 168 3797 19 10 98.02 16 14772512 967017807 185 5735 21 11 716.31 17 95815104 5705417501 230 21489 25 12 4417.50 18 666090624 48674196089 251 17425 31 13 39597.29 1 1 1 0 0 1 0 0.00 2 0 3 1 3 0 1 0.00 3 0 5 2 5 0 1 0.00 4 2 11 4 3 3 2 0.00 5 10 47 13 7 3 2 0.00 6 4 125 16 29 1 3 0.00 7 40 413 32 31 1 3 0.00 8 92 1583 36 39 3 5 0.00 9 352 5647 44 61 5 5 0.00 10 724 26993 72 303 5 6 0.02 11 2680 152561 85 593 5 7 0.10 12 14200 624065 93 537 7 7 0.42 13 73712 4207971 108 1189 9 9 2.73 14 365596 22752753 138 1573 13 9 15.26 15 2279184 160600739 163 6009 15 10 111.31 16 14772512 1064030539 188 5085 19 11 796.20 17 95815104 7841371897 228 12517 25 12 6071.34 18 666090624 62335207057 246 17673 27 13 50465.61 1 1 1 0 0 1 0 0.00 2 0 3 1 3 0 1 0.00 3 0 5 2 5 0 1 0.00 4 2 13 5 3 1 2 0.00 5 10 33 8 3 3 2 0.00 6 4 97 14 25 1 3 0.00 7 40 355 25 15 1 3 0.00 8 92 1337 37 67 3 5 0.00 9 352 6087 48 75 5 5 0.00 10 724 28443 61 181 3 6 0.02 11 2680 105421 73 455 5 7 0.06 12 14200 718821 98 897 7 8 0.43 13 73712 4019329 127 1075 11 9 2.59 14 365596 24013435 133 1735 13 9 15.97 15 2279184 137389711 162 2449 15 10 95.99 16 14772512 1134328209 195 5893 17 11 843.87 17 95815104 8069726395 223 11721 23 12 6231.81 18 666090624 64895327775 252 20509 27 13 52285.70 1 1 1 0 0 1 0 0.00 2 0 3 1 3 0 1 0.00 3 0 5 2 5 0 1 0.00 4 2 17 7 3 1 2 0.00 5 10 49 12 13 3 2 0.00 6 4 107 16 19 1 3 0.00 7 40 351 25 15 3 3 0.00 8 92 1569 39 73 3 4 0.00 9 352 5993 46 93 5 6 0.00 10 724 26643 58 157 3 6 0.02 11 2680 117539 81 389 9 7 0.08 12 14200 581979 85 507 11 7 0.39 13 73712 4038751 122 1725 11 8 2.56 14 365596 25253437 135 1787 15 9 16.61 15 2279184 163998565 161 3465 15 10 114.24 16 14772512 999362085 195 6555 17 11 743.79 17 95815104 9230876305 209 19267 23 12 7099.00 18 666090624 66056945803 241 20343 25 13 53482.20 1 1 1 0 0 1 0 0.00 2 0 3 1 3 0 1 0.00 3 0 7 3 7 0 1 0.00 4 2 15 6 7 1 2 0.00 5 10 39 15 9 3 2 0.00 6 4 163 17 21 1 3 0.00 7 40 359 27 17 3 3 0.00 8 92 1427 35 51 5 5 0.00 9 352 5665 47 123 5 5 0.00 10 724 24483 60 321 7 6 0.02 11 2680 140849 80 609 5 7 0.10 12 14200 753657 98 1115 9 8 0.51 13 73712 4755901 117 1155 9 9 3.05 14 365596 28641817 140 4845 13 9 19.01 15 2279184 216527313 171 4477 17 11 150.25 16 14772512 1170339183 198 7929 17 11 879.23 17 95815104 8937716485 209 9913 29 12 6865.92 18 666090624 77627950497 263 23025 27 13 62734.40 1 1 1 0 0 1 0 0.00 2 0 3 1 3 0 1 0.00 3 0 5 2 5 0 1 0.00 4 2 13 5 5 1 2 0.00 5 10 37 12 1 3 2 0.00 6 4 113 16 31 1 3 0.00 7 40 381 25 23 3 3 0.00 8 92 1441 42 31 5 4 0.00 9 352 6177 47 85 5 5 0.00 10 724 23125 57 143 5 6 0.02 11 2680 133923 81 611 5 7 0.08 12 14200 721995 96 597 7 7 0.44 13 73712 3380527 118 885 9 8 2.22 14 365596 24267789 138 2427 13 9 16.32 15 2279184 133979673 171 3291 17 10 93.46 16 14772512 952437139 187 3783 21 11 710.39 17 95815104 7167225981 220 7469 23 12 5566.29 18 666090624 63901097405 256 27267 27 13 51730.70 1 1 1 0 0 1 0 0.00 2 0 3 1 3 0 1 0.00 3 0 7 3 7 0 1 0.00 4 2 13 5 3 1 2 0.00 5 10 39 11 7 3 2 0.00 6 4 119 15 19 1 3 0.00 7 40 353 25 27 3 4 0.00 8 92 1477 37 29 5 4 0.00 9 352 5323 45 55 7 5 0.00 10 724 23689 58 195 7 6 0.01 11 2680 141545 88 419 7 7 0.09 12 14200 781275 96 523 7 7 0.49 13 73712 3411869 130 899 9 8 2.19 14 365596 23144685 137 2379 11 9 15.57 15 2279184 144793591 160 4085 19 10 101.01 16 14772512 977223649 183 6917 21 11 726.97 17 95815104 7601344435 222 10477 27 12 5890.04 18 666090624 59268625561 251 16343 31 13 48057.21
dfc8700a7482c17c81c337acf0d3aa7dffe2bbfb
257afcbc82d3610b68db6ad1227862a25f24e5d9
/man/spectrolab.Rd
eca3f7e833dd2b18646ec6ae1c5ce922f44740b1
[]
no_license
annakat/spectrolab
061f6e9dfdfcf00431b8fea6164be3de1be052fd
c0a342b4a924bd48f051d8418df0b60a3d0dd9d7
refs/heads/master
2021-07-21T05:21:30.337824
2019-09-05T19:36:18
2019-09-05T19:36:18
142,489,204
1
0
null
null
null
null
UTF-8
R
false
true
250
rd
spectrolab.Rd
% Generated by roxygen2: do not edit by hand % Please edit documentation in R/spectrolab.R \docType{package} \name{spectrolab} \alias{spectrolab} \alias{spectrolab-package} \title{Spectrolab} \description{ Class and methods for hyperspectral data. }
5df4630b06c1c09c35578abb1174d669c3e58018
67a6f1af8a7e28e3e64f123ce48fff3017364094
/man/getUCSC.Rd
4bb581e1baf01f3239990bf5cf3cc062b40d9cdf
[]
no_license
tastanlab/NoRCE
3257f0af8da9cbff2152313edc9df9e3b2b4dd1c
e8779cec9bdece0e71a8f85389259a8d1714465f
refs/heads/master
2020-05-28T14:17:11.643250
2019-05-26T12:11:24
2019-05-26T12:11:24
null
0
0
null
null
null
null
UTF-8
R
false
true
1,016
rd
getUCSC.Rd
% Generated by roxygen2: do not edit by hand % Please edit documentation in R/getNearest.R \name{getUCSC} \alias{getUCSC} \title{Get nearest genes for the window of the upstream/downstream region.} \usage{ getUCSC(bedfile, upstream, downstream, hg) } \arguments{ \item{bedfile}{Bed formated input gene regions} \item{upstream}{Maximum upstream distance from the transcription start region of the input gene} \item{downstream}{Maximum downstream distance from the transcription end region of the input gene} \item{hg}{genomee assembly of interest for the analysis. Possible assemblies are "mm10" for mouse, "dre10" for zebrafish, "rn6" for rat, "dm6" for fruit fly, "ce11" for worm, "sc3" for yeast, "hg19" and "hg38" for human} } \value{ genes } \description{ When downstream = 0 / upstream = 0, function converts bed formated regions to HUGO genes } \examples{ regionNC <- readbed(dm_file = ncRegion,isText = FALSE) neighbour <- getUCSC(bedfile = regionNC, upstream = 1000, downstream = 1000,hg = 'hg38') }
d633d0782183926f46cdd3f6ab14c15a16a27b76
f5e66f86b5e89c21a54cd8a095de5752018a549e
/data-raw/NOAAetal2012.R
eda3e4e0499e8d185669ad49fafaecc88f017898
[]
no_license
rjaneUCF/MultiHazard
5279e4efc869e8745818fe62b37ce1d35534114c
334b0e1aa6bd5f4dbd68876221fad3c499e691a2
refs/heads/master
2023-07-29T15:04:55.523801
2023-07-11T20:46:42
2023-07-11T20:46:42
239,541,679
11
4
null
null
null
null
UTF-8
R
false
false
90
r
NOAAetal2012.R
NOAAetal2012<-read.csv("NOAAetal2012.csv",header=TRUE) devtools::use_data(NOAAetal2012)
ed58f8c36779b6c7dcbef4c52ce42a38d8938752
930a64ae51ba9c4052bcd2b6d4392ff70f98bde8
/FORMULAS.R
2bddc8934a33356b6ef0189f9cb0179292b25e7f
[]
no_license
statisticallyfit/RStatistics
1e9f59a1ebef597d4c73f3cf10bed5170126d83b
93915cc141c4cb2b465d301d44695b8ce0ad35f8
refs/heads/master
2020-06-26T02:29:51.113577
2019-10-18T18:00:14
2019-10-18T18:00:14
74,606,344
0
0
null
null
null
null
UTF-8
R
false
false
38,671
r
FORMULAS.R
source('/datascience/projects/statisticallyfit/github/learningmathstat/RStatistics/Rfunctions.R') # use DescTools # Kurt # Skew #skewness <- function(x) { # m3 <- mean((x - mean(x))^3) # return(m3/(sd(x))^3) #} #kurtosis <- function(x) { # m4 <- mean((x - mean(x))^4) # return(m4/(sd(x))^4 - 3) #} # same SSE as for ANOVA as one from SUMMARY SSE <- function(fit) { y <- fit$model[[1]] yhat <- fit$fitted return(sum( (y - yhat)^2 )) } # can get this value with anova table too: # (under MeanSq Column and Resids Row - that is s^2) standardErrorOfRegression <- function(fit) { sse.value <- invisible(SSE(fit)) n <- length(fit$fitted) kplusOne <- ncol(fit$model) return (sqrt((sse.value) / (n - kplusOne))) } MSE <- function(fit) { s <- standardErrorOfRegression(fit) return(s^2) } # Validation - training MSE # Given a model fit on the training data, use the full Data set to calculate test info # to calculate the test MSE MSE <- function(train.fit, fullData){ trainIndices <- as.numeric(rownames(train.fit$model)) yName = colnames(train.fit$model)[1] y <- fullData[,yName] yHat = predict(train.fit, fullData) return(mean( (y - yHat)[-trainIndices]^2 )) } # take only test index rows and the predictors used in the model #testData <- fullData[-trainIndices, colnames(train.fit$model)] #testY <- testData[, 1] #preds = predict(train.fit, testData) #overallMSE <- mean( (testY - preds)^2 ) standardErrorOfSlope <- function(fit) { x <- fit$model[[2]] s <- standardErrorOfRegression(fit) return (s / sqrt(SSxx(x))) } SSyy <- function(fit) { print("Warning: assuming quantitative response data") y <- fit$model[[1]] y.mean <- mean(y) return ( sum( (y - y.mean)^2 ) ) } SSxx <- function(x) { #x <- fit$model[[xName]] x.mean <- mean(x) return ( sum( (x - x.mean)^2 ) ) } SSxy <- function(x, y) { x.mean <- mean(x) y.mean <- mean(y) return ( sum( (x - x.mean) * (y - y.mean) ) ) } #standardErrorOfRegression <- function(sse.value, n) { # return(sqrt(sse.value / (n - 2))) #} # OR #a <- anova(lm) #ss <- a$`Sum Sq` #return(ss[length(ss)]) # OR #s <- summary(r.lm) #(1-s$r.squared)*SST(var$datamat$dc) SST <- function(fit) { return(SSyy(fit) - SSE(fit)) } # TODO # between group variance (equivalent to SST) # input: list of xs and ys, where xs are the factor names and y = response betweenGroupVariance <- function(xs, ys){ groups <- unique(xs) grandMean <- mean(ys) } # within group variance (same as SSE) # from page 636 in Allan Bluman # TODO: BlockDesignTest (anova nested) that contains tests for both # the treatments and blocks as in the notes. # TODO RandomizedDesignTest (anova global F) # TODO: TwoFactorialDesignTest (anova) ## Confidence interval for the Slope in Regression Model (multiple) slopeCI <- function(fit, level=0.95) { mat <- confint(fit, level=level) df <- data.frame(as.numeric(mat[,1]), as.numeric(mat[,2])) colnames(df) <- colnames(mat) return(df) } #slopeCI <- function(fit, level = 0.95) { # slope <- fit$coefficients[[2]] # sB1 <- standardErrorOfSlope(fit) # # # Calculate alpha for the t-statistic, and df # alpha <- 1 - level # n <- length(y) # df <- n - 2 # t.alpha2 <- abs(qt(alpha/2, df)) # # # calculate conf.int # leftCI <- slope - t.alpha2 * sB1 # rightCI <- slope + t.alpha2 * sB1 # # return( c(leftCI, rightCI) ) #} # Confidence interval for the Mean when x = xp # E(y) = yhat(xp) +- t(alpha/2,df) * s * sqrt(1/n + (xp - xmean)^2/SSxx) ## NOTE: can be found using R with this: # predict(model, new = data.frame(x.name=x.value), interval="confidence", level=0.95) # TODODO use Rfunctions file betaCI to get many decimal places in output meanCI <- function(fit, x.values=c(), level=0.95){ predictorNames <- names(fit$model)[-1] df <- data.frame(x.values) #rownames(df) <- rep("", length(predictorNames)) colnames(df) <- predictorNames return(predict(fit, newdata = df, interval="confidence", level=level)) } predictCI <- function(fit, x.values, level=0.95){ predictorNames <- names(fit$model)[-1] df <- data.frame(cbind(x.values)) #rownames(df) <- "" colnames(df) <- predictorNames return(predict(fit, newdata = df, interval="prediction", level=level)) } #meanCI <- function(fit, x.value, level=0.95) { # # finding the yhat value at a particular x-.value # yhat.at.xp <- fit$coeff[[2]] * x.value + fit$coeff[[1]] # yhat <- fit$fitted # x <- fit$model[[2]] # y <- fit$model[[1]] # # # Finding the std error of regression, s # s <- standardErrorOfRegression(fit) # # # Finding the t, alpha # alpha <- 1 - level # n <- length(y) # df <- n - 2 # t.alpha2 <- abs(qt(alpha/2, df)) # # # Calculating the confidence interval. # leftCI <- yhat.at.xp - t.alpha2 * s * sqrt(1/n + (x.value - mean(x))^2 / SSxx(x)) # rightCI <- yhat.at.xp + t.alpha2 * s * sqrt(1/n + (x.value - mean(x))^2 / SSxx(x)) # # return(c(leftCI, rightCI)) #} # Confidence interval for the Predictor when x = xp # yi = yhat(xp) +- t(alpha/2,df) * s * sqrt(1 + 1/n + (xp - xmean)^2/SSxx) ## NOTE: can be found using R with this: # predict(model, new = data.frame(x.name=x.value), interval="prediction", level=0.95) #predictCI <- function(fit, x.value, level=0.95) { # # finding the yhat value at a particular x-.value # yhat.at.xp <- fit$coeff[[2]] * x.value + fit$coeff[[1]] # yhat <- fit$fitted # x <- fit$model[[2]] # y <- fit$model[[1]] # # # Finding the std error of regression, s # s <- standardErrorOfRegression(fit) # # # Finding the t, alpha # alpha <- 1 - level # n <- length(y) # df <- n - 2 # t.alpha2 <- abs(qt(alpha/2, df)) # # # Calculating the confidence interval. # leftCI <- yhat.at.xp - t.alpha2 * s * sqrt(1 + 1/n + (x.value - mean(x))^2 / SSxx(x)) # rightCI <- yhat.at.xp + t.alpha2 * s * sqrt(1 + 1/n + (x.value - mean(x))^2 / SSxx(x)) # # return(c(leftCI, rightCI)) #} # Given restricted and unrestricted models, # do joint F-test but give Chi square instead of F # k = number of restrictions = df1 # n - (k+1) = df2, n = sample size. ##### TODO: write the hypothesis tested: figure out the B# = B# = 0 etc. # from the coefs that are missing in the reduced model. ####################################### TODO: check out EtaSq from DescTools ######################################## Use Anova() from car package. #TODO: if the predictor is a factor THEN make the null hypothesis be stated # as H0: mu_level1 = mu_level2 = .... NestedFTest <- function(r.lm, u.lm, printNice=TRUE){ # g = number of parameter difference g = length(u.lm$coef) - length(r.lm$coef) # k = num parameters in the unrestricted/complete model k = length(u.lm$coef) - 1 # n - k - 1 df2 = nrow(u.lm$model) - k - 1 df1 = g # sse.r <- SSE(r.lm) sse.c <- SSE(u.lm) F.nested <- ((sse.r - sse.c) / df1) / ((sse.c / df2)); F.nested chi.stat <- F.nested * df1 chi.p.value <- round(1 - pchisq(chi.stat, df=df1), 5) f.p.value <- round(1 - pf(F.nested, df1=df1, df2=df2), 5) result = data.frame(ChiSquare=chi.stat, ChiSqPValue=chi.p.value, df.chi = df1, FStatistic=F.nested, FPvalue=f.p.value, df1=df1, df2=df2) if(f.p.value < 0.05){ recommend = u.lm recName = "complete model" } else{ recommend = r.lm recName = "reduced model" } result = list(RecommendedModel=recommend, RecommendedName=recName,Test=result) if(printNice){ nu = formula(u.lm) nr = formula(r.lm) cat("\n") cat("#############################################################\n") cat("#### Analysis Of Variance ###\n") cat("#### (F Test and Chi-Square Test for Nested Models) ###\n") cat("#############################################################\n") cat("\n") cat("H0: reduced model is true: \n"); cat(paste(nr[[2]], nr[[1]], nr[3])) cat("\n\nHA: complete model is true: \n"); cat(paste(nu[[2]], nu[[1]], nu[3])) cat("\n\n") cat("F statistic: ", F.nested, "\n") cat("p-value: ", f.p.value, "\n") cat("numerator df: ", df1, "\n") cat("denominator df: ", df2, "\n\n") return(invisible(result)) }else{ return(result) } } # The Global F-test for regression model fit. FTest <- function(fit) { sst = SST(fit) sse = SSE(fit) k = length(fit$coefficients) - 1 n = nrow(fit$model) Fcrit <- ((sst - sse)/k) / (sse / (n-k-1)) p.value <- 1 - pf(Fcrit, df1=k, df2= n-k-1) cat("\n") cat("#############################################################\n") cat("#### Analysis Of Variance ###\n") cat("#### (F Test The Regression Model) ###\n") cat("#############################################################\n") cat("\n") cat("F statistic: ", Fcrit, "\n") cat("p-value: ", p.value, "\n\n") df <- data.frame(FStatistic=Fcrit, PValue=p.value, DFNumerator=k, DFDenominator=n-k-1) rownames(df) <- "" return(invisible(df)) } # REASONOING: method shown in section 8.4 Sinicich. # We are splitting data determined by xSplit (by value of xs) and then # doing F-variance test on regression stderroreg of both models (MSE's) # xSplit = the x value such that x <= xSplit is sample 1 and x > xSplit is sample2 # variableName = the name of the variable that we want to split on. # fit = the lm object # alpha = sig level # alternative = two-sided or one-sided (cif one sided then calcs which side) # PREREQ: only for non-multiple regression (simple models) HomoskedasticityRegressionTest.Split <- function(theFormula, data, xName, xSplit, alternative="two-sided", alpha=0.05){ sample1 <- data[data[[xName]] <= xSplit, ] sample2 <- data[data[[xName]] > xSplit, ] fit1 <- lm(theFormula, data=sample1) fit2 <- lm(theFormula, data=sample2) n1 <- nrow(sample1) n2 <- nrow(sample2) Fstat <- 0 k <- ncol(fit1$model) -1# should be equal to that of mod2, is num independent vars # including transformations. numerator.df <- 0 denominator.df <- 0 mse1 <- MSE(fit1) mse2 <- MSE(fit2) if(mse1 > mse2) { Fstat <- mse1 / mse2 numerator.df <- n1 - (k+1) denominator.df <- n2 - (k+1) } else { Fstat <- mse2 / mse1 numerator.df <- n2 - (k+1) denominator.df <- n1 - (k+1) } # calculating F-crit Fcrit <- 0 p.value <- 0 alternativeStr <- 0 if(alternative == "two-sided"){ alternativeStr <- "Ha: MSE.1 != MSE.2" Fcrit <- qf(alpha/2, df1=numerator.df, df2=denominator.df, lower.tail=F) p.value <- 2*pf(Fstat, df1=numerator.df, df2=denominator.df, lower.tail=F) } else { # else it's one-sided if(mse1 < mse2) alternativeStr <- "Ha: MSE.1 < MSE.2" else alternativeStr <- "Ha: MSE.1 > MSE.2" Fcrit <- qf(alpha, df1=numerator.df, df2=denominator.df, lower.tail=F) p.value <- pf(Fstat, df1=numerator.df, df2=denominator.df, lower.tail=F) } cat("\n") cat("#############################################################\n") cat("######## Homoskedasticity of Regression Test ########\n") cat("#############################################################\n") cat(" H0: MSE.1 == MSE.2 \n") cat(" ",alternativeStr," \n",sep="") #cat("") cat("F-statistic = ", Fstat, sep="", "\n") cat("Numerator DF = ", numerator.df, sep="", "\n") cat("Denominator DF = ", denominator.df, sep="", "\n") cat("Critical F-value = ", Fcrit, sep="", "\n") cat("P-value = ", p.value,sep="","\n") df <- data.frame(Fstat=Fstat, FCritical=Fcrit, PValue=p.value) return(invisible(df)) } # Making the prediction equation, returning it as a function # fit = the lm object #predictionEquation <- function(fit) { # intercept = fit$coef[[1]] # slopes = as.numeric(fit$coef[-1]) # # slopesSign = c() #if(slopes < 0) " - " else " + " # newSlopes = c() # for (i in 1:length(slopes)) { # if(slopes[i] < 0){ # slopesSign = c(slopesSign, " - ") # newSlopes = c(newSlopes, abs(slopes[i])) # } # else{ # slopesSign = c(slopesSign, " + ") # newSlopes = c(newSlopes, slopes[i]) # } # # } # # Making the x-names x1 x2 x3 ... etc # xStrings <- names(fit$coefficients)[-1] # #numXs = length(fit$coefficients) - 1 # #xStrings = c() # #for(i in 1:numXs){ # # xStrings = c(xStrings, paste("x", i, sep="")) # #} # numCoefs <- length(fit$model) # multiplySigns <- replicate(numCoefs, "*") # allCoefsWithVars <- paste(intercept, # paste(c(rbind(slopesSign, newSlopes, # multiplySigns, xStrings)), # collapse = ''), sep="") # # # args = find independent names first with 'stringr' package # tup <- separateArgs(fit) # args <- tup[[1]] # extraArgs <- tup[[2]] # ## TODO: body = detect types of patterns in the formula so I(RPM^2) # # means square of the arg1=RPM, and RPM:CPRATIO is RPM*CPRATIO # # Then put those variables in the formula. # # PROCSS: # # 1. get independent args # # 2. for each independent arg, check for I-terms and get the matching # # i-term( thing inside the Iterm must match the independent arg. Get # # the poly-power (hint - split at ^)) # # 3. for each idnependent arg, if term is not I-term, then must be # # interaction term so split at ";" and create variable x1 * x2 to put # # in formula. # patterns <- c("\\^", "\\:") # bodyArgs <- c() # for (p in patterns){ # testPattern <- str_detect(extraArgs, p) # # for this pattern, get the simple arg with this pattern # str_detect(args, p) # ## TODO FINSIH # } # # eval(parse(text = paste("yHat <- function(", args, ") { return(", # body, ") }", sep=""))) # # return(eval(theFormula)) #} # Finds the independent, untransformed arguments of the lm object # So if we have I(RPM^2), it returns RPM separateArgs <- function(fit){ allNames <- names(fit$coefficients)[-1] patterns <- c("\\^", "\\:") extraArgs <- c() for (p in patterns) { # If no detecting of a pattern, then is INDEP ARG testExtra <- str_detect(allNames, p) extraArgs <- c(extraArgs, allNames[testExtra]) } indicesNotExtraArgs <- which(!allNames %in% extraArgs) args <- allNames[indicesNotExtraArgs] return(list(args, extraArgs)) } # OUTLIER POINTS = are those beyond (-2,2) of std residuals outlier.outlierValues <- function(fit){ library(car) srs = rstandard(fit) isOutlier <- srs < -2 | srs > 2 print(outlierTest(fit)) # from car df <- data.frame(Fitted=fit$fitted.values, StandardizedResiduals=srs, IsOutlier=isOutlier) return(invisible(df)) } # INFLUENTIAL POINTS # fit = the lm object influence.leverageValues <- function(fit){ hs <- hatvalues(fit) k <- length(fit$model) - 1 n <- nrow(fit$model) h.mean <- (k+1)/n h.cutoff <- 2*(k+1)/n isInfluential <- hs > h.cutoff return(data.frame(InfluentialPoints=hs, CutOff=h.cutoff, AvgLev=h.mean, IsInfluential=isInfluential)) } influence.cooksDistances <- function(fit) { cks <- cooks.distance(fit) p <- length(fit$coef) # p = number of parameters n <- nrow(fit$model) # Cooks distance Di follows an F-distribution: Di ~ F(df1=p, df2=n-p) Fcrit <- qf(0.5, df1=p, df2=n-p) cks.fprob <- pf(cks, df1=p, df2=n-p) # TODO: check if my method here cks > Fcrit is correct: # or do we use cks.fvalues > Fcrit??? isInfluential <- cks > Fcrit | cks >= 1 # https://newonlinecourses.science.psu.edu/stat501/node/340/ # An alternative method for interpreting Cook's distance that is sometimes # used is to relate the measure to the F(p, n–p) distribution and to find the # corresponding percentile value. If this percentile is less than about # 10 or 20 percent, then the case has little apparent influence on the # fitted values. On the other hand, if it is near 50 percent or even higher, # then the case has a major influence. (Anything "in between" is more ambiguous.) return(data.frame(CooksPoints=cks, FcritValue=Fcrit, CooksFProb=cks.fprob, FcritProb=rep(0.5, n), IsInfluential=isInfluential)) } # NOTE # pi.hat.Ho <- nullMod$fitted.values #pi.hat.Ha <- altMod$fitted.values #y <- placekick$good # ****** # likRatio <- -2 * sum(y * log(pi.hat.Ho/pi.hat.Ha) + (1-y)*log((1-pi.hat.Ho)/(1-pi.hat.Ha))) # NOTE: null model deviance is bigger (assuming) so the statistic # will be negative if not. # Equivalent to nested F-test between two models here, like anova(null, alt) # Tests missing parameter significance. NestedLikelihoodRatioTest <- function(reducedModel, fullModel, printNice=TRUE) { y <- reducedModel$model[1] pi.hat.Ho <- reducedModel$fitted.values pi.hat.Ha <- fullModel$fitted.values # don't know why this doesn't work when comparing null Mod with alternative #likRatioStat <- -2 * sum(y * log(pi.hat.Ho/pi.hat.Ha) + (1-y)*log((1-pi.hat.Ho)/(1-pi.hat.Ha))) likRatioStat <- reducedModel$deviance - fullModel$deviance # note: df.null = n - 1, df.resid = n - k - 1, k = num params (not incl. B0) df <- reducedModel$df.residual - fullModel$df.residual pValue <- 1 - pchisq(likRatioStat, df) #chi.crit <- qchisq(0.05, df=df, lower.tail=F) result <- rbind(c(ResidualDev.Ho=reducedModel$deviance, ResidualDev.Ha=fullModel$dev, df.res.Ho=reducedModel$df.residual, df.res.Ha=fullModel$df.residual, df.dev=df, Deviance=likRatioStat, PValue=pValue)) #ChiCrit=chi.crit, rownames(result) <- "" result <- data.frame(result) statement <- "" if(pValue < 0.05){ statement <- paste("Reject H0. Conclude at least one of the extra β ", "coefficients \n", "in the complete model is nonzero, so that the complete model is\n", "better for predicting Y = ", names(reducedModel$model)[1], ".", sep="") } else{ statement <- paste("Insufficient evidence to reject Ho, that is, to conclude that", "\nthe extra terms in the complete model are statistically useful", "\nuseful predictors in the regression model.", sep="") } if(printNice){ #likRatioPrintNice(result, reducedModel, fullModel, statement) nf = formula(reducedModel) na = formula(fullModel) cat("\n") cat("#####################################################################\n") cat("####### Nested Likelihood-Ratio Test #######\n") cat("#####################################################################\n") cat("\tH0: reduced model is true: "); cat(paste(nf[[2]], nf[[1]], nf[3])) cat("\n") cat("\tHA: complete model is true: "); cat(paste(na[[2]], na[[1]], na[3])) cat("\n\n") cat(" ΔG:\t\t ", result$Deviance, "\n") #cat(" Critical Chi-square (α = 0.05): ", ChiCrit, "\n") cat(" df:\t\t ", result$df, "\n") cat(" p-value:\t\t ", result$PValue, "\n\n") cat(statement) return(invisible(result)) }else{ return(result) } } # nested likelihood test between null model and fit model # NOTE: use the count = cbind(success, total) y-value when fitting the fit model # so that here tempData is made of two cols. Do not let y be a proportion # otherwise we get weird results. # TODO: make this work for binomial glm when response = proportion (beetle.glm in # STAT320, topic7) DevianceTest <- function(fit, printNice=TRUE){ # Check if the fitted model contains an offset. If so, we need to fit # the null model with this same offset # The nullData contains the response column observations and the # offset in another column nullData <- NULL yName <- NULL theFormula <- NULL if(!is.null(fit$offset)){ nullData <- data.frame(fit$model[1], OFFSET=fit$offset) yName <- colnames(nullData)[1] theFormula <- as.formula(paste(yName, "~ offset(OFFSET)", sep="")) } else { nullData <- data.frame(fit$model[1]) yName <- colnames(nullData)[1] theFormula <- as.formula(paste(yName, "~ 1", sep="")) } nullModel <- glm(theFormula, family=fit$family, data=nullData) result <- NestedLikelihoodRatioTest(nullModel, fit, printNice = printNice) if(printNice){ return(invisible(result)) } else { return(result) } } # Likelihood Ratio Test for the GLM Model # Null hypothesis is that expected mu and observed ys are the same # If low p-value then they are not. # TESTS: the difference between expected successes with observed ones, and the # expected failures with observed ones. (global F-test) # Equivalent to global F-test, tests overall model fit. # TODO: make this work for binomial glm when response = proportion (beetle.glm in # STAT320, topic7) ResidualDevianceTest <- function(fit, printNice=TRUE) { # residualdeviance has chi-square distribution on n - k - 1 degrees freedom. df <- fit$df.residual # always n - k - 1, where k+1 = num params/coefs res.dev <- fit$deviance result <- data.frame(LikRatio=res.dev, df=df, PValue= 1 - pchisq(res.dev, df=df)) row.names(result) <- "" # Ho: deviance = 0 p = big fail reject H0 = good model fit = deviance small statement <- "" if(result$PValue < 0.05){ # testing if G = 0 # ni <- gen$total; yi <- gen$male; mui <- ni *ratio.glm$fitted.values # G <- 2*sum( yi*log(yi/mui) + (ni-yi)*log((ni-yi)/(ni-mui)) ) statement <- paste("Reject H0. Conclude the residual deviance is large and\n", "different from zero. So expected successes are not equal to\n", "observed successes and expected failures are not equal to \n", "observed failures. The model is not a good fit for the data.", sep="") } else{ statement <- paste("Fail to reject H0. Not enough evidence to conclude that the\n", "residual deviance is not 0, so we say the residual deviance is small.\n", "So expected and observed successes/failures are similar. \n", "Thus the model is a good fit for the data.", sep="") } # TODO: update null hypothesis, is not the same of the nested test H0. if(printNice){ yName <- names(fit$model)[1] form = as.formula(paste(yName, " ~ 1", sep="")) nullModel <- glm(form, data=fit$model, family=fit$family) #likRatioPrintNice(result, nullModel, fit, statement) nf = formula(nullModel) na = formula(fit) cat("\n") cat("#####################################################################\n") cat("####### Likelihood-Ratio Residual Deviance Test #######\n") cat("#####################################################################\n") cat("\tH0: residual deviance G = 0 \n") #; cat(paste(nf[[2]], nf[[1]], nf[3])) #cat("\n") cat("\tHA: residual deviance G != 0\n\n") #; cat(paste(na[[2]], na[[1]], na[3])) cat(" G:\t\t ", result$LikRatio, "\n") cat(" df:\t\t ", result$df, "\n") cat(" p-value:\t\t ", result$PValue, "\n\n") cat(statement) return(invisible(result)) } else{ return(result) } } NullDevianceTest <- function(model){ # null deviance has chi-square distribution on n - 1 degrees freedom. df <- model$df.null dev <- model$null.deviance result <- data.frame(NullDeviance=dev, df=df, PValue= 1 - pchisq(dev, df=df)) row.names(result) <- "" return(result) } #DevianceResiduals <- function(obsData, expData=NULL) { # # doing chi-test just to get expected values. # if(!is.null(expData)) chi.test <- chisq.test(obsData, p=expData/sum(expData)) # else chi.test <- chisq.test(obsData) # os <- obsData # es <- chi.test$exp # return(sign(os - es) * sqrt(abs(2 * os * log(os/es)))) #} # # GOAL: computes the deviance residuals for a poisson glm # TODO: how to check that family == poisson? (string-based comparison?) # if this is not a poisson glm, this result will be wrong # must be the same as residuals(fit) DevianceResiduals.Poisson <- function(fit) { yi <- fit$model[1] mui <- fit$fitted.values si <- sign(yi - mui) di <- si * sqrt(2 * (yi * log(yi/mui) - (yi - mui))) return(di[,]) } # TODO: cannot calculate mui since the counts n_i are not always given - sometimes # we are just given binary 1,0 data. # TODO: this still won't work when we get NaN's like when ni's and yi's are the same. #DevianceResiduals.Binomial <- function(fit) { # yi <- fit$model[1] # mui <- #yi <- beetleData$r #fit$model[1] # ni <- beetleData$n # mui <- ni * beetle.glm$fitted.values # si <- sign(yi - mui) # di <- si * sqrt(2 * (yi * log(yi/mui) + (ni - yi) * log((ni-yi)/(ni - mui)))) ##} ResidualDevianceTest.Poisson <- function(fit){ devianceRes <- DevianceResiduals.Poisson(fit) deviance <- sum(devianceRes^2) result <- data.frame(ResidualDeviance=deviance, PValue=1-pchisq(deviance, df=fit$df.residual), DegreesFreedom = fit$df.residual) return(result) } # ---------------------- Row/Col Probability Estimates ----------------------------------------- rowProbabilityHat <- function(tbl){prop.table(tbl, margin=1)} colProbabilityHat <- function(tbl){prop.table(tbl, margin=2)} # ---------------------- Returns table with marginal row/col sums ------------------------------ ################ TODO make for k-way tables too, not just two-way marginalTable <- function(tbl) { t = tbl dimnames(t) <- NULL t <- cbind(t, margin.table(t, margin=1)) t <- rbind(t, margin.table(t, margin=2)) dms <- dimnames(tbl) dms[[1]] <- c(dms[[1]], "") # c(dms[[1]], "ColTotals") dms[[2]] <- c(dms[[2]], "") dimnames(t) <- dms return(t) } # ---------------------------------------------------------------------------------------------- ################################################################################# ######## Measures of Association for 1,2-way Tables ######## ################################################################################# # odds ratio, relative risk, diff of proportions test independence of two variables # in the two-way table. # ---------------------- Odds Ratio ---------------------------- #################################### TODO make it work with ftable #################################### problem because no names in ftable # odds ratio for n x m table (two-way) is the same anyway you place the coeffs # Returns odds ratio for all combinations of pairings between variable levels. # CAN TEST WITH THIS DATA: #eyeTable <- as.table(matrix(c(20,30,10,15,10,85,25,15,12,20,10,82,45,45,22,35,20,167),byrow = TRUE, nrow=3)) #rownames(eyeTable) <- c("Female", "Male", "Total") #colnames(eyeTable) <- c("Black", "Brown", "Blue", "Green", "Gray", "Total") #oddsRatio(eyeTable) colOdds <- function(tbl) { if(length(dim(tbl)) > 2){ cat("Error: Needs to be 2-dimensional table") return(invisible(NULL)) } ### make names combos combosColnames <- combn(colnames(tbl), m=2) combosColnames.forward <- paste(combosColnames[1,], "/", combosColnames[2,], sep="") combosColnames.backward <- paste(combosColnames[2,], "/", combosColnames[1,], sep="") ### make odds for each col, holding rows constant combosCol <- lapply(1:nrow(tbl), function(i) combn(tbl[i,], m=2)) cOdds.forward <- lapply(1:nrow(tbl), function(i){combosCol[[i]][1, ] / combosCol[[i]][2, ]}) cOdds.backward <- lapply(1:nrow(tbl), function(i){combosCol[[i]][2, ] / combosCol[[i]][1, ]}) # adjusting library(plyr) cOdds.forward <- ldply(cOdds.forward) cOdds.backward <- ldply(cOdds.backward) #naming colnames(cOdds.forward) <- combosColnames.forward rownames(cOdds.forward) <- rownames(tbl) colnames(cOdds.backward) <- combosColnames.backward rownames(cOdds.backward) <- rownames(tbl) return(cbind(cOdds.forward, cOdds.backward)) } rowOdds <- function(tbl){ if(length(dim(tbl)) > 2){ cat("Error: Needs to be 2-dimensional table") return(invisible(NULL)) } ### make names combos combosRownames <- combn(rownames(tbl), m=2) combosRownames.forward <- paste(combosRownames[1, ], "/", combosRownames[2,], sep="") combosRownames.backward <- paste(combosRownames[2, ], "/", combosRownames[1,], sep="") ### make odds for each col, holding rows constant combosRow <- lapply(1:ncol(tbl), function(i) combn(tbl[,i], m=2)) rOdds.forward <- lapply(1:ncol(tbl), function(i){combosRow[[i]][1, ] / combosRow[[i]][2, ]}) rOdds.backward <- lapply(1:ncol(tbl), function(i){combosRow[[i]][2, ] / combosRow[[i]][1, ]}) # adjusting a bit library(plyr) rOdds.forward <- t(ldply(rOdds.forward)) rOdds.backward <- t(ldply(rOdds.backward)) #naming colnames(rOdds.forward) <- colnames(tbl) rownames(rOdds.forward) <- combosRownames.forward colnames(rOdds.backward) <- colnames(tbl) rownames(rOdds.backward) <- combosRownames.backward return(rbind(rOdds.forward, rOdds.backward)) } oddsRatio <- function(tbl) { if(length(dim(tbl)) > 2){ cat("Error: Needs to be 2-dimensional table") return(invisible(NULL)) } ### make names combos combosColnames <- combn(colnames(tbl), m=2) combosColnames <- paste(combosColnames[1,], "/", combosColnames[2,], sep="") combosRownames <- combn(rownames(tbl), m=2) combosRownames <- paste(combosRownames[1, ], "/", combosRownames[2,], sep="") ### make odds for each col, holding rows constant combosCol <- lapply(1:nrow(tbl), function(i) combn(tbl[i,], m=2)) cOdds <- lapply(1:nrow(tbl), function(i){combosCol[[i]][1, ] / combosCol[[i]][2, ]}) library(plyr) cOdds <- ldply(cOdds) colnames(cOdds) <- combosColnames rownames(cOdds) <- rownames(tbl) oddsPairs <- lapply(1:ncol(cOdds), function(i) combn(cOdds[,i], m=2)) oddsRatios <- lapply(1:ncol(cOdds), function(i) {oddsPairs[[i]][1,] / oddsPairs[[i]][2,]}) oddsRatios <- t(ldply(oddsRatios)) colnames(oddsRatios) <- combosColnames rownames(oddsRatios) <- combosRownames return(oddsRatios) } # TODO: normality subset tests for the completely randomized design # and rest # factorials etc... within each population, do shapiro wilk normality test # and report p-values in a table. Also graph densities like in the # Leaf data set (logistic) # TODO: equal variance subset tests for all the randomized/block/factorial # designs (levens and bartlet) and report p-vals in table. # ------------------------------------------------------------------------------- bootstrapMean <- function(data, R, level=0.95){ # Get n samples from the known population distribution. (this is the data given) n = length(data) # observed data, original data # Sample from F-hat (instead of rexp) to sample with replacement from F-hat H.star = rep(NA, R) for(i in 1:R){ # resample from original data with replacement. dataStar = sample(data, size=n, replace=TRUE) #this is the bootstrap sample H.star[i] = mean(dataStar) } # MEAN(H*) should be close to MU_XBAR should be close to MU # SD(H*) should be close to SD_XBAR should be close to S/SQRT(N) cat("boot.mu_xbar (hstar) = ", mean(H.star), "\n", sep="") cat("xbar (mean of data) = ", mean(data), "\n\n", sep="") B.hat = mean(H.star) - mean(data) # estimated bias cat("B.hat = mean(hstar) - mean(data) = ", B.hat, "\n", sep="") mu.hat.B = mean(data) - B.hat # bias-corrected version of mu cat("theta.hat.B = mean(data) - bias = ", mu.hat.B, "\n\n",sep="") se.mean = sd(H.star) # standard error of the mean cat("boot.se.mean (hstar) = ", se.mean, "\n", sep="") # call this se.mean #print(sqrt(var(H.star))) # same as sd(H.star) cat("se.mean = sigma/sqrtn(n) = ", theta/sqrt(n), "\n", sep="") cat("se.mean = s / sqrt(n) = ", sd(data)/sqrt(n), "\n\n", sep="") # 95 % confidence interval methods. # calculate critical value first lower = abs( (1-level)/2) upper = lower + level z.crit = abs(qnorm(lower)) cat("CI by normal approximation: ") cat("(",mu.hat.B - z.crit*se.mean,", ",mu.hat.B + z.crit*se.mean,")","\n",sep="") cat("CI by percentile method: ") qs = quantile(H.star, c(lower, upper)) cat("(", qs[1],", ", qs[2],")", "\n", sep="") cat("CI by basic method:", "") cat("(", 2*xbar - qs[2],", ", 2*xbar - qs[1],")", "\n", sep="") return(invisible(H.star)) } # STAT330 Learning ----------------------------------------------------------------------- # GOAL: fit lda model but attach also the observed data in a separate column. # ldaFit <- function(formula()) # TODO: how to get formula in arguments #ldaFit <- function(response, predictors, data){ # library(MASS) # formulaToFit <- reformulate(response=response, termlables=predictors) # lda.fit <- lda(formulaToFit, data=data) # return (lda.fit) #} # lda.fit = the model fit by lda (MASS package) # GOAL: converts output of lda.fit (list) to data frame to look nicer ldaToDataFrame <- function(lda.fit){ pred.list <- predict(lda.fit) # note: posterior in pred.list may be multidim array? depending on num classes # so that changes num cols of this df ?? ldaValues <- pred.list$x colnames(ldaValues) <- "LDAClassifier" pred.df <- data.frame(PredictedClass = pred.list$class, ldaValues, Posterior=pred.list$posterior) # note: LDA classifier == linear discriminant fits return(pred.df) } # observedY = original observed y-values (categorical) # lda.fit = the model fit by lda (MASS package) # GOAL: calculate lda error rate, which is estimation of Bayes error rate. ldaErrorRate <- function(lda.fit, observedY) { return(1 - mean(predict(lda.fit)$class == observedY)) } # GOAL: calculate confusion matrix of the lda fit # observedY = vector of observed y values (categorical) # lda.fit = model fit by lda # link to another type of confusion matrix: # https://maths-people.anu.edu.au/~johnm/courses/mathdm/2008/pdf/r-exercisesVI.pdf twoWayConfusionMatrix <- function(lda.fit, observedY){ df = data.frame(PredictedResponse=predict(lda.fit)$class, ObservedResponse=observedY) # note: returning transpose so positions of sensitivity and specificity # match my notes tbl = marginalTable(table(df)) # rename "ColTotals" to total population counts per class rownames(tbl)[3] <- "TotalPopulationCounts" colnames(tbl)[3] <- "TotalPredictedCounts" # calculate sensitivity (true positive) = lower right corner rate: TP / P # TODO: apply to multivariate case # calculate specificity (true negative) = upper left corner rate: TN / N return(tbl) }
fac6778abef5010ce5bc1cbf8efb20d2c0892857
0ea852e85df22dde661279d2738f229e2f8511e1
/R/gra.R
69416b86957c6197e60f49c0a0d5aad89cc29c87
[]
no_license
ekarbowiak/SuperFarmerPKEK
6666768970e682de58a1d7136b744c0a3f642f4f
e660a8a5ef72834d77a64bd8ce7290e9e2c0af8e
refs/heads/master
2021-01-13T05:31:16.125472
2017-01-27T09:08:00
2017-01-27T09:08:00
80,165,451
0
0
null
null
null
null
UTF-8
R
false
false
1,051
r
gra.R
#' Gra w SuperFarmera zadana strategia #' #' Funkcja gra() oblicza czas gry w grę SupreFarmer zadana strategia #' #' @param strategia strategia, ktora chcemy zagrac. W pakiecie do wyboru: strategy1, strategy2, strategy3 #' @param kostka1 zwierzeta znajdujace sie na kostce nr 1 #' @param kostka2 zwierzeta znajdujace sie na kostce nr 2 #' @param StadoGracza stan stada gracza, zapisany jako nazwany wektor #' @return funkcja zwraca czas gry dana strategia #' #' @export #' #' gra = function(strategia=SuperFarmerPKEK::strategy2, kostka1 = SuperFarmerPKEK::kostka1, kostka2 = SuperFarmerPKEK::kostka2,StadoGracza = SuperFarmerPKEK::StadoGracza) { czas = 0 while (!czy_wygrana(StadoGracza)) { czas = czas + 1 StadoGracza = strategia(StadoGracza) if (!czy_wygrana(StadoGracza)) { kostka1.wynik = sample(kostka1, 1) kostka2.wynik = sample(kostka2, 1) StadoGracza = reproduction(kostka1.wynik, kostka2.wynik, StadoGracza)} } return(czas) }
18f8d934168fb4283542605213ba6edba053fc98
b119d79e8a8790fd6ce300bab406a2b67f7e70ec
/tests/testthat/test-parser.R
c2eb67d6c3df5d60b650689ea21289dffa0168eb
[ "BSD-3-Clause" ]
permissive
gadenbuie/selectr
f8a499c8aad67e3dfacb312e155947b8a6dd8f93
7bd1b0f834fc7eaa1b6dde749a1b847884663dc0
refs/heads/master
2022-04-27T22:02:58.729128
2019-04-02T08:42:08
2019-04-02T08:43:19
202,213,707
0
0
NOASSERTION
2019-08-13T19:47:56
2019-08-13T19:47:56
null
UTF-8
R
false
false
5,984
r
test-parser.R
context("parser") test_that("parser parses canonical test expressions", { parse_many <- function(css) { selectors <- lapply(css, function(x) parse(x)) n <- length(selectors) results <- list() for (i in seq_len(n)) { selector <- selectors[[i]] if (is.list(selector)) { results[[i]] <- unlist(lapply(selector, function(x) x$repr())) } else { results[[i]] <- selector$repr() } } if (n) unlist(results) else character(0) } expect_that(parse_many("*"), equals("Element[*]")) expect_that(parse_many("*|*"), equals("Element[*]")) expect_that(parse_many("*|foo"), equals("Element[foo]")) expect_that(parse_many("|foo"), equals("Element[foo]")) expect_that(parse_many("foo|*"), equals("Element[foo|*]")) expect_that(parse_many("foo|bar"), equals("Element[foo|bar]")) expect_that(parse_many('foo[lang|="zh"]'), equals("Attrib[Element[foo][lang |= 'zh']]")) # This will never match, but it is valid: expect_that(parse_many("#foo#bar"), equals("Hash[Hash[Element[*]#foo]#bar]")) expect_that(parse_many(c("div>.foo", "div> .foo", "div >.foo", "div > .foo", "div > .foo", "div \n> \t \t .foo", "div\r>\n\n\n.foo", "div\f>\f.foo")), equals(rep("CombinedSelector[Element[div] > Class[Element[*].foo]]", 8))) expect_that(parse_many(c("td.foo,.bar", "td.foo, .bar", "td.foo\t\r\n\f ,\t\r\n\f .bar")), equals(rep(c("Class[Element[td].foo]", "Class[Element[*].bar]"), 3))) expect_that(parse_many(c("div, td.foo, div.bar span")), equals(c("Element[div]", "Class[Element[td].foo]", "CombinedSelector[Class[Element[div].bar] <followed> Element[span]]"))) expect_that(parse_many("div > p"), equals("CombinedSelector[Element[div] > Element[p]]")) expect_that(parse_many("td:first"), equals("Pseudo[Element[td]:first]")) expect_that(parse_many("td :first"), equals("CombinedSelector[Element[td] <followed> Pseudo[Element[*]:first]]")) expect_that(parse_many(c("a[name]", "a[ name\t]")), equals(rep("Attrib[Element[a][name]]", 2))) expect_that(parse_many("a [name]"), equals("CombinedSelector[Element[a] <followed> Attrib[Element[*][name]]]")) expect_that(parse_many(c('a[rel="include"]', 'a[rel = include]')), equals(rep("Attrib[Element[a][rel = 'include']]", 2))) expect_that(parse_many(c("a[hreflang |= 'en']", "a[hreflang|=en]")), equals(rep("Attrib[Element[a][hreflang |= 'en']]", 2))) expect_that(parse_many("div:nth-child(10)"), equals("Function[Element[div]:nth-child(['10'])]")) expect_that(parse_many(":nth-child(2n+2)"), equals("Function[Element[*]:nth-child(['2', 'n', '+2'])]")) expect_that(parse_many("div:nth-of-type(10)"), equals("Function[Element[div]:nth-of-type(['10'])]")) expect_that(parse_many("div div:nth-of-type(10) .aclass"), equals("CombinedSelector[CombinedSelector[Element[div] <followed> Function[Element[div]:nth-of-type(['10'])]] <followed> Class[Element[*].aclass]]")) expect_that(parse_many("label:only"), equals("Pseudo[Element[label]:only]")) expect_that(parse_many("a:lang(fr)"), equals("Function[Element[a]:lang(['fr'])]")) expect_that(parse_many('div:contains("foo")'), equals("Function[Element[div]:contains(['foo'])]")) expect_that(parse_many("div#foobar"), equals("Hash[Element[div]#foobar]")) expect_that(parse_many("div:not(div.foo)"), equals("Negation[Element[div]:not(Class[Element[div].foo])]")) expect_that(parse_many("td ~ th"), equals("CombinedSelector[Element[td] ~ Element[th]]")) # handle comments expect_that(parse_many("a /* test */"), equals("Element[a]")) expect_that(parse_many("a/* test */"), equals("Element[a]")) expect_that(parse_many("/* test */ a"), equals("Element[a]")) expect_that(parse_many("/* test */a"), equals("Element[a]")) expect_that(parse_many("a /* test */ b"), equals("CombinedSelector[Element[a] <followed> Element[b]]")) expect_that(parse_many("a /* test "), equals("Element[a]")) }) test_that("parsed elements print correctly", { shw <- function(x) trimws(capture.output(parse(x)[[1]]$show())) expect_that(shw("a"), equals("Element[a]")) expect_that(shw(".test"), equals("Class[Element[*].test]")) expect_that(shw(":active"), equals("Pseudo[Element[*]:active]")) expect_that(shw("a:not(.toggle)"), equals("Negation[Element[a]:not(Class[Element[*].toggle])]")) expect_that(shw("[href]"), equals("Attrib[Element[*][href]]")) expect_that(shw("#id"), equals("Hash[Element[*]#id]")) }) test_that("compiled regex parsing functions behave as expected", { m_whitespace <- compile_('[ \t\r\n\f]+') m_number <- compile_('[+-]?(?:[0-9]*\\.[0-9]+|[0-9]+)') m_hash <- compile_(paste0("^#([_a-zA-Z0-9-]|", nonascii, "|\\\\(?:", delim_escapes, "))+")) m_ident <- compile_(paste0("^([_a-zA-Z0-9-]|", nonascii, "|\\\\(?:", delim_escapes, "))+")) expect_that(m_whitespace("a b"), equals(match_whitespace("a b"))) expect_that(m_number("a 1"), equals(match_number("a 1"))) expect_that(m_hash("a #test"), equals(match_hash("a #test"))) expect_that(m_ident(" test"), equals(match_ident(" test"))) })
ab3214b976903edc7adda28eea07c05c8ceadcb1
d692ef9a915e8d901d6c17567a632f555c70d5c9
/YATAWebModels/R/generators.R
bada7e4ad93635605bdc20d759267398a8f42514
[ "CC0-1.0" ]
permissive
cryptobuks1/YATA2
386f0cc47e6bfeda8c626d6d44e033708f06c404
04d7c4fefea3babc0d0f30ee15c9a52602623055
refs/heads/main
2023-04-26T16:05:54.430701
2021-05-27T15:00:58
2021-05-27T15:00:58
null
0
0
null
null
null
null
UTF-8
R
false
false
1,761
r
generators.R
makePoints = function(size=100) { rpar = 50 # Start r1 = sample(100:150, 10, replace=TRUE) idx = sample(1:10, 1) # Plus/Minus ud = sample(c(-1,1),size,replace=TRUE) #values v1 = runif(n = size, min = 0, max = 1) v1 = round(v1,3) var = v1 * ud / 10 dat = rep(r1[idx], size) for (i in 1:(size-1)) { dat[i+1] = dat[i] * (1 + var[i]) } data.frame(x=seq(1,size), y=dat) } makePlot = function(df, color, base) { p = ggplot(data=df) + geom_point(aes(x,y)) + theme_bw() if (!missing(base)) p = base + p m = nrow(df) p = p + geom_segment(aes(x=df[1,1], y=df[1,2], xend=df[m,1], yend=df[m,2], colour=color)) plot = Plot$new(df,p,calcRect(df)) plot$tg = calcSlope(plot) plot } addSegment = function (model) { m = nrow(model$dfw) p = model$plots[[model$step + 1]] model$plots[[model$step + 2]] = p + geom_segment(aes(x=model$dfw[1,1], y=model$dfw[1,2], xend=model$dfw[m,1], yend=model$dfw[m,2], colour=model$color)) eq = calcRect(model$dfw) model$equs[[model$step + 2]] = eq } calcRect = function(df) { x1 = df[1,1] y1 = df[1,2] x2 = df[nrow(df),1] y2 = df[nrow(df),2] xr = x2 - x1 yr = y2 - y1 B = ((y1 * xr) - (x1 * yr)) / xr A = yr / xr list(a=A,b=B) } calcSlope = function(model) { dfw = model$df dfw$y = dfw$y - model$beta size = nrow(dfw) dfw$x = dfw$x / size dfw$y = dfw$y / size parms = calcRect(dfw) atan(parms$a) * 180 / pi } rotate = function() { cang = cos(alpha * pi / 180) * 180 / pi sang = sin(alpha * pi / 180) * 180 / pi df$x1 = (df$x * cang) + (df$y * sang) df$y1 = (df$x * sang * -1) + (df$y * cang) # grados * pi / 180 } # x'=x\cos \theta +y\sin \theta # y ′ = − x sin ⁡ θ + y cos ⁡
431ed021c69925bc4d25a3afe415b08248d55b41
aee78785ad6670a0fab9a6ae0b43710076f4f67f
/R/cra3.R
a4e96c57e43ceca019fbddf65cf874d99c421658
[]
no_license
cran/PowerUpR
86f9b9210dbfa5645b5780c448c75d0e339e7749
ac7e9ab6b727f9536a0245441642b17bdbb3f54e
refs/heads/master
2021-11-10T04:28:44.972166
2021-10-25T15:10:02
2021-10-25T15:10:02
72,525,187
11
7
null
2018-04-25T18:56:54
2016-11-01T10:12:25
R
UTF-8
R
false
false
40,291
r
cra3.R
mdes.cra3r3 <- function(power=.80, alpha=.05, two.tailed=TRUE, rho2, rho3, p=.50, g3=0, r21=0, r22=0, r23=0, n, J, K){ user.parms <- as.list(match.call()) .error.handler(user.parms) df <- K - g3 - 2 SSE <- sqrt(rho3*(1-r23)/(p*(1-p)*K) + rho2*(1-r22)/(p*(1-p)*J*K) + (1-rho3-rho2)*(1-r21)/(p*(1-p)*J*K*n)) mdes <- .mdes.fun(power = power, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed) .summ.mdes(effect = "main", power = power, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed, mdes = mdes) mdes.out <- list(fun = "mdes.cra3r3", parms = list(power=power, alpha=alpha, two.tailed=two.tailed, rho2=rho2, rho3=rho3, g3=g3, r21=r21, r22=r22, r23=r23, p=p, n=n, J=J, K=K), df = df, ncp = mdes[1]/SSE, mdes = mdes) class(mdes.out) <- c("main", "mdes") return(invisible(mdes.out)) } # example # mdes.cra3r3(rho3=.06, rho2=.17, n=15, J=3, K=60) mdes.cra3 <- mdes.cra3r3 mdesd.mod331 <- mdes.mod331 <- function(power=.80, alpha=.05, two.tailed=TRUE, rho2, rho3, omegam2, omegam3, r21=0, r2m3=0, p=.50, q=NULL, n, J, K){ user.parms <- as.list(match.call()) .error.handler(user.parms) if(omegam2 == 0) { df <- n*J*K - J*K - K - 2 if(omegam3 != 0 || r2m3 != 1) { omegam3 <- 0 r2m3 <- 1 message("Arguments 'omegam3' and/or 'r2m3' are ignored") } cat("\nModerator effect: Non-randomly varying (level 2 and 3) \nModerator type:", ifelse(is.null(q), "Continuous\n", "Binary\n")) } else if(omegam3 == 0 || r2m3 == 1) { df <- J*K - K - 2 cat("\nModerator effect: Non-randomly varying (level 3) \nModerator type:", ifelse(is.null(q), "Continuous\n", "Binary\n")) } else { df <- K - 2 cat("\nModerator effect: Randomly varying \nModerator type:", ifelse(is.null(q), "Continuous\n", "Binary\n")) } SSE <- ifelse(is.null(q), sqrt(rho3*omegam3*(1-r2m3)/(p*(1-p)*K) + rho2*omegam2/(p*(1-p)*K*J) + (1-rho2-rho3)*(1-r21)/(p*(1-p)*K*J*n)), # continuous mod sqrt(rho3*omegam3*(1-r2m3)/(p*(1-p)*K) + rho2*omegam2/(p*(1-p)*K*J) + (1-rho2-rho3)*(1-r21)/(p*(1-p)*q*(1-q)*K*J*n)) # binary mod ) mdes <- .mdes.fun(power = power, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed) .summ.mdes(effect = "mod", power = power, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed, mdes = mdes) mdes.out <- list(fun = "mdes.mod331", parms = list(power=power, alpha=alpha, two.tailed=two.tailed, rho2=rho2, rho3=rho3, omegam2=omegam2, omegam3=omegam3, r21=r21, r2m3=r2m3, p=p, q=q, n=n, J=J, K=K), df = df, ncp = mdes[1]/SSE, mdes = mdes) class(mdes.out) <- c("mod331", "mdes") return(invisible(mdes.out)) } # examples # mdes.mod331(rho3=.05, rho2=.12, omegam2=.08, omegam3=.07, p=.4, q=.7, r21=.20, r2m3=0, n=20, J=4, K=60) # mdes.mod331(rho3=.05, rho2=.12, omegam2=.08, omegam3=.07, p=.4, r21=.20, r2m3=0, n=20, J=4, K=60) # mdes.mod331(rho3=.05, rho2=.12, omegam2=0.1, omegam3=0, p=.4, q=.7, r21=.20, r2m3=0, n=20, J=4, K=60) # mdes.mod331(rho3=.05, rho2=.12, omegam2=0, omegam3=0, p=.4, r21=.20, r2m3=1, n=20, J=4, K=60) mdesd.mod332 <- mdes.mod332 <- function(power=.80, alpha=.05, two.tailed=TRUE, rho2, rho3, omegam3, r21=0, r22=0, r2m3=0, p=.50, q=NULL, n, J, K){ user.parms <- as.list(match.call()) .error.handler(user.parms) if(omegam3 == 0 || r2m3 == 1) { df <- J*K - K - 2 cat("\nModerator effect: Non-randomly varying \nModerator type:", ifelse(is.null(q), "Continuous\n", "Binary\n")) } else { df <- K - 2 cat("\nModerator effect: Randomly varying \nModerator type:", ifelse(is.null(q), "Continuous\n", "Binary\n")) } SSE <- ifelse(is.null(q), sqrt(rho3*omegam3*(1-r2m3)/(p*(1-p)*K) + rho2*(1-r22)/(p*(1-p)*K*J) + (1-rho2-rho3)*(1-r21)/(p*(1-p)*K*J*n)), # continuous mod sqrt(rho3*omegam3*(1-r2m3)/(p*(1-p)*K) + rho2*(1-r22)/(p*(1-p)*q*(1-q)*K*J) + (1-rho2-rho3)*(1-r21)/(p*(1-p)*q*(1-q)*K*J*n)) # binary mod ) mdes <- .mdes.fun(power = power, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed) .summ.mdes(effect = "mod", power = power, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed, mdes = mdes) mdes.out <- list(fun = "mdes.mod332", parms = list(power=power, alpha=alpha, two.tailed=two.tailed, rho2=rho2, rho3=rho3, omegam3=omegam3, r21=r21, r22=r22, r2m3=r2m3, p=p, q=q, n=n, J=J, K=K), df = df, ncp = mdes[1]/SSE, mdes = mdes) class(mdes.out) <- c("mod332", "mdes") return(invisible(mdes.out)) } # examples # mdes.mod332(rho3=.1, rho2=.1, omegam3=.05, q=.5, r21=.30, r22=.4, r2m3=0, n=20, J=4, K=60) # mdes.mod332(rho3=.1, rho2=.1, omegam3=.05, r21=.30, r22=.4, r2m3=0, n=20, J=4, K=60) # mdes.mod332(rho3=.1, rho2=.1, omegam3=0, q=.5, r21=.30, r22=.4, r2m3=0, n=20, J=4, K=60) # mdes.mod332(rho3=.1, rho2=.1, omegam3=0, r21=.30, r22=.4, r2m3=0, n=20, J=4, K=60) mdesd.mod333 <- mdes.mod333 <- function(power=.80, alpha=.05, two.tailed=TRUE, rho2, rho3, r21=0, r22=0, r23=0, p=.50, q=NULL, n, J, K){ user.parms <- as.list(match.call()) .error.handler(user.parms) cat(ifelse(is.null(q), "\nModerator type: Continuous\n", "\nModerator type: Binary\n")) df <- K - 5 SSE <- ifelse(is.null(q), sqrt(rho3*(1-r23)/(p*(1-p)*(K-5)) + rho2*(1-r22)/(p*(1-p)*J*(K-5)) + (1-rho3-rho2)*(1-r21)/(p*(1-p)*J*(K-5)*n)), # continuous mod sqrt(rho3*(1-r23)/(p*(1-p)*q*(1-q)*(K-5)) + rho2*(1-r22)/(p*(1-p)*q*(1-q)*J*(K-5)) + (1-rho3-rho2)*(1-r21)/(p*(1-p)*q*(1-q)*J*(K-5)*n)) # binary mod ) mdes <- .mdes.fun(power = power, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed) .summ.mdes(effect = "mod", power = power, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed, mdes = mdes) mdes.out <- list(fun = "mdes.mod333", parms = list(power=power, alpha=alpha, two.tailed=two.tailed, rho2=rho2, rho3=rho3, r21=r21, r22=r22, r23=r23, p=p, q=q, n=n, J=J, K=K), df = df, ncp = mdes[1]/SSE, mdes = mdes) class(mdes.out) <- c("mod333", "mdes") return(invisible(mdes.out)) } # examples # mdes.mod333(rho3=.1, rho2=.1, q=.5, r21=.3, r22=.4, r23=.5, n=20, J=4, K=60) # mdes.mod333(rho3=.1, rho2=.1, r21=.3, r22=.4, r23=.5, n=20, J=4, K=60) power.cra3r3 <- function(es=.25, alpha=.05, two.tailed=TRUE, rho2, rho3, g3=0, r21=0, r22=0, r23=0, p=.50, n, J, K){ user.parms <- as.list(match.call()) .error.handler(user.parms) df <- K - g3 - 2 SSE <- sqrt(rho3*(1-r23)/(p*(1-p)*K) + rho2*(1-r22)/(p*(1-p)*J*K) + (1-rho3-rho2)*(1-r21)/(p*(1-p)*J*K*n)) power <- .power.fun(es = es, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed) .summ.power(power = power, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed, es = es) power.out <- list(fun = "power.cra3r3", parms = list(es=es, alpha=alpha, two.tailed=two.tailed, rho2=rho2, rho3=rho3, g3=g3, r21=r21, r22=r22, r23=r23, p=p, n=n, J=J, K=K), df = df, ncp = es/SSE, power = power) class(power.out) <- c("main", "power") return(invisible(power.out)) } # example # power.cra3r3(es=.269, rho3=.06, rho2=.17, n=15, J=3, K=60) power.cra3 <- power.cra3r3 power.mod331 <- function(es=.25, alpha=.05, two.tailed=TRUE, rho2, rho3, omegam2, omegam3, r21=0, r2m3=0, p=.50, q=NULL, n, J, K){ user.parms <- as.list(match.call()) .error.handler(user.parms) if(omegam2 == 0) { df <- n*J*K - J*K - K - 2 if(omegam3 != 0 || r2m3 != 1) { omegam3 <- 0 r2m3 <- 1 message("Arguments 'omegam3' and/or 'r2m3' are ignored") } cat("\nModerator effect: Non-randomly varying (level 2 and 3) \nModerator type:", ifelse(is.null(q), "Continuous\n", "Binary\n")) } else if(omegam3 == 0 || r2m3 == 1) { df <- J*K - K - 2 cat("\nModerator effect: Non-randomly varying (level 3) \nModerator type:", ifelse(is.null(q), "Continuous\n", "Binary\n")) } else { df <- K - 2 cat("\nModerator effect: Randomly varying \nModerator type:", ifelse(is.null(q), "Continuous\n", "Binary\n")) } SSE <- ifelse(is.null(q), sqrt(rho3*omegam3*(1-r2m3)/(p*(1-p)*K) + rho2*omegam2/(p*(1-p)*K*J) + (1-rho2-rho3)*(1-r21)/(p*(1-p)*K*J*n)), # continuous mod sqrt(rho3*omegam3*(1-r2m3)/(p*(1-p)*K) + rho2*omegam2/(p*(1-p)*K*J) + (1-rho2-rho3)*(1-r21)/(p*(1-p)*q*(1-q)*K*J*n)) # binary mod ) power <- .power.fun(es = es, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed) .summ.power(power = power, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed, es = es) power.out <- list(fun = "power.mod331", parms = list(es=es, alpha=alpha, two.tailed=two.tailed, rho2=rho2, rho3=rho3, omegam2=omegam2, omegam3=omegam3, r21=r21, r2m3=r2m3, p=p, q=q, n=n, J=J, K=K), df = df, ncp = es/SSE, power = power) class(power.out) <- c("mod331", "power") return(invisible(power.out)) } # examples # power.mod331(es=.16, rho3=.05, rho2=.12, omegam2=.08, omegam3=.07, p=.4, q=.7, r21=.20, r2m3=0, n=20, J=4, K=60) # power.mod331(es=.09, rho3=.05, rho2=.12, omegam2=.08, omegam3=.07, p=.4, r21=.20, r2m3=0, n=20, J=4, K=60) # power.mod331(es=.16, rho3=.05, rho2=.12, omegam2=0, omegam3=.07, p=.4, q=.7, r21=.20, r2m3=0, n=20, J=4, K=60) # power.mod331(es=.09, rho3=.05, rho2=.12, omegam2=0, omegam3=.07, p=.4, r21=.20, r2m3=0, n=20, J=4, K=60) # power.mod331(es=.16, rho3=.05, rho2=.12, omegam2=.08, omegam3=0, p=.4, q=.7, r21=.20, r2m3=0, n=20, J=4, K=60) # power.mod331(es=.09, rho3=.05, rho2=.12, omegam2=.08, omegam3=0, p=.4, r21=.20, r2m3=0, n=20, J=4, K=60) power.mod332 <- function(es=.25, alpha=.05, two.tailed=TRUE, rho2, rho3, omegam3, r21=0, r22=0, r2m3=0, p=.50, q=NULL, n, J, K){ user.parms <- as.list(match.call()) .error.handler(user.parms) if(omegam3 == 0 || r2m3 == 1) { df <- J*K - K - 2 cat("\nModerator effect: Non-randomly varying \nModerator type:", ifelse(is.null(q), "Continuous\n", "Binary\n")) } else { df <- K - 2 cat("\nModerator effect: Randomly varying \nModerator type:", ifelse(is.null(q), "Continuous\n", "Binary\n")) } SSE <- ifelse(is.null(q), sqrt(rho3*omegam3*(1-r2m3)/(p*(1-p)*K) + rho2*(1-r22)/(p*(1-p)*K*J) + (1-rho2-rho3)*(1-r21)/(p*(1-p)*K*J*n)), # continuous mod sqrt(rho3*omegam3*(1-r2m3)/(p*(1-p)*K) + rho2*(1-r22)/(p*(1-p)*q*(1-q)*K*J) + (1-rho2-rho3)*(1-r21)/(p*(1-p)*q*(1-q)*K*J*n)) # binary mod ) power <- .power.fun(es = es, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed) .summ.power(power = power, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed, es = es) power.out <- list(fun = "power.mod332", parms = list(es=es, alpha=alpha, two.tailed=two.tailed, rho2=rho2, rho3=rho3, omegam3=omegam3, r21=r21, r22=r22, r2m3=r2m3, p=p, q=q, n=n, J=J, K=K), df = df, ncp = es/SSE, power = power) class(power.out) <- c("mod332", "power") return(invisible(power.out)) } # examples # power.mod332(es=.22, rho3=.1, rho2=.1, omegam3=.05, q=.5, r21=.30, r22=.4, r2m3=0, n=20, J=4, K=60) # power.mod332(es=.11, rho3=.1, rho2=.1, omegam3=.05, r21=.30, r22=.4, r2m3=0, n=20, J=4, K=60) # power.mod332(es=.22, rho3=.1, rho2=.1, omegam3=0, q=.5, r21=.30, r22=.4, r2m3=0, n=20, J=4, K=60) # power.mod332(es=.11, rho3=.1, rho2=.1, omegam3=0, r21=.30, r22=.4, r2m3=0, n=20, J=4, K=60) power.mod333 <- function(es=.25, alpha=.05, two.tailed=TRUE, rho2, rho3, r21=0, r22=0, r23=0, p=.50, q=NULL, n, J, K){ user.parms <- as.list(match.call()) .error.handler(user.parms) cat(ifelse(is.null(q), "\nModerator type: Continuous\n", "\nModerator type: Binary\n")) df <- K-5 SSE <- ifelse(is.null(q), sqrt(rho3*(1-r23)/(p*(1-p)*(K-5)) + rho2*(1-r22)/(p*(1-p)*J*(K-5)) + (1-rho3-rho2)*(1-r21)/(p*(1-p)*J*(K-5)*n)), # continuous mod sqrt(rho3*(1-r23)/(p*(1-p)*q*(1-q)*(K-5)) + rho2*(1-r22)/(p*(1-p)*q*(1-q)*J*(K-5)) + (1-rho3-rho2)*(1-r21)/(p*(1-p)*q*(1-q)*J*(K-5)*n)) # binary mod ) power <- .power.fun(es = es, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed) .summ.power(power = power, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed, es = es) power.out <- list(fun = "power.mod333", parms = list(es=es, alpha=alpha, two.tailed=two.tailed, rho2=rho2, rho3=rho3, r21=r21, r22=r22, r23=r23, p=p, q=q, n=n, J=J, K=K), df = df, ncp = es/SSE, power = power) class(power.out) <- c("mod333", "power") return(invisible(power.out)) } # examples # power.mod333(es=.30, rho3=.1, rho2=.1, q=.5, r21=.3, r22=.4, r23=.5, n=20, J=4, K=60) # power.mod333(es=.15, rho3=.1, rho2=.1, r21=.3, r22=.4, r23=.5, n=20, J=4, K=60) power.med331 <- function(esa, esB, two.tailed = TRUE, alpha = .05, mc = TRUE, nsims = 1000, ndraws = 1000, rho2, rho3, gm3 = 4, r2m3 = 0, r21 = 0, r22 = 0, g3 = 5, r23 = 0, p = .50, n, J, K) { user.parms <- as.list(match.call()) .error.handler(user.parms) # standard errors for 3-3-1 mediation .se.a331 <- function(r2m3, gm3, p, K) { sig2m <- 1 var.a331 <- sig2m * (1 - r2m3) / (p * (1 - p) * (K - gm3 - 1)) if(is.nan(var.a331) | var.a331 <= 0) { stop("Design is not feasible", call. = FALSE) } return(invisible(sqrt(var.a331))) } .se.B331 <- function(rho2, rho3, r2m3, r21, r22, g3, r23, n, J, K) { sig2m <- 1 var.B331 <- (rho3 * (1 - r23) + rho2 * (1 - r22) / J + (1 - rho3 - rho2) * (1 - r21) / (n * J)) / ((K - g3 - 1) * sig2m * (1 - r2m3)) if(is.nan(var.B331) | var.B331 <= 0) { stop("Design is not feasible", call. = FALSE) } return(invisible(sqrt(var.B331))) } dfa <- K - gm3 - 1 dfB <- K - g3 - 1 df <- rbind(dfa, dfB) colnames(df) <- "df" rownames(df) <- c("a", "B") sea331 <- .se.a331(r2m3 = r2m3, gm3 = gm3, p = p, K = K) seB331 <- .se.B331(rho2 = rho2, rho3 = rho3, r2m3 = r2m3, r21 = r21, r22 = r22, g3 = g3, r23 = r23, n = n, J = J, K = K) ncpa <- esa/sea331 ncpB <- esB/seB331 ncp <- rbind(ncpa, ncpB) colnames(ncp) <- "ncp" rownames(ncp) <- c("a", "B") powera <- .power.fun(es = esa, alpha = alpha, sse = sea331, two.tailed = two.tailed, df = dfa) powerB <- .power.fun(es = esB, alpha = alpha, sse = seB331, two.tailed = two.tailed, df = dfB) power.sobel.aB <- .power.sobel(x = esa, y = esB, sex = sea331, sey = seB331, alpha = alpha, two.tailed = two.tailed) power.joint.aB <- .power.jt(x = esa, y = esB, sex = sea331, sey = seB331, alpha = alpha, dfx = dfa, dfy = dfB, two.tailed = two.tailed) power.mc.aB <- ifelse(mc, .power.mc(nsims = nsims, ndraws = ndraws, x = esa, y = esB, sex = sea331, sey = seB331, alpha = alpha, two.tailed = two.tailed), NA) power <- rbind( c(round(powera, 3), NA, NA, NA), c(round(powerB, 3), NA, NA, NA), c(NA, round(power.sobel.aB, 3), round(power.joint.aB, 3), round(power.mc.aB, 3)) ) colnames(power) <- c("t", "sobel", "joint", "mc") rownames(power) <- c("a", "B", "aB") power.out <- list(fun = "power.med331", parms = list(esa = esa, esB = esB, two.tailed = two.tailed, alpha = alpha, mc = mc, nsims = nsims, ndraws = ndraws, rho2 = rho2, rho3 = rho3, gm3 = gm3, r2m3 = r2m3, r21 = r21, r22 = r22, g3 = g3, r23 = r23, p = p, n = n, J = J, K = K), df = df, ncp = ncp, power = round(power, 3)) cat("Statistical power: \n") cat("------------------------------------ \n") print(power) cat("------------------------------------ \n") cat("Degrees of freedom for path a:", dfa, "\nDegrees of freedom for path B:", dfB, "\nStandardized standard error for path a:", round(sea331, 3), "\nStandardized standard error for path B:", round(seB331, 3), "\nType I error rate:", alpha, "\nTwo-tailed test:", two.tailed, "\n") class(power.out) <- c("power", "med331") return(invisible(power.out)) } # example # power.med331(esa= .5, esB = .3, rho2 = .15, rho3 = .15, # r21 = .2, r22 = .2, g3 = 4, # n = 20, J = 4, K = 80, p = .5, mc = TRUE) power.med321 <- function(esa, esB, two.tailed = TRUE, alpha = .05, mc = TRUE, nsims = 1000, ndraws = 1000, rhom3, rho2, rho3, r2m2 = 0, gm3 = 4, r2m3 = 0, r21 = 0, r22 = 0, g3 = 5, r23 = 0, p = .50, n, J, K) { user.parms <- as.list(match.call()) .error.handler(user.parms) # standard errors for 3-2-1 mediation .se.a321 <- function(rhom3, r2m2, r2m3, gm3, p, J, K) { var.a321 <- (rhom3 * (1 - r2m3) + (1 - rhom3) * (1 - r2m2) / J) / (p * (1 - p) * (K - gm3 - 1)) if(is.nan(var.a321) | var.a321 <= 0) { stop("Design is not feasible", call. = FALSE) } return(invisible(sqrt(var.a321))) } .se.B321 <- function(rhom3, rho2, rho3, r2m2, r2m3, r21, r22, g3, r23, n, J, K) { var.B321 <- (rho3 * (1 - r23) + rho2 * (1 - r22) / J + (1 - rho3 - rho2) * (1 - r21) / (n * J)) / ((K - g3 - 1) * (rhom3 * (1 - r2m3) + (1 - rhom3) * (1 - r2m2) / J)) if(is.nan(var.B321) | var.B321 <= 0) { stop("Design is not feasible", call. = FALSE) } return(invisible(sqrt(var.B321))) } dfa <- K - gm3 - 1 dfB <- K - g3 - 1 df <- rbind(dfa, dfB) colnames(df) <- "df" rownames(df) <- c("a", "B") sea321 <- .se.a321(rhom3 = rhom3, r2m2 = r2m2, gm3 = gm3, r2m3 = r2m3, p = p, J = J, K = K) seB321 <- .se.B321(rhom3 = rhom3, rho2 = rho2, rho3 = rho3, r2m2 = r2m2, g3 = g3, r2m3 = r2m3, r21 = r21, r22 = r22, r23 = r23, n = n, J = J, K = K) ncpa <- esa/sea321 ncpB <- esB/seB321 ncp <- rbind(ncpa, ncpB) colnames(ncp) <- "ncp" rownames(ncp) <- c("a", "B") powera <- .power.fun(es = esa, alpha = alpha, sse = sea321, two.tailed = two.tailed, df = dfa) powerB <- .power.fun(es = esB, alpha = alpha, sse = seB321, two.tailed = two.tailed, df = dfB) power.sobel.aB <- .power.sobel(x = esa, y = esB, sex = sea321, sey = seB321, alpha = alpha, two.tailed = two.tailed) power.joint.aB <- .power.jt(x = esa, y = esB, sex = sea321, sey = seB321, alpha = alpha, dfx = dfa, dfy = dfB, two.tailed = two.tailed) power.mc.aB <- ifelse(mc, .power.mc(nsims = nsims, ndraws = ndraws, x = esa, y =esB, sex = sea321, sey = seB321, alpha = alpha, two.tailed = two.tailed), NA) power <- rbind( c(round(powera, 3), NA, NA, NA), c(round(powerB, 3), NA, NA, NA), c(NA, round(power.sobel.aB, 3), round(power.joint.aB, 3), round(power.mc.aB, 3)) ) colnames(power) <- c("t", "sobel", "joint", "mc") rownames(power) <- c("a", "B", "aB") power.out <- list(fun = "power.med321", parms = list(esa = esa, esB = esB, two.tailed = two.tailed, alpha = alpha, mc = mc, nsims = nsims, ndraws = ndraws, rhom3 = rhom3, rho2 = rho2, rho3 = rho3, r2m2 = r2m2, gm3 = gm3, r2m3 = r2m3, r21 = r21, r22 = r22, g3 = g3, r23 = r23, p = p, n = n, J = J, K = K), df = df, ncp = ncp, power = round(power, 3)) cat("Statistical power: \n") cat("------------------------------------ \n") print(power) cat("------------------------------------ \n") cat("Degrees of freedom for path a:", dfa, "\nDegrees of freedom for path B:", dfB, "\nStandardized standard error for path a:", round(sea321, 3), "\nStandardized standard error for path B:", round(seB321, 3), "\nType I error rate:", alpha, "\nTwo-tailed test:", two.tailed, "\n") class(power.out) <- c("power", "med321") return(invisible(power.out)) } # example # power.med321(esa= .49, esB = .30, rhom3 = 0.26, rho2 = .15, rho3 = .20, # r2m2 = .07, r2m3 = .17, r21 = .02, r22 = .41, r23 = .38, # p = .50, n = 20, J = 4, K = 30) power.med311 <- function(esa, esB, two.tailed = TRUE, alpha = .05, mc = TRUE, nsims = 1000, ndraws = 1000, rhom2, rhom3, rho2, rho3, r2m1 = 0, r2m2 = 0, gm3 = 4, r2m3 = 0, r21 = 0, r22 = 0, g3 = 5, r23 = 0, p = .50, n, J, K) { user.parms <- as.list(match.call()) .error.handler(user.parms) # standard errors for 3-1-1 mediation .se.a311 <- function(rhom2, rhom3, r2m1, gm3, r2m2, r2m3, p, n, J, K) { # r2m3z, var.a311 <- (rhom3 * (1 - r2m3) + rhom2 * (1 - r2m2) / J + (1 - rhom3 - rhom2) * (1 - r2m1) / (n*J)) / (p * (1 - p) * (K - gm3 - 1)) if(is.nan(var.a311) | var.a311 <= 0) { stop("Design is not feasible", call. = FALSE) } return(invisible(sqrt(var.a311))) } .se.B311 <- function(rho2, rho3, rhom2, rhom3, r2m1, r2m2, r2m3, r21, r22, g3, r23, n, J, K) { var.B311 <- (rho3 * (1 - r23) + rho2 * (1 - r22) / J + (1 - rho3 - rho2) * (1 - r21) / (n * J)) / ((K - g3 - 1) * (rhom3 * (1 - r2m3) + rhom2 * (1 - r2m2) / J + (1 - rhom3 - rhom2) * (1 - r2m3) / (n*J))) if(is.nan(var.B311) | var.B311 <= 0) { stop("Design is not feasible", call. = FALSE) } return(invisible(sqrt(var.B311))) } dfa <- K - gm3 - 1 dfB <- K - g3 - 1 df <- rbind(dfa, dfB) colnames(df) <- "df" rownames(df) <- c("a", "B") sea311 <- .se.a311(rhom2 = rhom2, rhom3 = rhom3, r2m1 = r2m1, r2m2 = r2m2, r2m3 = r2m3, gm3 = gm3, p = p, n = n, J = J, K = K) seB311 <- .se.B311(rho2 = rho2, rho3 = rho3, rhom2 = rhom2, rhom3 = rhom3, r2m1 = r2m1, r2m2 = r2m2, r2m3 = r2m3, r21 = r21, r22 = r22, g3 = g3, r23 = r23, n = n, J = J, K = K) ncpa <- esa/sea311 ncpB <- esB/seB311 ncp <- rbind(ncpa, ncpB) colnames(ncp) <- "ncp" rownames(ncp) <- c("a", "B") powera <- .power.fun(es = esa, alpha = alpha, sse = sea311, two.tailed = two.tailed, df = dfa) powerB <- .power.fun(es = esB, alpha = alpha, sse = seB311, two.tailed = two.tailed, df = dfB) power.sobel.aB <- .power.sobel(x = esa, y = esB, sex = sea311, sey = seB311, alpha = alpha, two.tailed = two.tailed) power.joint.aB <- .power.jt(x = esa, y = esB, sex = sea311, sey = seB311, alpha = alpha, dfx = dfa, dfy = dfB, two.tailed = two.tailed) power.mc.aB <- ifelse(mc, .power.mc(nsims = nsims, ndraws = ndraws, x = esa, y = esB, sex = sea311, sey = seB311, alpha = alpha, two.tailed = two.tailed), NA) power <- rbind( c(round(powera, 3), NA, NA, NA), c(round(powerB, 3), NA, NA, NA), c(NA, round(power.sobel.aB, 3), round(power.joint.aB, 3), round(power.mc.aB, 3)) ) colnames(power) <- c("t", "sobel", "joint", "mc") rownames(power) <- c("a", "B", "aB") power.out <- list(fun = "power.med311", parms = list(esa = esa, esB = esB, two.tailed = two.tailed, alpha = alpha, mc = mc, nsims = nsims, ndraws = ndraws, rhom2 = rhom2, rhom3 = rhom3, rho2 = rho2, rho3 = rho3, r2m1 = r2m1, r2m2 = r2m2, r2m3 = r2m3, gm3 = gm3, r21 = r21, r22 = r22, r23 = r23, g3 = g3, p = p, n = n, J = J, K = K), df = df, ncp = ncp, power = round(power, 3)) cat("Statistical power: \n") cat("------------------------------------ \n") print(power) cat("------------------------------------ \n") cat("Degrees of freedom for path a:", dfa, "\nDegrees of freedom for path B:", dfB, "\nStandardized standard error for path a:", round(sea311, 3), "\nStandardized standard error for path B:", round(seB311, 3), "\nType I error rate:", alpha, "\nTwo-tailed test:", two.tailed, "\n") class(power.out) <- c("power", "med311") return(invisible(power.out)) } # example # power.med311(esa= .49 , esB = .30, two.tailed = TRUE, alpha = .05, # mc = TRUE, nsims = 1000, ndraws = 1000, # rhom2 = .05, rhom3 = .26, rho2 = .15, rho3 = .20, # r2m1 = .10, r2m2 = .07, r2m3 = .17, r21 = .02, r22 = .41, r23 = .38, # p = .50, n = 20, J = 4, K = 30) mrss.cra3r3 <- function(es=.25, power=.80, alpha=.05, two.tailed=TRUE, n, J, K0=10, tol=.10, rho2, rho3, p=.50, g3=0, r21=0, r22=0, r23=0){ user.parms <- as.list(match.call()) .error.handler(user.parms) i <- 0 conv <- FALSE while(i<=100 & conv==FALSE){ df <- K0-g3-2 if(df<= 0 | is.infinite(df)){break} T1 <- ifelse(two.tailed==TRUE,abs(qt(alpha/2,df)),abs(qt(alpha,df))) T2 <- abs(qt(power,df)) M <- ifelse(power>=.5,T1+T2,T1-T2) K1 <- (M/es)^2 * (rho3*(1-r23)/(p*(1-p)) + rho2*(1-r22)/(p*(1-p)*J) + (1-rho3-rho2)*(1-r21)/(p*(1-p)*J*n)) K0 <- (K1+K0)/2 i <- i+1 } K <- ifelse(df>0,round(K0),NA) mrss.out <- list(fun = "mrss.cra3r3", parms = list(es=es, power=power, alpha=alpha, two.tailed=two.tailed, n=n, J=J, K0=K0, tol=tol, rho2=rho2, rho3=rho3, p=p, r21=r21, r22=r22, r23=r23, g3=g3), df = df, ncp = M, K = K) class(mrss.out) <- c("main", "mrss") cat("K =", K, "\n") return(invisible(mrss.out)) } # example # mrss.cra3r3(rho3=.06, rho2=.17, n=15, J=3) mrss.cra3 <- mrss.cra3r3 mrss.mod331 <- function(es=.25, power=.80, alpha=.05, two.tailed=TRUE, rho2, rho3, omegam2, omegam3, r21=0, r2m3=0, p=.50, q=NULL, n, J, K0=10, tol=.10){ user.parms <- as.list(match.call()) .error.handler(user.parms) i <- 0 conv <- FALSE while(i<=100 & conv==FALSE){ if(omegam2 == 0) { df <- n*J*K0 - J*K0 - K0 - 2 if(omegam3 != 0 || r2m3 != 1) { omegam3 <- 0 r2m3 <- 1 } } else if(omegam3 == 0 || r2m3 == 1) { df <- J*K0 - K0 - 2 } else { df <- K0 - 2 } if(df<= 0 | is.infinite(df)){break} T1 <- ifelse(two.tailed==TRUE,abs(qt(alpha/2,df)),abs(qt(alpha,df))) T2 <- abs(qt(power,df)) M <- ifelse(power>=.5,T1+T2,T1-T2) K1 <- ifelse(is.null(q), (M/es)^2 * (rho3*omegam3*(1-r2m3)/(p*(1-p)) + rho2*omegam2/(p*(1-p)*J) + (1-rho2-rho3)*(1-r21)/(p*(1-p)*J*n)), # continuous mod (M/es)^2 * (rho3*omegam3*(1-r2m3)/(p*(1-p)) + rho2*omegam2/(p*(1-p)*J) + (1-rho2-rho3)*(1-r21)/(p*(1-p)*q*(1-q)*J*n)) # binary mod ) K0 <- (K1+K0)/2 i <- i+1 } K <- ifelse(df>0,round(K0),NA) mrss.out <- list(fun = "mrss.mod331", parms = list(es=es, power=power, alpha=alpha, two.tailed=two.tailed, rho2=rho2, rho3=rho3, omegam2=omegam2, omegam3=omegam3, r21=r21, r2m3=r2m3, p=p, q=q, n=n, J=J, K0=K0, tol=tol), df = df, ncp = M, K = K) if(omegam2 == 0) { if(omegam3 != 0 || r2m3 != 1) { message("Arguments 'omegam3' and/or 'r2m3' are ignored") } cat("\nModerator effect: Non-randomly varying (level 2 and 3) \nModerator type:", ifelse(is.null(q), "Continuous\n", "Binary\n"), "\nK =", K) } else if(omegam3 == 0 || r2m3 == 1) { cat("\nModerator effect: Non-randomly varying (level 3) \nModerator type:", ifelse(is.null(q), "Continuous\n", "Binary\n"), "\nK =", K) } else { cat("\nModerator effect: Randomly varying \nModerator type:", ifelse(is.null(q), "Continuous\n", "Binary\n"), "\nK =", K) } class(mrss.out) <- c("mod331", "mrss") return(invisible(mrss.out)) } # examples # mrss.mod331(es=.16, rho3=.05, rho2=.12, omegam2=.08, omegam3=.07, p=.4, q=.7, r21=.20, r2m3=0, n=20, J=4) # mrss.mod331(es=.09, rho3=.05, rho2=.12, omegam2=.08, omegam3=.07, p=.4, r21=.20, r2m3=0, n=20, J=4) # mrss.mod331(es=.16, rho3=.05, rho2=.12, omegam2=0, omegam3=.07, p=.4, q=.7, r21=.20, r2m3=0, n=20, J=4) # mrss.mod331(es=.09, rho3=.05, rho2=.12, omegam2=0, omegam3=.07, p=.4, r21=.20, r2m3=0, n=20, J=4) # mrss.mod331(es=.16, rho3=.05, rho2=.12, omegam2=.08, omegam3=0, p=.4, q=.7, r21=.20, r2m3=0, n=20, J=4) # mrss.mod331(es=.09, rho3=.05, rho2=.12, omegam2=.08, omegam3=0, p=.4, r21=.20, r2m3=0, n=20, J=4) mrss.mod332 <- function(es=.25, power=.80, alpha=.05, two.tailed=TRUE, rho2, rho3, omegam3, r21=0, r22=0, r2m3=0, p=.50, q=NULL, n, J, K0=10, tol=.10){ user.parms <- as.list(match.call()) .error.handler(user.parms) i <- 0 conv <- FALSE while(i<=100 & conv==FALSE){ if(omegam3 == 0 || r2m3 == 1) { df <- J*K0 - K0 - 2 } else { df <- K0 - 2 } if(df<= 0 | is.infinite(df)){break} T1 <- ifelse(two.tailed==TRUE,abs(qt(alpha/2,df)),abs(qt(alpha,df))) T2 <- abs(qt(power,df)) M <- ifelse(power>=.5,T1+T2,T1-T2) K1 <- ifelse(is.null(q), (M/es)^2 * (rho3*omegam3*(1-r2m3)/(p*(1-p)) + rho2*(1-r22)/(p*(1-p)*J) + (1-rho2-rho3)*(1-r21)/(p*(1-p)*J*n)), # continuous mod (M/es)^2 * (rho3*omegam3*(1-r2m3)/(p*(1-p)) + rho2*(1-r22)/(p*(1-p)*q*(1-q)*J) + (1-rho2-rho3)*(1-r21)/(p*(1-p)*q*(1-q)*J*n)) # binary mod ) K0 <- (K1+K0)/2 i <- i+1 } K <- ifelse(df>0,round(K0),NA) mrss.out <- list(fun = "mrss.mod332", parms = list(es=es, power=power, alpha=alpha, two.tailed=two.tailed, rho2=rho2, rho3=rho3, omegam3=omegam3, r21=r21, r22=r22, r2m3=r2m3, p=p, q=q, n=n, J=J, K0=K0, tol=tol), df = df, ncp = M, K = K) if(omegam3 == 0 || r2m3 == 1) { cat("\nModerator effect: Non-randomly varying \nModerator type:", ifelse(is.null(q), "Continuous\n", "Binary\n"), "\nK =", K) } else { cat("\nModerator effect: Randomly varying \nModerator type:", ifelse(is.null(q), "Continuous\n", "Binary\n"), "\nK =", K) } class(mrss.out) <- c("mod332", "mrss") return(invisible(mrss.out)) } # examples # mrss.mod332(es=.22, rho3=.1, rho2=.1, omegam3=.05, q=.5, r21=.30, r22=.4, r2m3=0, n=20, J=4) # mrss.mod332(es=.11, rho3=.1, rho2=.1, omegam3=.05, r21=.30, r22=.4, r2m3=0, n=20, J=4) # mrss.mod332(es=.22, rho3=.1, rho2=.1, omegam3=0, q=.2, r21=.30, r22=.4, r2m3=0, n=20, J=4) # mrss.mod332(es=.11, rho3=.1, rho2=.1, omegam3=0, r21=.30, r22=.4, r2m3=0, n=20, J=4) mrss.mod333 <- function(es=.25, power=.80, alpha=.05, two.tailed=TRUE, rho2, rho3, r21=0, r22=0, r23=0, p=.50, q=NULL, n, J, K0=10, tol=.10){ user.parms <- as.list(match.call()) .error.handler(user.parms) i <- 0 conv <- FALSE while(i<=100 & conv==FALSE){ df <- K0 - 5 if(df<= 0 | is.infinite(df)){break} T1 <- ifelse(two.tailed==TRUE,abs(qt(alpha/2,df)),abs(qt(alpha,df))) T2 <- abs(qt(power,df)) M <- ifelse(power>=.5,T1+T2,T1-T2) K1 <- ifelse(is.null(q), 5 + (M/es)^2 * (rho3*(1-r23)/(p*(1-p)) + rho2*(1-r22)/(p*(1-p)*J) + (1-rho3-rho2)*(1-r21)/(p*(1-p)*J*n)), # continuous mod 5 + (M/es)^2 * (rho3*(1-r23)/(p*(1-p)*q*(1-q)) + rho2*(1-r22)/(p*(1-p)*q*(1-q)*J) + (1-rho3-rho2)*(1-r21)/(p*(1-p)*q*(1-q)*J*n)) # binary mod ) K0 <- (K1+K0)/2 i <- i+1 } K <- ifelse(df>0,round(K0),NA) mrss.out <- list(fun = "mrss.mod333", parms = list(es=es, power=power, alpha=alpha, two.tailed=two.tailed, rho2=rho2, rho3=rho3, r21=r21, r22=r22, r23=r23, p=p, q=q, n=n, J=J, K0=K0, tol=tol), df = df, ncp = M, K = K) cat(ifelse(is.null(q), "\nModerator type: Continuous\n", "\nModerator type: Binary\n"), "\nK =", K) class(mrss.out) <- c("mod333", "mrss") return(invisible(mrss.out)) } # examples # mrss.mod333(es=.30, rho3=.1, rho2=.1, q=.5, r21=.3, r22=.4, r23=.5, n=20, J=4) # mrss.mod333(es=.15, rho3=.1, rho2=.1, r21=.3, r22=.4, r23=.5, n=20, J=4) mdes.bcra4f3 <- function(power=.80, alpha=.05, two.tailed=TRUE, rho2, rho3, p=.50, r21=0, r22=0, r23=0, g3=0, n, J, K, L){ user.parms <- as.list(match.call()) .error.handler(user.parms) df <- L * (K - 2) - g3 SSE <- sqrt(rho3*(1-r23)/(p*(1-p)*K*L) + rho2*(1-r22)/(p*(1-p)*J*K*L) + (1-rho3-rho2)*(1-r21)/(p*(1-p)*J*K*L*n)) mdes <- .mdes.fun(power = power, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed) .summ.mdes(effect = "main", power = power, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed, mdes = mdes) mdes.out <- list(fun = "mdes.bcra4f3", parms = list(power=power, alpha=alpha, two.tailed=two.tailed, rho2=rho2, rho3=rho3, p=p, r21=r21, r22=r22, r23=r23, g3=g3, n=n, J=J, K=K, L=L), df=df, ncp = mdes[1]/SSE, mdes = mdes) class(mdes.out) <- c("main", "mdes") return(invisible(mdes.out)) } # example # mdes.bcra4f3(alpha=.05, two.tailed=TRUE, power=.80, rho3=.15, rho2=.15, n=10, J=4, K=4, L=15) power.bcra4f3 <- function(es=.25, alpha=.05, two.tailed=TRUE, rho2, rho3, p=.50, r21=0, r22=0, r23=0, g3=0, n, J, K, L){ user.parms <- as.list(match.call()) .error.handler(user.parms) df <- L * (K - 2) - g3 SSE <- sqrt(rho3*(1-r23)/(p*(1-p)*K*L) + rho2*(1-r22)/(p*(1-p)*J*K*L) + (1-rho3-rho2)*(1-r21)/(p*(1-p)*J*K*L*n)) power <- .power.fun(es = es, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed) .summ.power(power = power, alpha = alpha, sse = SSE, df = df, two.tailed = two.tailed, es = es) power.out <- list(fun = "power.bcra4f3", parms = list(es=es, alpha=alpha, two.tailed=two.tailed, rho2=rho2, rho3=rho3, p=p, r21=r21, r22=r22, r23=r23, g3=g3, n=n, J=J, K=K, L=L), df=df, ncp = es/SSE, power = power) class(power.out) <- c("main", "power") return(invisible(power.out)) } # example # power.bcra4f3(es=0.24, alpha=.05, two.tailed=TRUE, rho3=.15, rho2=.15, n=10, J=4, K=4, L=15) mrss.bcra4f3 <- function(es=.25, power=.80, alpha=.05, two.tailed=TRUE, n, J, L, K0=10, tol=.10, rho2, rho3, p=.50, g3=0, r21=0, r22=0, r23=0){ user.parms <- as.list(match.call()) .error.handler(user.parms) i <- 0 conv <- FALSE while(i<=100 & conv==FALSE){ df <- L*(K0-2)-g3 if(df<=0 | is.infinite(df)){break} T1 <- ifelse(two.tailed==TRUE,abs(qt(alpha/2,df)),abs(qt(alpha,df))) T2 <- abs(qt(power,df)) M <- ifelse(power>=.5,T1+T2,T1-T2) K1 <- (M/es)^2 * (rho3*(1-r23)/(p*(1-p)*L) + rho2*(1-r22)/(p*(1-p)*L*J) + (1-rho3-rho2)*(1-r21)/(p*(1-p)*J*L*n)) if(abs(K1-K0)<tol){conv <- TRUE} K0 <- (K1+K0)/2 i <- i+1 } K <- ifelse(df>0,round(K0),NA) mrss.out <- list(fun = "mrss.bcra4f3", parms = list(es=es, power=power, alpha=alpha, two.tailed=two.tailed, n=n, J=J, L=L, K0=K0, tol=tol, rho2=rho2, rho3=rho3, p=p, r21=r21, r22=r22, r23=r23, g3=g3), df=df, ncp = M, K = K) class(mrss.out) <- c("main", "mrss") cat("K =", K, "(per block)\n") return(invisible(mrss.out)) } # example # mrss.bcra4f3(rho3=.15, rho2=.15, g3=1, p=.5, r23=.5, r22=.5, r21=.5, n=10, J=4, L=4)
c5485ffbbdca33e8721007ce76e4820c3b9fc18a
aa01dbbf23cbea8b1575dc9b7b5f04717a13796e
/Project5.R
95e8aeab1dde8a8d856ce93cf44ebd29a353f0a5
[]
no_license
Priyanshi73/R_projects
21a66f1db3a05f52fc80f3cd69438a1f67060381
f7b5352aae088e0c6fa1801f7a70cbd0676ab3fb
refs/heads/master
2022-12-14T20:08:24.688877
2020-09-14T13:28:29
2020-09-14T13:28:29
295,216,317
0
0
null
null
null
null
UTF-8
R
false
false
6,364
r
Project5.R
getwd() setwd("C:\\Users\\Priyanshi\\Downloads\\Data\\project_5") bank_full_test=read.csv("bank-full_test.csv",stringsAsFactors = F) bank_full_train=read.csv("bank-full_train.csv",stringsAsFactors = F) View(bank_full_train) dim(bank_full_test) dim(bank_full_train) setdiff(names(bank_full_train),names(bank_full_test)) bank_full_test$y=NA bank_full_test$data="test" bank_full_train$data="train" bank <- rbind(bank_full_train,bank_full_test) dim(bank) library(dplyr) glimpse(bank) ##character variable table(bank$job)#dummy encoding table(bank$marital) ## 0-divorced 1-single 2-married table(bank$education) #0-pri 1-sec 2-tert 3-unknown table(bank$default) #0 1 table(bank$housing) #0 1 table(bank$loan) # 0 1 table(bank$contact) ## 0-cellu 1-tele 3-unknown table(bank$month)#dummy table(bank$poutcome) ##0-fail 1-success 2-other 3-unknown table(bank$y) #0 1 bank=bank %>% mutate(default=as.numeric(default=="yes"), housing=as.numeric(housing=="yes"), loan=as.numeric(loan=="yes"), y=as.numeric(y=="yes")) glimpse(bank) ##education #0-pri 1-sec 2-tert 3-unknown ##contact # 0-cellu 1-tele 3-unknown #failure ##0-fail 1-success 2-other 3-unknown #marital ## 0-divorced 1-single 2-married bank=bank %>% mutate(education=ifelse(education=="primary",0, ifelse(education=="secondary",1, ifelse(education=="tertiary",2,3))), contact=ifelse(contact=="cellular",0, ifelse(contact=="telephone",1,2)), poutcome=ifelse(poutcome=="failure",0, ifelse(poutcome=="success",1, ifelse(poutcome=="other",2,3))), marital=ifelse(marital=="divorced",0, ifelse(marital=="single",1,2))) glimpse(bank) #job-- group by mean bank %>% group_by(job) %>% summarise(mean_job=mean(y,na.rm=T)) bank=bank %>% mutate(job_11=as.numeric(job %in% c("admin","self-employed","technician","unknown")), job_13=as.numeric(job %in% c("management","unemployed")), job_07=as.numeric(job %in% c(" blue-collar","housemaid","entrepreneur","services")), job_20=as.numeric(job %in% c("retired","student"))) %>% select(-job) ##month -- group by mean bank %>% group_by(month) %>% summarise(mean_job=mean(y,na.rm=T)) bank=bank %>% mutate(month_4=as.numeric(month %in% c("dec","oct","sep","marc")), month_06=as.numeric(month %in% c("may","jul")), month_09=as.numeric(month %in% c("jun","nov","jan","aug")), month_16=as.numeric(month %in% c("feb","apr"))) %>% select(-month) glimpse(bank) ## table(bank$age) sort(table(bank$balance),decreasing = T)[1:5] table(bank$day) table(bank$duration) table(bank$campaign) table(bank$pdays) table(bank$previous) table(bank$ID) ##----------- #checking for NA colSums(is.na(bank)) dim(bank) bank_full_test=bank %>% filter(data=="test") %>% select(-data,-y) bank_full_train=bank %>% filter(data=="train") %>% select(-data) glimpse(bank_full_train) dim(bank_full_train) ## s=sample(1:nrow(bank_full_train),.8*nrow(bank_full_train)) bank_train1=bank_full_train[s,] bank_train2=bank_full_train[-s,] ## library(car) for_vif=lm(y~.-ID,data=bank_train1) sort(vif(for_vif),decreasing = T) #removed vif>4 for_vif=lm(y~.-ID-month_06,data=bank_train1) sort(vif(for_vif),decreasing = T) #glm log_fit=glm(y~.-ID-month_06,data=bank_train1,family = "binomial") log_fit=step(log_fit) formula(log_fit) log_fit=glm(y ~ marital + education + balance + housing + loan + contact + duration + campaign + previous + poutcome + job_07 + job_20 + month_4+ month_16,data=bank_full_train,family = "binomial") summary(log_fit) ##scoring auc library(pROC) train1.score=predict(log_fit,newdata = bank_train1,type="response") auc(roc(bank_train1$y,train1.score)) train2.score=predict(log_fit,newdata = bank_train2,type="response") auc(roc(bank_train2$y,train2.score)) train.score=predict(log_fit,newdata = bank_full_train,type="response") real=bank_full_train$y #positivies cutoffs=seq(0.001,0.999,0.001) cutoff_data=data.frame(cutoff=99,Sn=99,Sp=99,KS=99,F5=99,F.1=99,M=99) for(cutoff in cutoffs){ print(paste0("cutoff is:", cutoff)) predicted=as.numeric(train.score>cutoff) #call it 1 TP=sum(real==1 & predicted==1) TN=sum(real==0 & predicted==0) FP=sum(real==0 & predicted==1) FN=sum(real==1 & predicted==0) P=TP+FN N=TN+FP Sn=TP/P #sensitivity Sp=TN/N #specificity precision=TP/(TP+FP) recall=Sn KS=(TP/P)-(FP/N) F5=(26*precision*recall)/((25*precision)+recall) F.1=(1.01*precision*recall)/((.01*precision)+recall) M=(4*FP+FN)/(5*(P+N)) cutoff_data=rbind(cutoff_data, c(cutoff,Sn,Sp,KS,F5,F.1,M)) } cutoff_data=cutoff_data[-1,] View(cutoff_data) #### visualise how these measures move across cutoffs library(ggplot2) ggplot(cutoff_data,aes(x=cutoff,y=Sp))+geom_line() ## to see whr is ur maxx cutoff and KS my_cutoff=cutoff_data$cutoff[which.max(cutoff_data$KS)] my_cutoff View(cutoff_data) #look KS at cotoff=.121 #ks=.624 #now we have KS we will predict with train and test train.score train.predicted=as.numeric(train.score>my_cutoff) test.score=predict(log_fit,newdata = bank_full_test,type="response") test.predicted=as.numeric(test.score>my_cutoff) head(test.predicted) dim(bank_full_test) length(test.predicted) write.csv(test.predicted,"Priyanshi_Agarwal_P5_part2.csv",row.names = F) ## ##---------------------------------Quiz------------------------------------- View(bank_full_train) #1 40.91 mean(bank_full_train$age,na.rm = T) #2 3329 table(bank_full_train$balance) #upper quantile(bank_full_train$balance,.75)+1.5*IQR(bank_full_train$balance) sum(bank_full_train$balance>3427) #3315 #lower quantile(bank_full_train$balance,.25)-1.5*IQR(bank_full_train$balance) sum(bank_full_train$balance<(-1941)) #14 #3 var(bank_full_train$balance) #4-- vif #5-- lower AIC #6-- no #7-- yes #8-- balanced #9-- Q3+1.5*IQR #10-- adjusted R2 ##------------------------------------------------------------------
dcc6668152ab63bd0f7c2c316a8586dd0f561f3e
7a513b603765226575b01d439530715b1519d74c
/man/convert.temp.Rd
704fb833e264b4d67deed97591dd0e3bb982769f
[]
no_license
jsugarelli/tempconvertr
00ce29b5312cceee4e11a590be8b68cd4ced1ae9
c0960f6e83bbaa0bc81a783b0ccd387fcf3e32ee
refs/heads/master
2021-03-01T18:37:07.693329
2020-03-08T12:11:09
2020-03-08T12:11:09
245,806,456
1
0
null
null
null
null
UTF-8
R
false
true
1,397
rd
convert.temp.Rd
% Generated by roxygen2: do not edit by hand % Please edit documentation in R/tempconv.r \name{convert.temp} \alias{convert.temp} \title{Converting Temperatures} \usage{ convert.temp(from.temp, from.unit = "Celsius", to.unit = "Kelvin", as.json = FALSE) } \arguments{ \item{from.temp}{Temperature value to be converted.} \item{from.unit}{Scale of the temperature value to be converted. Either \code{"Celsius"} (default), \code{"Fahrenheit"} or \code{"Kelvin"}.} \item{to.unit}{Target temperature scale. Either \code{"Celsius"} (default), \code{"Fahrenheit"} or \code{"Kelvin"}.} \item{as.json}{Indicates if function returns JSON object describing the conversion instead of just the converted temperature value.} } \value{ Either the converted temperature value or a JSON object (see details). } \description{ Converts temperatures temperatures between degrees Celsius, degrees Fahrenheit and Kelvin. } \details{ If \code{as.json==TRUE} then \code{convert.temp()} returns a JSON object containing two sub-object \code{from} and \code{to} each of which has a \code{temp} and a \code{unit} field to describe the temperature. The \code{from.unit} and \code{to.unit} arguments are case-insensitive. } \examples{ result.fahrh.json <- convert.temp(24.5, from.unit="celsius", to.unit="fahrenheit", as.json=TRUE) result.kelv <- convert.temp(24.5) }
317741497b389110c55939f7d40b74b3417afd87
7350b810110e86c3418ed68556a1922cfdc0ac17
/script.R
3fece8c423c39bfc45b761489946715ae9302319
[]
no_license
mattpiskorz/image_processing_r
dd808403628912191a70be4684f8631627aef8c2
a64c13543f5646aaa5a7a208e784c7d3fb2b2620
refs/heads/master
2020-05-30T18:56:01.647357
2014-12-04T14:07:36
2014-12-04T14:07:36
null
0
0
null
null
null
null
UTF-8
R
false
false
271
r
script.R
library("EBImage") library("png", lib.loc="~/R/x86_64-pc-linux-gnu-library/3.1") file_source <- "/home/matt/Projects/image_processing/test_images" file_name <- "6_6_black_and_white.png" image = readPNG(paste(file_source,file_name, sep="/")) display(image) print(image)
0869086682d473af1e9ee052fc66b6c4b3b24c97
04ab1edfb4b08adabbf89eb8011b78c35c6f4e0f
/scripts/10_parseProteomicsSpectronaut.R
b84d60029a8659fbd770e377883ae20f785412ad
[]
no_license
alanlorenzetti/tlr_v2
b4bc9d7c00580dd08015273957e919a35cc9b4df
ea4c3e2701cbd5e6357fac83b4f764e6b7969d30
refs/heads/master
2023-05-27T11:57:20.296063
2021-06-08T22:17:02
2021-06-08T22:17:02
290,974,388
0
0
null
null
null
null
UTF-8
R
false
false
6,257
r
10_parseProteomicsSpectronaut.R
# alorenzetti 202007 # description #### # this script will parse proteomics abundance data # generated by Spectronaut software # loading files #### file = "data/Halo_WholeLysate_analysis_HaloIonLibraryVNG_merged_final_2018-04-07_SW100_Protein_Report_20200731.xls" file2 = "data/Halo_Ribo_analysis_HaloIonLibraryVNG_merged_final_2018-04-07_SW100_Protein_Report.xls" # they will throw a warning saying # cols were parsed as.character # but we ll deal with that later spectro1 = read_delim(file = file, delim = "\t") spectro2 = read_delim(file = file2, delim = "\t") # in this version I am going to use # only the lysate fraction spectro = spectro1 # full join of both dataframes #spectro = full_join(spectro1, spectro2, by = "PG.ProteinAccessions") # wrangling #### # adjusting colnames colnames(spectro)[-1] = sub("^\\[.* ", "", colnames(spectro)[-1]) colnames(spectro)[-1] = sub("^.*_?(BR[1-3])(TP[1-4]).*_.*_.*_(r0[1-3]).*$", "\\2_\\1_\\3", colnames(spectro)[-1], perl = T) colnames(spectro)[-1] = paste0(rep("lysate_", 36), colnames(spectro)[-1]) colnames(spectro)[1] = "locus_tag" # removing first entry line spectro = spectro[-1, ] # warnings will be thrown due to # missing entries ("Filtered" value) spectro = spectro %>% mutate_at(.vars = vars(contains("BR")), .funs = as.numeric) # selection of entries #### # we have to filter the table due to the existence # of peptides matching more than one protein # our simplification is: # the members of a protein group can exist in # the form of an individual observation. # if only one member of a protein group exists individually, # protein group values and individual protein values # are tallied up; # if more than two members of a protein group exist individually # the protein group is discarded # if no member of a protein group exists individually # the protein group is kept (first locus_tag is preserved) # finding out solos and protein groups solo = spectro %>% filter(!str_detect(locus_tag, ",")) pg = spectro %>% filter(str_detect(locus_tag, ",")) ex = NULL pgvspg = NULL for(i in 1:dim(pg)[1]){ curline = pg$locus_tag[i] %>% str_split(pattern = ",") %>% unlist() for(j in 1:length(curline)){ ex[j] = curline[j] %in% solo$locus_tag names(ex)[j] = curline[j] } if(sum(ex) == 0){pass = "pass0"; repres = names(ex)[1]} if(sum(ex) == 1){pass = "pass1"; repres = names(which(ex == TRUE))} if(sum(ex) > 1){pass = "fail"; repres = NA_character_} y = 1:dim(pg)[1] for(k in y[-i]){ curpg = pg$locus_tag[k] %>% str_split(pattern = ",") %>% unlist() pgvspg = c(pgvspg, sum(names(ex) %in% curpg)) } npg = sum(pgvspg > 0) if(sum(pgvspg) == 0){passpg = "pass"} if(sum(pgvspg) > 0){passpg = paste0("fail", npg)} if((pass == "pass0" | pass == "pass1") & passpg == "pass"){ pg$locus_tag[i] = repres } ex = NULL pgvspg = NULL } # filtering out those protein groups # that failed our simplification pg = pg %>% filter(!str_detect(locus_tag, ",")) # VNG5030G (GvpA) and VNG5033G (GvpN) were manually included # since they are protein groups contained within # another protein group but satisfy the nonambiguity criterion # e.g. the protein groups come from isoforms of GvpA1a, GvpA1b, and GvpA2 gvpAN = spectro %>% filter(str_detect(string = locus_tag, pattern = "^VNG5030G|^VNG5033G")) %>% mutate(locus_tag = str_replace(string = locus_tag, pattern = ",.*", replacement = "")) # unifying individual proteins to # simplified protein groups soloPlusSPG = bind_rows(solo, pg, gvpAN) %>% arrange(locus_tag) %>% group_by(locus_tag) %>% dplyr::summarise(across(.cols = starts_with("lysate"), .fns = ~ sum(.x, na.rm = T))) %>% ungroup() %>% dplyr::mutate(across(.cols = starts_with("lysate"), .fns = ~ case_when(.x == 0 ~ NA_real_, TRUE ~ as.numeric(.x)))) spectro = soloPlusSPG # pivoting data frame # we will take run means and annotate number of runs used # I would say using six (of nine) observations is fair enough spectroLong = spectro %>% pivot_longer(cols = contains("BR"), names_to = c("libType", "timepoint", "bioRep", "run"), names_sep = "_", values_to = "abundance") %>% group_by(locus_tag, libType, timepoint) %>% summarise(nruns = 9 - sum(is.na(abundance)), mean_abundance = mean(abundance, na.rm = T), se_abundance = (sd(abundance, na.rm = T) / sqrt(nruns))) %>% mutate(mean_abundance = case_when(is.nan(mean_abundance) ~ NA_real_, TRUE ~ as.numeric(mean_abundance)), se_abundance = case_when(is.nan(se_abundance) ~ NA_real_, TRUE ~ as.numeric(se_abundance))) %>% ungroup() %>% filter(nruns >= 6) # using longer dataframe, I will # create a wider version to be able # to plot heat maps using ComplxHeatmaps # and furthermore to unify it with # RNA-Seq data spectroWide = spectroLong %>% dplyr::select(-nruns) %>% pivot_wider(names_from = c("libType", "timepoint"), names_sep = "_", values_from = c("mean_abundance", "se_abundance")) colnames(spectroWide)[-1] = sub("abundance_", "abundance_protein_", colnames(spectroWide)[-1]) # getting representative locus_tags # representative entries with more than # one corresponding protein entry will get the mean spectroWide = left_join(x = spectroWide, y = nrtxsep %>% select(-product), by = c("locus_tag" = "locus_tag")) %>% filter(!is.na(representative)) %>% relocate(representative) %>% select(-locus_tag) %>% group_by(representative) %>% summarise(across(.cols = everything(), .fns = ~ mean(.x))) %>% rename(locus_tag = "representative") # exploratory plots ##### # plotting densities # normalization doesnt seem necessary # distributions are quite similar # and look like poisson # ggplot(spectroLong, # aes(x = mean_abundance, # color = timepoint)) + # geom_density() + # xlim(c(0, 50000))
3a0010d2473f7a3cafd6a3e49678b667e282fedc
f8698ecfccdb58bb284f364108e93cd0d4c8355e
/functions/utility.R
944cd0b2e239250aa4f752aa0965d2db8326d484
[]
no_license
martin-vasilev/DEVS2
5e46cb702ed06e6ee927907fcd8606a4e5277baf
f47f5d19d5c1d5b13bf64c128afb56aa205dd347
refs/heads/master
2023-01-11T22:06:28.078862
2020-11-11T22:44:46
2020-11-11T22:44:46
121,888,621
0
0
null
null
null
null
UTF-8
R
false
false
26,048
r
utility.R
# Martin R. Vasilev, 2017 ######################## # UTILITY FUNCTIONS # ######################## # Extract text containing stimuli info: get_text<- function(file){ ## extracts the loaded text material # start<- which(grepl("DISPLAY TEXT", file))+1 # start point end<- which(grepl("START", file)) if(length(start)==0){ # no start of text detected return(0) # don't map fixations to stimuli } else{ # extract text containing stimuli info text<- file[start:end] # subset file a= which(gregexpr(pattern ='BUTTON', text)==1) if(length(a)>0){ text<- text[-a] # text<- text[-a] # because one line is removed } #input<- which(grepl("INPUT", text)); input<- input[1]-1 # end point end2<- which(grepl("REGION", text)) end2<- end2[length(end2)] text<- text[1:end2] #end<- which(grepl("INPUT", file)); end<- end[1]-1 # end point #text<- file[start:end] # subset file return(text) } } # Create a database with position of text on screen get_coord<- function(string){ # extracts text coordinates from trial info # check to make sure there are no button press flags here.. a= which(gregexpr(pattern ='BUTTON', string)==1) if(length(a)>0){ string<- string[-a] } #if(which(grepl(' ', string))==1){ # loc<- as.numeric(gregexpr("CHAR", string)) # part1<- substr(string, 1, loc+7) # part2<- substr(string, loc+9, nchar(string)) # string2<- paste(part1, part2, sep="") #} #else{ #out <- data.frame( do.call( rbind, strsplit( string, ' ' ) ) ) out <- do.call( rbind, strsplit( string, '\t' ) ) out<- out[,2] out <- data.frame(do.call( rbind, strsplit( out, ' ' ) ) ) #} out<- subset(out, X2!="DELAY") # Remove DELAY 1ms lines out$X7<- as.numeric(as.character(out$X7)) out$X8<- as.numeric(as.character(out$X8)) out$X9<- as.numeric(as.character(out$X9)) out$X10<- as.numeric(as.character(out$X10)) out$X11<- as.numeric(as.character(out$X11)) fix_spaces<- function(out){ out$space<- NULL a<- which(out$X6=="") # find position of empty spaces out$space<- NA out$space[a]<- 1 # Re-arrange misplaced coords out$X7[a]<- out$X8[a] out$X8[a]<- out$X9[a] out$X9[a]<- out$X10[a] out$X10[a]<- out$X11[a] out<- out[,-11] } out<- fix_spaces(out) # clean_MSG<- function(msg){as.numeric(unlist(gsub("[^0-9]", "", unlist(msg)), ""))} # out$X1<- clean_MSG(out$X1) # get rid of MSG text out<- out[,-c(1,2,3,5)] # remove useless columns # map sentences: map_sent<- function(out){ sent_bnd<- which(out$X6=="."| out$X6=="?"); sent<- NULL if(length(sent_bnd)>0){ for(i in 1:length(sent_bnd)){ if(i==1){ sent[1:sent_bnd[i]]<- 1 } else{ sent<- c(sent, c(rep(i, length(sent_bnd[i-1]+1:sent_bnd[i])- length(sent)))) # sent[sent_bnd[i-1]+1:sent_bnd[i]]<- i } if(i==length(sent_bnd)){ sent<- c(sent, c(rep(i+1, length(sent_bnd[i]+1:nrow(out))- length(sent)))) } } out$sent<- sent } else{ out$sent<- 1 } return(out) } out<- map_sent(out) # map lines: map_line<- function(out){ line<- NULL lines<- sort(unique(out$X8)); # as.numeric.factor <- function(x) {as.numeric(levels(x))[x]} #lines<- as.numeric.factor(lines) for(i in 1:length(lines)){ loc_lines<- which(out$X8==lines[i]) line<- c(line, rep(i, length(loc_lines))) out$space[length(line)]<- 2 } out$line<- line return(out) } out<- map_line(out) # map words: map_words<- function(out){ out$X6<- as.character(out$X6) out$word<- NULL curr_sent=1 curr_word=1 sent_line<- which(out$space==2); sent_line<- sent_line+1 for(i in 1:nrow(out)){ newSent<- curr_sent!= out$sent[i] out$word[i]<- curr_word if(out$X6[i]== ""& !newSent){ curr_word<- curr_word+1 out$word[i]<- curr_word } if(is.element(i, sent_line)){ if(out$X6[i]!="."){ curr_word<- curr_word+1 } out$word[i]<- curr_word } if(newSent){ curr_sent<- curr_sent+1 curr_word<- 1 out$word[i]<- curr_word } } return(out) } out<- map_words(out) # change column names: colnames(out)<- c("char", "letter", "x1", "y1", "x2", "y2", "space", "sent", "line", "word") # map characters per line (for Eye Doctor): out$line_char<- NA unq_line<- unique(out$line) for(i in 1:length(unq_line)){ line<- which(out$line==unq_line[i]) out$line_char[line[1]:line[length(line)]]<- 1:length(line) } return(out) } # Use stimuli information to create a coordinate map for each pixel on the screen # This makes it possible to find exactly what participants were fixating coord_map<- function(coords, x=ResX, y= ResY){ #as.numeric.factor <- function(x) {as.numeric(levels(x))[x]} #coords$x1<- as.numeric.factor(coords$x1); coords$x2<- as.numeric.factor(coords$x2) #coords$y1<- as.numeric.factor(coords$y1); coords$y2<- as.numeric.factor(coords$y2) coords$id<- 1:nrow(coords) map<- data.frame(matrix(NA, nrow = y, ncol = x)) for(i in 1:nrow(coords)){ map[coords$y1[i]:coords$y2[i],coords$x1[i]:coords$x2[i]]<- coords$id[i] } return(map) } # Create a data frame with information about trials, to be used for pre-processing trial_info<- function(file, maxtrial, data){ # extracts information for processing trials ### get trial names: ID<- which(grepl('TRIALID', file)); trial_text<- file[ID] trials<- substr(trial_text, unlist(gregexpr(pattern =' ',trial_text[1]))[2]+1, nchar(trial_text)) #trials<- trials[which(letter!="P" & letter!="F")] # remove practice items and questions trials<- gsub(" ", "", trials) # sometimes there is an extra empty space that can mess up detection of duplicates ### get condition: I<- unlist(gregexpr(pattern ='I',trials)) # start of item info cond<- as.numeric(substr(trials, 2, I-1)) # extract condition number ### get item: D<- unlist(gregexpr(pattern ='D',trials)) # start of dependent info item<- as.numeric(substr(trials, I+1, D-1)) # extract condition number depend<- as.numeric(substr(trials, nchar(trials), nchar(trials))) ### get sequence: #seq<- 1:length(trials) ### get start & end times start<- which(grepl('DISPLAY ON', file)) end <- which(grepl('DISPLAY OFF', file)) duplicated<- trials[duplicated(trials)] if(length(duplicated)>0){ # if there were aborted trials.. # message(paste(" Diplicated trial", duplicated, "for file:", data, "\n")) # message("Analysing only last attempt at the trial!") toBeRemoved<- NULL uniqueDupl<- unique(duplicated) dup_rem<- NULL for(i in 1:length(uniqueDupl)){ dup_rem_T<- which(trials==uniqueDupl[i]) dup_rem<- c(dup_rem, dup_rem_T[1:length(dup_rem_T)-1]) } # end of i start<- start[-dup_rem] #end<- end[-dup_rem] cond<- cond[-dup_rem] item<- item[-dup_rem] # seq<- seq[-toBeRemoved] depend<- depend[-dup_rem] ID<- ID[-dup_rem] } # end of aborted conditional trial_db<- data.frame(cond, item, depend, start, end, ID) trial_db<- subset(trial_db, depend==0 & item< maxtrial+1) trial_db$seq<- 1:nrow(trial_db) ### # trials<- trials[which(!is.element(trials, duplicated))] return(trial_db) } # Basic pre-processing and extraction of fixations from data file: parse_fix<- function(file, map, coords, trial_db, i, ResX, ResY, keepLastFix, hasText=TRUE){ get_FIX_stamp<- function(string){as.numeric(substr(string, 1, unlist(gregexpr(pattern ='\t', string))[1]-1))} loc_blinks<- function(blink_time, s_time){findInterval(blink_time, s_time)+1 } # +1 because it affects the next fixation get_x_pixel<- function(string){ #tab_loc<- unlist(gregexpr(pattern ='\t', string))[3:4] #sub_str<- substr(string, tab_loc[1], tab_loc[2]) #x<- as.numeric(unlist(gsub("[^0-9.]", "", unlist(sub_str)), "")) #x<- floor(x) a<- data.frame(do.call( rbind, strsplit( string, '\t' ) ) ) x<- as.numeric(as.character(unlist(a$X4))) return(x) } get_y_pixel<- function(string){ #tab_loc<- unlist(gregexpr(pattern ='\t', string))[4:5] #sub_str<- substr(string, tab_loc[1], tab_loc[2]) #y<- as.numeric(unlist(gsub("[^0-9.]", "", unlist(sub_str)), "")) #y<- floor(y) a<- data.frame(do.call( rbind, strsplit( string, '\t' ) ) ) y<- as.numeric(as.character(unlist(a$X5))) return(y) } # trial_db<- trial_info(file) # for(i in 1:nrow(trial_db)){ # get position of fixation stamps: SFIX_stamps<- which(grepl('SFIX', file[trial_db$start:trial_db$end])) EFIX_stamps<- which(grepl('EFIX', file[trial_db$start:trial_db$end])) if(length(SFIX_stamps)==0 | length(EFIX_stamps)==0){ # means that there was no complete fixation on this trial (i.e, # participant likely pressed end button by mistake) raw_fix<- NULL return(raw_fix) message(sprintf("No fixations in Trial %d: excluded", j)) } if(EFIX_stamps[1]<SFIX_stamps[1]){ # removes fixation that triggered gaze box EFIX_stamps<- EFIX_stamps[-1] } if(EFIX_stamps[length(EFIX_stamps)]< SFIX_stamps[length(SFIX_stamps)]){ SFIX_stamps<- SFIX_stamps[-length(SFIX_stamps)] } # fixation was not terminated before the end of trial # get start and end time of fixations: s_time<- get_FIX_stamp(file[SFIX_stamps+ trial_db$start]) # start time of fixation e_time<- get_FIX_stamp(file[EFIX_stamps+ trial_db$start-2]) # end time of fixation # calculate fixation durations: fixDur<- e_time- s_time # get x pixel position: x<- get_x_pixel(file[EFIX_stamps+ trial_db$start-1]) # get y pixel position: y<- get_y_pixel(file[EFIX_stamps+ trial_db$start-1]) # find blinks: blink_stamp<- which(grepl('EBLINK', file[trial_db$start:trial_db$end])) blink_time<- get_FIX_stamp(file[blink_stamp+ trial_db$start])-1 blink_out<- which(blink_time<s_time[1]| blink_time>e_time[length(e_time)]) if(length(blink_out>0)){ # blinks outside time window that is analysed blink_time<- blink_time[-blink_out] # remove them } blink_pos<- loc_blinks(blink_time, s_time) blink<- rep(0, length(s_time)) blink[blink_pos]<-1 #if(length(blink)>length(e_time)){ # blink<- blink[-length(blink)] #} # merge into a dataframe: fix<- data.frame(s_time, e_time, fixDur, x, y, blink) #-----------------------------------------------# # map fixations to stimuli on the screen: # #-----------------------------------------------# loc<- NULL; raw_fix<- NULL; temp<- NULL; sub<- NULL s_time<- NULL; e_time<- NULL; xPos<- NULL; yPos<- NULL item<- NULL; cond<- NULL; seq<- NULL; fix_num<- NULL; fix_dur<- NULL sent<- NULL; line<- NULL; word<- NULL; char_trial<- NULL max_sent<- NULL; max_word<- NULL; intersent_regr<- NULL intrasent_regr<- NULL; blink<- NULL; outOfBnds<- NULL; outsideText<- NULL if(hasText){ # max word for each sentence: curr_sent<- matrix(0, max(coords$sent),2) curr_sent[,1]<- c(1:max(coords$sent)) } for(j in 1:nrow(fix)){ if(hasText){ loc<- map[fix$y[j], fix$x[j]] # locate fixation if(is.list(loc)){ loc<- NULL } } # general info: sub[j]<- i item[j]<- trial_db$item cond[j]<- trial_db$cond seq[j]<- trial_db$seq fix_num[j]<- j fix_dur[j]<- fix$fixDur[j] # info from asc file: s_time[j]<- fix$s_time[j]; e_time[j]<- fix$e_time[j] xPos[j]<- fix$x[j]; yPos[j]<- fix$y[j] blink[j]<- fix$blink[j] if(xPos[j]<1 | xPos[j]> ResX | yPos[j]< 1 | yPos[j]>ResY){ # fixation is out of bounds outOfBnds[j]<- 1 } else{ outOfBnds[j]<- 0 if(hasText){ # outside of text area? if(is.na(loc)){ outsideText[j]<- 1 } else{ outsideText[j]<- 0 } } } if(fix$x[j]<0){ loc<- NA outOfBnds[j]<- 1 outsideText[j]<- 1 } if(hasText){ # stimuli info: if(!is.null(loc)){ sent[j]<- coords$sent[loc] line[j]<- coords$line[loc] word[j]<- coords$word[loc] char_trial[j]<- as.numeric(as.character(levels(coords$char[loc])[coords$char[loc]]))+1 # +1 bc Eyetrack counts from 0 } else{ sent[j]<- NA; line[j]<- NA; word[j]<- NA; char_trial[j]<- NA } # saccade stuff: if(j==1){ max_sent[j]<- sent[j] } else{ max_sent[j]<- max_sent[j-1] if(!is.na(max_sent[j])& !is.na(sent[j]) & sent[j]> max_sent[j]){ max_sent[j]<- sent[j] } } # maximum word: if(j==1){ max_word[j]<- abs(word[j]) curr_sent[sent[j],2]<- abs(word[j]) } else{ max_word[j]<- curr_sent[sent[j],2] if(!is.na(word[j])& abs(word[j])>curr_sent[sent[j],2]){ max_word[j]<- abs(word[j]) curr_sent[sent[j],2]<- abs(word[j]) # replace new max word } } # Regression stuff: if(!is.na(max_sent[j])& !is.na(sent[j]) & sent[j]< max_sent[j]){ intersent_regr[j]<- 1 } else{ intersent_regr[j]<- 0 } # intra-sentence regressions: if(!is.na(word[j])& abs(word[j])<max_word[j]){ intrasent_regr[j]<- 1 }else{ intrasent_regr[j]<- 0 } } else{ # end of if hasText sent[j]=NA; max_sent[j]=NA; line[j]=NA; word[j]=NA; max_word[j]=NA; char_trial[j]=NA; intrasent_regr[j]=NA; intersent_regr[j]=NA; outsideText[j]=NA } } # end of j loop if(length(outsideText)!= length(item)){ outsideText[length(outsideText):length(item)]<- NA } raw_fix<- data.frame(sub,item, cond, seq, s_time, e_time,xPos, yPos, fix_num, fix_dur, sent, max_sent, line, word, max_word, char_trial, intrasent_regr, intersent_regr, blink, outOfBnds, outsideText) if(keepLastFix==FALSE){ # remove last fixation on trial (due to participants' making a decision to press the button) raw_fix<- raw_fix[-nrow(raw_fix),] } if(hasText==TRUE){ raw_fix$hasText<-1 }else{ raw_fix$hasText<-0 } return(raw_fix) } ############# # PLOTFIX.R # ############# plot_fix<- function(coords, raw_fix_temp, i, j, ResX, ResY, hasText=TRUE, printOriginal= TRUE){ remap_letters<- function(letter, y){ # adjusted y position for easier reading letter<- as.character(letter) ascenders<- c("b", "d", "f", "h", "i", "k", "l", "t") descenders<- c("g", "j", "p", "q", "y") punct<- c(",", ".") caps<- which(grepl("[A-Z]",letter)) which_asc<- which(is.element(letter, ascenders)) which_desc<- which(is.element(letter, descenders)) which_punct<- which(is.element(letter, punct)) y[which_desc]<- y[which_desc]- 2 y[which_asc]<- y[which_asc]+1 y[which_punct]<- y[which_punct]-4 y[caps]<- y[caps]+1 return(y) } add.alpha <- function(col, alpha=1){ if(missing(col)) stop("Please provide a vector of colours.") apply(sapply(col, col2rgb)/255, 2, function(x) rgb(x[1], x[2], x[3], alpha=alpha)) } # create new directory for images: mainDir <- getwd() imgDir <- "img" subDir<- paste("s", i, sep= "") if (!file.exists(imgDir)){ dir.create(file.path(mainDir, imgDir), showWarnings = FALSE) } if (!file.exists(paste(imgDir, "/", subDir, sep=""))){ dir.create(file.path(imgDir, subDir), showWarnings = FALSE) } # create output string output= paste(imgDir, "/", subDir, "/", "Sub_", i, "_", "item_", j, ".png", sep="") # open file for plotting: png(filename = output, width = ResX, height = ResY, units = "px", pointsize = 12, bg="white", res = 100) par(mar=c(0,0,0,0)) # set plot margins to 0 # create empty plot: plot(NA, axes=F, main="", xlab="" ,ylab="", col="black", ylim=c(0, ResY), xlim=c(0, ResX), xaxs="i", yaxs="i") if(hasText){ # convert coordinates to numbers: coords$y1<- as.numeric(as.character(coords$y1)) coords$y2<- as.numeric(as.character(coords$y2)) coords$x1<- as.numeric(as.character(coords$x1)) coords$x2<- as.numeric(as.character(coords$x2)) # Plot stimuli that appeared on screen: rect(coords$x1, ResY-coords$y1, coords$x2, ResY-coords$y2, col= "white", border= "#CFCBCB") xpos= coords$x1+ (coords$x2- coords$x1)/2 ypos= ResY-coords$y1- (coords$y2- coords$y1)/2 # correct y pos of some letter for better readibility: ypos<- remap_letters(coords$letter, ypos) # print letters: text(xpos, ypos, coords$letter, col= "black") #symbols(raw_fix$xPos, raw_fix$yPos, circles=rep(0.1, nrow(raw_fix))) # add saccades # for (k in 1:nrow(raw_fix_temp)){ # if(k==1){ next} # x1<- raw_fix_temp$xPos[k-1]+6 # y1<- ResY-raw_fix_temp$yPos[k-1] # if(x2>x1){ # x2<- raw_fix_temp$xPos[k]-10 # } else{ # x2<- raw_fix_temp$xPos[k]+10 # } # y2<- ResY-raw_fix_temp$yPos[k] # fixPosX<- x1+ (x2-x1)/2 # fixPosY<- y1+ (y2-y1)/2 # arrows(x1, y1, x2, y2, col = add.alpha("blue",0.2), lty= 1, lwd=2, length=0.10) #text(fixPosX, fixPosY, raw_fix_temp$fix_num, col= add.alpha("blue",0.3)) # } first<- subset(raw_fix_temp, intrasent_regr==0 & intersent_regr==0) second<- subset(raw_fix_temp, intrasent_regr==1 | intersent_regr==1) # first-pass: points(x= first$xPos, y=ResY-first$yPos, pch = 16, col= add.alpha("green",0.20), cex= 0.7*(first$fix_dur/75)) points(x= first$xPos, y=ResY-first$yPos, pch = 16, cex=0.7, col="green") # second-pass: points(x= second$xPos, y=ResY-second$yPos, pch = 16, col= add.alpha("orange",0.20), cex= 0.7*(second$fix_dur/75)) points(x= second$xPos, y=ResY-second$yPos, pch = 16, cex=0.7, col="orange") # fixation numbers: text(raw_fix_temp$xPos, ResY-raw_fix_temp$yPos+15, raw_fix_temp$fix_num, col= add.alpha("red",0.6)) } else{ # end of hasText # plot fixations: points(x= raw_fix_temp$xPos, y=ResY-raw_fix_temp$yPos, pch = 16, col= add.alpha("blue",0.20), cex= 0.7*(raw_fix_temp$fix_dur/75)) points(x= raw_fix_temp$xPos, y=ResY-raw_fix_temp$yPos, pch = 16, cex=0.7, col="blue") # fixation numbers: text(raw_fix_temp$xPos, ResY-raw_fix_temp$yPos+15, raw_fix_temp$fix_num, col= add.alpha("red",0.6)) } # print original label: if(printOriginal){ text(ResX - 0.05*ResX, ResY -ResY*0.02, 'ORIGINAL', col= 'black', face=2) } dev.off() # close file } reAlign<- function(rawfix, coords, map, ResX, ResY){ #------------------------------------------ # Functions: #------------------------------------------ # Check for a return sweep (RS): RS<- function(i, rawfix, coords, reqYthresh=TRUE, reqXthresh=TRUE, Ythresh= 1/4, Xthresh= 8, threshSimilar= 2/3){ if(i==1){ # first fixation can't be a return sweep return(0) } ### settings: lw<- coords$x2[1]-coords$x1[1] # letter width lh<- coords$y2[1]-coords$y1[1] # letter height meetXthresh<- FALSE meetYthresh<- FALSE nextSimilar<- FALSE ############################# # conditions # leftward saccade? leftSacc<- rawfix$xPos[i]< rawfix$xPos[i-1] # downward saccade? downSacc<- rawfix$yPos[i]> rawfix$yPos[i-1] if(downSacc & reqYthresh){ # x pixels downwards required for RS Ydiff<- lh*Ythresh # threshold to be met trueYdiff<- rawfix$yPos[i]- rawfix$yPos[i-1] # Y distance traveled meetYthresh<- trueYdiff >= Ydiff } if(leftSacc & reqXthresh){ # x pixels leftwards required for RS Xdiff<- lw*Xthresh # threshold to be met trueXdiff<- rawfix$xPos[i-1]- rawfix$xPos[i] # X distance traveled meetXthresh<- trueXdiff >= Xdiff } # next fixation with 'similar' Y pos? if(i!= nrow(rawfix)){ # only if not the last fixation in trial.. howSimilar<- threshSimilar*lh # within x/yth of a letter height nextSimilar<- rawfix$yPos[i+1]>= rawfix$yPos[i]- howSimilar | rawfix$yPos[i+1]<= rawfix$yPos[i]+ howSimilar } ###### Point system: # - leftward saccade: 1 point # - leftward saccade meeting threshold: 1 point # - downward saccade: 2 points # - downward saccade meeting threshold: 1 point # - next Fix. with 'similar' Ypos: 1 point # = 6 max points maxPoints<- 1 +2 +1 if(reqYthresh){ maxPoints<- maxPoints+1 } if(reqXthresh){ maxPoints<- maxPoints+1 } #---------------------------- currPoints<- 0 # start with 0 if(leftSacc){ currPoints<- currPoints + 1/maxPoints if(meetXthresh){ currPoints<- currPoints+ 1/maxPoints } } if(downSacc){ currPoints<- currPoints +2/maxPoints if(meetYthresh){ currPoints<- currPoints+ 1/maxPoints } } if(nextSimilar){ currPoints<- currPoints +1/maxPoints } # prob<- currPoints/maxPoints return(round(currPoints, 2)) } # Check if fixation is still on the same line (SL): SL<- function(i, rawfix, coords, curr_line, xstart, xend, RSthresh= 0.8){ if(i==1){ # first fixation will be on the first line (assuming gaze box) return(1) } # Fixation is already assigned to the current line? isAssigned<- rawfix$outsideText[i]==0 & rawfix$line[i]== curr_line # Is current fixation a likely return sweep? likelyRS<- rawfix$pRS[i]>= RSthresh #how much skipped info if fixation is no longer on the same line? ppl<- coords$x2[1]- coords$x1[1] # pixels per letter pixLeft<- xend[curr_line, 2] - rawfix$xPos[i] # pixels left until end of line letLeft<- pixLeft/ppl # letters left until end of line totalLetters<- (xend[curr_line, 2]- xstart[curr_line, 2])/ ppl # num of letters on line textLeft<- totalLetters- (totalLetters- letLeft) # num letters from current xPos until end of line propLeft<- textLeft/totalLetters # prop of text left on screen ###### Point system: # - Fixation is already assigned to the current line: 2 points # - Fixation is not likely a return sweep: 1 point # - Discourage skipping text on the line: 1 points max (function of remaining text) # = max 4 points maxPoints<- 2+1+1 currPoints<- 0 if(isAssigned){ # already assigned to same line currPoints<- currPoints + 2/maxPoints } if(!likelyRS){ # not likely a RS currPoints<- currPoints + 1/maxPoints } # weight points by amount of text left on the line (max 1) currPoints<- currPoints+ (1-propLeft)/maxPoints currPoints<- round(currPoints,2) return(currPoints) } # Re-map fixation info after re-aligning it: reMap<- function(rawfix, i, map, coords, newX=NULL, newY=NULL){ rawfix$reAligned[i]<- 1 rawfix$prevLine[i]<- rawfix$line[i] rawfix$prevX[i]<- rawfix$xPos[i] rawfix$prevY[i]<- rawfix$yPos[i] if(hasArg(newX)){ # if new x to be replaced.. rawfix$xPos[i]<- newX } if(hasArg(newY)){ # if new y to be replaced.. rawfix$yPos[i]<- newY } # new location on the screen: loc<- map[rawfix$yPos[i], rawfix$xPos[i]] rawfix$sent[i]<- coords$sent[loc] rawfix$word[i]<- coords$word[loc] rawfix$line[i]<- coords$line[loc] return(rawfix) } #--------------------------------------- # get some info about position of text: #--------------------------------------- ystart<- coords$y1[1] # start of first line on y-axis yend<- coords$y2[nrow(coords)] # end of last line on y-axis nlines<- max(coords$line) # number of lines in trial # start position of each line xstart<- matrix(nrow = nlines, ncol = 2, data = 0) xstart[1:nlines,1]<- 1:nlines ystart<- matrix(nrow = nlines, ncol = 2, data = 0) ystart[1:nlines,1]<- 1:nlines # end position of each line xend<- matrix(nrow = nlines, ncol = 2, data = 0) xend[1:nlines,1]<- 1:nlines yend<- matrix(nrow = nlines, ncol = 2, data = 0) yend[1:nlines,1]<- 1:nlines for(i in 1:nlines){ a<- subset(coords, line==i) xstart[i,2]<- a$x1[1] xend[i,2]<- a$x2[nrow(a)] ystart[i,2]<- a$y1[1] yend[i,2]<- a$y2[1] } #################################################### # Process fixations here: # #################################################### rawfix$pRS<- NULL rawfix$pSL<- NULL # prob fixation is still on the same line rawfix$reAligned<- 0 rawfix$prevX<- NA rawfix$prevY<- NA rawfix$prevLine<- NA # check first fixation: curr_line<- 1 # start at line 1 (assuming gaze box) if(rawfix$line[1]!=1){ if(rawfix$yPos[1]< ystart[1,2]){ # first fix is above first one rawfix<- reMap(rawfix, 1, map, coords, newY= ystart[1,2]+1) } if(rawfix$yPos[1]> yend[1,2]){ # first fix is below first line rawfix<- reMap(rawfix, 1, map, coords, newY= yend[1,2]-1) } } ## Calculate probability of return sweep for each fixation: for(i in 1:nrow(rawfix)){ rawfix$pRS[i]<- RS(i, rawfix, coords) } for(i in 1:nrow(rawfix)){ rawfix$pSL[i]<- SL(i, rawfix, coords, curr_line, xstart, xend) if(!is.na(rawfix$line[i])){ curr_line<- rawfix$line[i] } } return(rawfix) }
9a1968c2f4af0c9233aae705ce9d034b3e9d11ff
9edbb0f6dab00623bd0b0042062e0201042090f0
/man/plot.detectOutlier.Rd
7aeee4cff5a07698374e73bb3d9f9fa03567ce3a
[]
no_license
bozenne/butils
87161bb1e31570984f5a80e00d783f59297516fb
358a62cb656bf0b8ac335e71bf8b79102b458d8e
refs/heads/master
2023-07-23T10:19:58.756236
2023-07-18T13:00:10
2023-07-18T13:00:10
63,180,644
0
0
null
null
null
null
UTF-8
R
false
true
385
rd
plot.detectOutlier.Rd
% Generated by roxygen2: do not edit by hand % Please edit documentation in R/plot.detectOutlier.R \name{plot.detectOutlier} \alias{plot.detectOutlier} \title{plot function for detectOutlier objects} \usage{ \method{plot}{detectOutlier}(x, ...) } \arguments{ \item{x}{an object of class detectOutlier.} \item{...}{not used.} } \description{ plot function for detectOutlier objects. }
adc9e204ff79d031db95fff6c6064583bf63034c
f57f1f4c562cde9d39539bc3186c8eed3b6f54e0
/man/selectLambda.Rd
c4d7e05b0a09056e99a8a0057d5bd1b2e0c02501
[]
no_license
ChristianGoueguel/rospca
0a8905c686ad83a24ad4b081c924bd4ad1539a44
6631abbd32845558160bf682ac992be018768643
refs/heads/master
2023-03-19T03:37:37.298457
2018-10-20T15:46:39
2018-10-20T15:46:39
null
0
0
null
null
null
null
UTF-8
R
false
false
5,311
rd
selectLambda.Rd
\name{selectLambda} \alias{selectLambda} %- Also NEED an '\alias' for EACH other topic documented here. \title{ Selection of sparsity parameter using IC } \description{ Selection of the sparsity parameter for ROSPCA and SCoTLASS using BIC of Hubert et al. (2016), and for SRPCA using BIC of Croux et al. (2013). } \usage{ selectLambda(X, k, kmax = 10, method = "ROSPCA", lmin = 0, lmax = 2, lstep = 0.02, alpha = 0.75, stand = TRUE, skew = FALSE, multicore = FALSE, mc.cores = NULL, P = NULL, ndir = "all") } %- maybe also 'usage' for other objects documented here. \arguments{ \item{X}{An \eqn{n} by \eqn{p} matrix or data matrix with observations in the rows and variables in the columns.} \item{k}{ Number of Principal Components (PCs). } \item{kmax}{ Maximal number of PCs to be computed, only used when \code{method = "ROSPCA"} or \code{method = "ROSPCAg"}. Default is 10.} \item{method}{ PCA method to use: ROSPCA (\code{"ROSPCA"} or \code{"ROSPCAg"}), SCoTLASS (\code{"SCoTLASS"} or \code{"SPCAg"}) or SRPCA (\code{"SRPCA"}). Default is \code{"ROSPCA"}. } \item{lmin}{ Minimal value of \eqn{\lambda} to look at, default is 0. } \item{lmax}{ Maximal value of \eqn{\lambda} to look at, default is 2. } \item{lstep}{ Difference between two consecutive values of \eqn{\lambda}, i.e. the step size, default is 0.02. } \item{alpha}{ Robustness parameter for ROSPCA, default is 0.75. } \item{stand}{ Logical indicating if the data should be standardised, default is \code{TRUE}. } \item{skew}{ Logical indicating if the skewed version of ROSPCA should be applied, default is \code{FALSE}. } \item{multicore}{ Logical indicating if multiple cores can be used, default is \code{TRUE}. Note that this is not possible for the Windows platform, so \code{multicore} is always \code{FALSE} there. } \item{mc.cores}{ Number of cores to use if \code{multicore=TRUE}, default is \code{NULL} which corresponds to the number of cores minus 1. } \item{P}{ True loadings matrix, a numeric matrix of size \eqn{p} by \eqn{k}. The default is \code{NULL} which means that no true loadings matrix is specified. } \item{ndir}{Number of directions used when computing the outlyingness (or the adjusted outlyingness when \code{skew=TRUE}) in \code{rospca}, see \code{\link[mrfDepth]{outlyingness}} and \code{\link[mrfDepth]{adjOutl}} for more details. } } \details{ We select an optimal value of \eqn{\lambda} for a certain method on a certain dataset by looking at an equidistant grid of \eqn{\lambda} values. For each value of \eqn{\lambda}, we apply the method on the dataset using this sparsity parameter, and compute an Information Criterion (IC). The optimal value of \eqn{\lambda} is then the one corresponding to the minimal IC. The ICs we consider are the BIC of for Hubert et al. (2016) for ROSPCA and SCoTLASS, and the BIC of Croux et al. (2013) for SRPCA. The BIC of Hubert et al. (2016) is defined as \deqn{BIC(\lambda)=\ln(1/(h_1p)\sum_{i=1}^{h_1} OD^2_{(i)}(\lambda))+df(\lambda)\ln(h_1p)/(h_1p),} where \eqn{h_1} is the size of \eqn{H_1} (the subset of observations that are kept in the non-sparse reweighting step) and \eqn{OD_{(i)}(\lambda)} is the \eqn{i}th smallest orthogonal distance for the model when using \eqn{\lambda} as the sparsity parameter. The degrees of freedom \eqn{df(\lambda)} are the number of non-zero loadings when \eqn{\lambda} is used as the sparsity parameter. } \value{ A list with components:\cr \item{opt.lambda}{Value of \eqn{\lambda} corresponding to minimal IC.} \item{min.IC}{Minimal value of IC.} \item{Lambda}{Numeric vector containing the used values of \eqn{\lambda}.} \item{IC}{Numeric cector containing the IC values corresponding to all values of \eqn{\lambda} in \code{Lambda}.} \item{loadings}{Loadings obtained using method with sparsity parameter \code{opt.lambda}, a numeric matrix of size \eqn{p} by \eqn{k}.} \item{fit}{Fit obtained using method with sparsity parameter \code{opt.lambda}. This is a list containing the loadings (\code{loadings}), the eigenvalues (\code{eigenvalues}), the standardised data matrix used as input (\code{Xst}), the scores matrix (\code{scores}), the orthogonal distances (\code{od}) and the score distances (\code{sd}).} \item{type}{Type of IC used: \code{BICod} (BIC of Hubert et al. (2016)) or \code{BIC} (BIC of Croux et al. (2013)).} \item{measure}{A numeric vector containing the standardised angles between the true and the estimated loadings matrix for each value of \eqn{\lambda} if a loadings matrix is given. When no loadings matrix is given as input (\code{P=NULL}), \code{measure} is equal to \code{NULL}.} } \references{ Hubert, M., Reynkens, T., Schmitt, E. and Verdonck, T. (2016). ``Sparse PCA for High-Dimensional Data with Outliers,'' \emph{Technometrics}, 58, 424--434. Croux, C., Filzmoser, P., and Fritz, H. (2013), ``Robust Sparse Principal Component Analysis,'' \emph{Technometrics}, 55, 202--214. } \author{ Tom Reynkens } \seealso{ \link{selectPlot}, \link[parallel]{mclapply}, \link{angle} } \examples{ X <- dataGen(m=1, n=100, p=10, eps=0.2, bLength=4)$data[[1]] sl <- selectLambda(X, k=2, method="ROSPCA", lstep=0.1) selectPlot(sl) } % Add one or more standard keywords, see file 'KEYWORDS' in the % R documentation directory. \keyword{ optimize }
11d39c244a78f8767bb383fb873d58cb11758b7f
22057bf4f2eb001f739761e53a5578de578e6920
/2D_model_initial_setup/field.statistics.R
a90fed6b288f36408f3512475ce4929608602a8a
[]
no_license
mrubayet/archived_codes_for_sfa_modeling
3e26d9732f75d9ea5e87d4d4a01974230e0d61da
f300fe8984d1f1366f32af865e7d8a5b62accb0d
refs/heads/master
2020-07-01T08:16:17.425365
2019-08-02T21:47:18
2019-08-02T21:47:18
null
0
0
null
null
null
null
UTF-8
R
false
false
20,521
r
field.statistics.R
rm(list = ls()) library(rhdf5) library(BurStFin) #for partial.rainbow H5close() load("results/general.r") case.name='heat2.1' obs.time = seq(1,960) ntime = length(obs.time) load(paste("results/",case.name,".x.velocity",sep='')) load(paste("results/",case.name,".z.velocity",sep='')) load(paste("results/",case.name,".hydraulic.head",sep='')) #load(paste("results/",case.name,".ch2o.conc",sep='')) #load(paste("results/",case.name,".h.conc",sep='')) #load(paste("results/",case.name,".hco3.conc",sep='')) #load(paste("results/",case.name,".n2.conc",sep='')) #load(paste("results/",case.name,".no3.conc",sep='')) #load(paste("results/",case.name,".o2.conc",sep='')) load(paste("results/",case.name,".tracer.conc",sep='')) tracer.conc = tracer.conc/35.453 load(paste("results/",case.name,".elevation.field",sep='')) river.gradients=as.matrix(read.table(paste("field.5/",case.name,"/Gradients_River2015.txt",sep=''))) river.level=as.matrix(read.table(paste("field.5/",case.name,"/DatumH_River2015.txt",sep=''))) #river.gradients = river.gradients[(10*24+1):dim(river.gradients)[1],] #river.level = river.level[(10*24+1):dim(river.level)[1],] east.level=array(2*dim(river.level)[1],dim=c(dim(river.level)[1],2)) ##east.level[,1]=river.level[,1]/3600/24-9 east.level[,1]=river.level[,1]/3600-240 east.level[,2]=(y.new-river.level[,3])*river.gradients[,3]+river.level[,4] well.level=as.matrix(read.table(paste("field.5/",case.name,"/DatumH_West2015.txt",sep=""))) #well.level = well.level[(10*24+1):dim(river.level)[1],] west.level=array(2*dim(well.level)[1],dim=c(dim(well.level)[1],2)) ##west.level[,1]=well.level[,1]/3600/24-9 west.level[,1]=well.level[,1]/3600-240 west.level[,2]=well.level[,4] #creat new material id material_ids.new=h5read(paste("field.5/",case.name,"/Plume_Slice_AdaptiveRes_material.h5",sep=''),"Materials/Material Ids") material_ids.new=array(material_ids.new,c(nx.new,ny.new,nz.new)) material_ids.reverse=material_ids.new #find river.bank mud.hanford=NULL for (iz in nz.new:2) { for (ix in nx.new:2) { if (((material_ids.new[ix,1,iz]-material_ids.new[ix,1,(iz-1)])==4) || ((material_ids.new[ix,1,iz]-material_ids.new[(ix-1),1,iz])==4)) { mud.hanford=rbind(mud.hanford,c(ix,iz)) } } } mud.hanford = mud.hanford[order(mud.hanford[,1]),] hanford.ringold=NULL for (iz in nz.new:2) { for (ix in (nx.new-1):2) { if (((material_ids.new[ix,1,iz]-material_ids.new[ix,1,(iz-1)])==-3) || ((material_ids.new[ix,1,iz]-material_ids.new[(ix-1),1,iz])==-3) || ((material_ids.new[ix,1,iz]-material_ids.new[(ix+1),1,iz])==-3)) { hanford.ringold=rbind(hanford.ringold,c(ix,iz)) } } } hanford.ringold = hanford.ringold[order(hanford.ringold[,1]),] ## header = names(h5.data[[obs.time[1]]][[3]]) ## simu.col=grep("Material_ID",header) ## simu.results = h5.data[[obs.time[1]]][[3]][[simu.col]] ## simu.results = aperm(simu.results,c(3,1,2)) ## simu.results = simu.results[,,] #elevation.field=t(replicate(nx.new,z.new)) #elevation.field[simu.results==0]=0 obs.type = c("X-Velocity", "Y-Velocity", "Z-Velocity", "Liquid_Pressure", "Liquid_Saturation", "Material_ID", "Total_CH2O(aq)", #12.0107 "Total_H+", #1.00794 "Total_HCO3-", #12.0107 "Total_N2(aq)", #28.0134 "Total_NO3- [M]", #62.005 "Total_Total_O2(aq)", #31.9988 "Tracer ") for (itime in 1:ntime){ print(itime) jpeg.name = paste("figures/",case.name,".",formatC((itime),width = 3,flag = "0"), "_hydraulic.head",".jpg",sep = "") jpeg(jpeg.name,width = 12,height = 2.58,units = "in",res = 300, quality = 100) par(xpd=TRUE,mgp=c(2.,0.6,0),mar=c(4.1,4.1,2.1,2.1)) filled.contour(x.new,z.new,hydraulic.head[,,itime], ylim = c(bottom.new,top.new), xlim = c(west.new,east.new), zlim = range(hydraulic.head[hydraulic.head>100]), color.palette = terrain.colors, xlab = "Rotated east-west direction (m)", ylab = "Elevation (m)", main = paste("Hydraulic head : t =",itime,"hour"), asp = 1.0, plot.axes = { axis(1,cex.axis = 1.) axis(2,cex.axis = 1.) lines(x.new[river.bank.x]-0.5*0.1,z.new[river.bank.z]-0.5*0.05, col = 'black',lwd = 0.5) lines(x.new[mud.hanford[,1]]-0.5*0.1,z.new[mud.hanford[,2]]-0.5*0.05, col = "black", lwd = 0.5) lines(x.new[hanford.ringold[,1]],z.new[hanford.ringold[,2]],lwd = 0.5) x.index = rep(seq(1,nx.new),nz.new) z.index = rep(seq(1,nz.new),each = nx.new) ## x.index = x.index[hydraulic.head[,,itime]<0][which(elevation.field[hydraulic.head[,,itime]<0]>0)] ## z.index = z.index[hydraulic.head[,,itime]<0][which(elevation.field[hydraulic.head[,,itime]<0]>0)] x.index = x.index[intersect(which(hydraulic.head[,,itime]<elevation.field),which(elevation.field>0))] z.index = z.index[intersect(which(hydraulic.head[,,itime]<elevation.field),which(elevation.field>0))] # z.index = z.index[hydraulic.head[,,itime]<elevation.field] x.vadose = unique(x.index) x.vadose = sort(x.vadose) z.vadose = rep(0,length(x.vadose)) j=1 for (i in 1:length(x.vadose)) { z.vadose[i] = min(z.index[x.index==x.vadose[i]]) j=j+1 } lines(x.new[x.vadose],z.new[z.vadose],lty = 2,lwd = 0.5) current.west.level = west.level[which.min(abs(west.level[,1]-obs.time[itime])),2] current.east.level = east.level[which.min(abs(east.level[,1]-obs.time[itime])),2] current.east.interface = x.new[river.bank.x[which.min(abs(z.new[river.bank.z]- current.east.level))]] lines(c(current.east.interface,east.new),rep(current.east.level,2),col = "blue",lwd = 0.8) points(east.new,current.west.level,col = "black",pch = 16) text((east.new-10),current.east.level+2, paste("dh =", formatC(current.east.level-current.west.level,digits=2,format="e"),"m"), col="black") } ) dev.off() ## jpeg.name = paste("figures/",case.name,formatC((itime),width = 3,flag = "0"), ## "_CH2O",".jpg",sep = "") ## jpeg(jpeg.name,width = 12,height = 2.58,units = "in",res = 300, quality = 100) ## par(xpd=TRUE,mgp=c(2.,0.6,0),mar=c(4.1,4.1,2.1,2.1)) ## filled.contour(x.new,z.new,ch2o.conc[,,itime], ## ylim = c(bottom.new,top.new), ## xlim = c(west.new,east.new), ## zlim= range(ch2o.conc), ## color = function(x)rev(heat.colors(x)), ## xlab = "Rotated east-west direction (m)", ## ylab = expression("CH"[2]*"O (mg/L)"), ## main = bquote("CH"[2]*"O : t =" ~.(obs.time[itime]) ~ "day" ), ## asp = 1.0, ## plot.axes = { ## axis(1,cex.axis = 1.) ## axis(2,cex.axis = 1.) ## lines(x.new[river.bank.x]-0.5*0.1,z.new[river.bank.z]-0.5*0.05, ## col = 'black',lwd = 0.5) ## lines(x.new[mud.hanford[,1]]-0.5*0.1,z.new[mud.hanford[,2]]-0.5*0.05, ## col = "black", lwd = 0.5) ## lines(x.new[hanford.ringold[,1]],z.new[hanford.ringold[,2]],lwd = 0.5) ## lines(x.new[x.vadose],z.new[z.vadose],lty = 2,lwd = 0.5) ## lines(c(current.east.interface,east.new),rep(current.east.level,2),col = "blue",lwd = 0.8) ## points(east.new,current.west.level,col = "black",pch = 16) ## text((east.new-10),current.east.level+2, ## paste("dh =", ## formatC(current.east.level-current.west.level,digits=2,format="e"),"m"), ## col="black") ## } ## ) ## dev.off() ## jpeg.name = paste("figures/",case.name,formatC((itime),width = 3,flag = "0"), ## "_H+",".jpg",sep = "") ## jpeg(jpeg.name,width = 12,height = 2.58,units = "in",res = 300, quality = 100) ## par(xpd=TRUE,mgp=c(2.,0.6,0),mar=c(4.1,4.1,2.1,2.1)) ## filled.contour(x.new,z.new,h.conc[,,itime], ## ylim = c(bottom.new,top.new), ## xlim = c(west.new,east.new), ## zlim = range(h.conc), ## color = function(x)rev(heat.colors(x)), ## xlab = "Rotated east-west direction (m)", ## ylab = expression("H+ (mg/L)"), ## main = bquote("H+ : t =" ~.(obs.time[itime]) ~ "day" ), ## asp = 1.0, ## plot.axes = { ## axis(1,cex.axis = 1.) ## axis(2,cex.axis = 1.) ## lines(x.new[river.bank.x]-0.5*0.1,z.new[river.bank.z]-0.5*0.05, ## col = 'black',lwd = 0.5) ## lines(x.new[mud.hanford[,1]]-0.5*0.1,z.new[mud.hanford[,2]]-0.5*0.05, ## col = "black", lwd = 0.5) ## lines(x.new[hanford.ringold[,1]],z.new[hanford.ringold[,2]],lwd = 0.5) ## lines(x.new[x.vadose],z.new[z.vadose],lty = 2,lwd = 0.5) ## lines(c(current.east.interface,east.new),rep(current.east.level,2),col = "blue",lwd = 0.8) ## points(east.new,current.west.level,col = "black",pch = 16) ## text((east.new-10),current.east.level+2, ## paste("dh =", ## formatC(current.east.level-current.west.level,digits=2,format="e"),"m"), ## col="black") ## } ## ) ## dev.off() ## jpeg.name = paste("figures/",case.name,formatC((itime),width = 3,flag = "0"), ## "_HCO3-",".jpg",sep = "") ## jpeg(jpeg.name,width = 12,height = 2.58,units = "in",res = 300, quality = 100) ## par(xpd=TRUE,mgp=c(2.,0.6,0),mar=c(4.1,4.1,2.1,2.1)) ## filled.contour(x.new,z.new,hco3.conc[,,itime], ## ylim = c(bottom.new,top.new), ## xlim = c(west.new,east.new), ## zlim = range(hco3.conc), ## color = function(x)rev(heat.colors(x)), ## xlab = "Rotated east-west direction (m)", ## ylab = expression("HCO"[3]*"- (mg/L)"), ## main = bquote("HCO"[3]*"- : t =" ~.(obs.time[itime]) ~ "day" ), ## asp = 1.0, ## plot.axes = { ## axis(1,cex.axis = 1.) ## axis(2,cex.axis = 1.) ## lines(x.new[river.bank.x]-0.5*0.1,z.new[river.bank.z]-0.5*0.05, ## col = 'black',lwd = 0.5) ## lines(x.new[mud.hanford[,1]]-0.5*0.1,z.new[mud.hanford[,2]]-0.5*0.05, ## col = "black", lwd = 0.5) ## lines(x.new[hanford.ringold[,1]],z.new[hanford.ringold[,2]],lwd = 0.5) ## lines(x.new[x.vadose],z.new[z.vadose],lty = 2,lwd = 0.5) ## lines(c(current.east.interface,east.new),rep(current.east.level,2),col = "blue",lwd = 0.8) ## points(east.new,current.west.level,col = "black",pch = 16) ## text((east.new-10),current.east.level+2, ## paste("dh =", ## formatC(current.east.level-current.west.level,digits=2,format="e"),"m"), ## col="black") ## } ## ) ## dev.off() ## jpeg.name = paste("figures/",case.name,formatC((itime),width = 3,flag = "0"), ## "_N2",".jpg",sep = "") ## jpeg(jpeg.name,width = 12,height = 2.58,units = "in",res = 300, quality = 100) ## par(xpd=TRUE,mgp=c(2.,0.6,0),mar=c(4.1,4.1,2.1,2.1)) ## filled.contour(x.new,z.new,n2.conc[,,itime], ## ylim = c(bottom.new,top.new), ## xlim = c(west.new,east.new), ## zlim = range(n2.conc), ## color = function(x)rev(heat.colors(x)), ## xlab = "Rotated east-west direction (m)", ## ylab = expression("N"[2]*" (mg/L)"), ## main = bquote("N"[2]*" concentration : t =" ~.(obs.time[itime]) ~ "day" ), ## asp = 1.0, ## plot.axes = { ## axis(1,cex.axis = 1.) ## axis(2,cex.axis = 1.) ## lines(x.new[river.bank.x]-0.5*0.1,z.new[river.bank.z]-0.5*0.05, ## col = 'black',lwd = 0.5) ## lines(x.new[mud.hanford[,1]]-0.5*0.1,z.new[mud.hanford[,2]]-0.5*0.05, ## col = "black", lwd = 0.5) ## lines(x.new[hanford.ringold[,1]],z.new[hanford.ringold[,2]],lwd = 0.5) ## lines(x.new[x.vadose],z.new[z.vadose],lty = 2,lwd = 0.5) ## lines(c(current.east.interface,east.new),rep(current.east.level,2),col = "blue",lwd = 0.8) ## points(east.new,current.west.level,col = "black",pch = 16) ## text((east.new-10),current.east.level+2, ## paste("dh =", ## formatC(current.east.level-current.west.level,digits=2,format="e"),"m"), ## col="black") ## } ## ) ## dev.off() ## jpeg.name = paste("figures/",case.name,formatC((itime),width = 3,flag = "0"), ## "_NO3-",".jpg",sep = "") ## jpeg(jpeg.name,width = 12,height = 2.58,units = "in",res = 300, quality = 100) ## par(xpd=TRUE,mgp=c(2.,0.6,0),mar=c(4.1,4.1,2.1,2.1)) ## filled.contour(x.new,z.new,no3.conc[,,itime], ## ylim = c(bottom.new,top.new), ## xlim = c(west.new,east.new), ## zlim = range(no3.conc), ## color = function(x)rev(heat.colors(x)), ## xlab = "Rotated east-west direction (m)", ## ylab = expression("NO"[3]*"- (mg/L)"), ## main = bquote("NO"[3]*"- : t =" ~.(obs.time[itime]) ~ "day" ), ## asp = 1.0, ## plot.axes = { ## axis(1,cex.axis = 1.) ## axis(2,cex.axis = 1.) ## lines(x.new[river.bank.x]-0.5*0.1,z.new[river.bank.z]-0.5*0.05, ## col = 'black',lwd = 0.5) ## lines(x.new[mud.hanford[,1]]-0.5*0.1,z.new[mud.hanford[,2]]-0.5*0.05, ## col = "black", lwd = 0.5) ## lines(x.new[hanford.ringold[,1]],z.new[hanford.ringold[,2]],lwd = 0.5) ## lines(x.new[x.vadose],z.new[z.vadose],lty = 2,lwd = 0.5) ## lines(c(current.east.interface,east.new),rep(current.east.level,2),col = "blue",lwd = 0.8) ## points(east.new,current.west.level,col = "black",pch = 16) ## text((east.new-10),current.east.level+2, ## paste("dh =", ## formatC(current.east.level-current.west.level,digits=2,format="e"),"m"), ## col="black") ## } ## ) ## dev.off() ## jpeg.name = paste("figures/",case.name,formatC((itime),width = 3,flag = "0"), ## "_O2",".jpg",sep = "") ## jpeg(jpeg.name,width = 12,height = 2.58,units = "in",res = 300, quality = 100) ## par(xpd=TRUE,mgp=c(2.,0.6,0),mar=c(4.1,4.1,2.1,2.1)) ## filled.contour(x.new,z.new,o2.conc[,,itime], ## ylim = c(bottom.new,top.new), ## xlim = c(west.new,east.new), ## zlim = range(o2.conc), ## color = function(x)rev(heat.colors(x)), ## xlab = "Rotated east-west direction (m)", ## ylab = expression("O"[2]*" (mg/L)"), ## main = bquote("O"[2]*" concentration : t =" ~.(obs.time[itime]) ~ "day" ), ## asp = 1.0, ## plot.axes = { ## axis(1,cex.axis = 1.) ## axis(2,cex.axis = 1.) ## lines(x.new[river.bank.x]-0.5*0.1,z.new[river.bank.z]-0.5*0.05, ## col = 'black',lwd = 0.5) ## lines(x.new[mud.hanford[,1]]-0.5*0.1,z.new[mud.hanford[,2]]-0.5*0.05, ## col = "black", lwd = 0.5) ## lines(x.new[hanford.ringold[,1]],z.new[hanford.ringold[,2]],lwd = 0.5) ## lines(x.new[x.vadose],z.new[z.vadose],lty = 2,lwd = 0.5) ## lines(c(current.east.interface,east.new),rep(current.east.level,2),col = "blue",lwd = 0.8) ## points(east.new,current.west.level,col = "black",pch = 16) ## text((east.new-10),current.east.level+2, ## paste("dh =", ## formatC(current.east.level-current.west.level,digits=2,format="e"),"m"), ## col="black") ## } ## ) ## dev.off() jpeg.name = paste("figures/",case.name,".",formatC((itime),width = 3,flag = "0"), "_Tracer",".jpg",sep = "") jpeg(jpeg.name,width = 12,height = 2.58,units = "in",res = 300, quality = 100) par(xpd=TRUE,mgp=c(2.,0.6,0),mar=c(4.1,4.1,2.1,2.1)) filled.contour(x.new,z.new,tracer.conc[,,itime], ylim = c(bottom.new,top.new), xlim = c(west.new,east.new), zlim = range(tracer.conc), color = function(x)rev(heat.colors(x)), xlab = "Rotated east-west direction (m)", ylab = expression("Tracer (mg/l)"), main = bquote("Tracer : t =" ~.(obs.time[itime]) ~ "hour" ), asp = 1.0, plot.axes = { axis(1,cex.axis = 1.) axis(2,cex.axis = 1.) lines(x.new[river.bank.x]-0.5*0.1,z.new[river.bank.z]-0.5*0.05, col = 'black',lwd = 0.5) lines(x.new[mud.hanford[,1]]-0.5*0.1,z.new[mud.hanford[,2]]-0.5*0.05, col = "black", lwd = 0.5) lines(x.new[hanford.ringold[,1]],z.new[hanford.ringold[,2]],lwd = 0.5) lines(x.new[x.vadose],z.new[z.vadose],lty = 2,lwd = 0.5) lines(c(current.east.interface,east.new),rep(current.east.level,2),col = "blue",lwd = 0.8) points(east.new,current.west.level,col = "black",pch = 16) text((east.new-10),current.east.level+2, paste("dh =", formatC(current.east.level-current.west.level,digits=2,format="e"),"m"), col="black") } ) dev.off() }
16bfa68e757cbac33ddaeadff5505489e2b24379
e55359349183a5c8547f624c628e59f8d378f618
/SLX-12998_mmhs/peaks/SLX-12998.D707_D507.HH772BBXX.s_2.r_1.fq.gz_model.r
112de3c8d12f1200e265370cee0440c18c75f4c4
[]
no_license
andrewholding/BrundleDevelopment
701d011546cdce0c3033a9a4f91357fa629e609a
46034028558886f0c442f329ded61969b12c023d
refs/heads/master
2021-01-17T19:15:48.543303
2018-02-20T16:28:53
2018-02-20T16:28:53
95,553,226
5
0
null
null
null
null
UTF-8
R
false
false
78,110
r
SLX-12998.D707_D507.HH772BBXX.s_2.r_1.fq.gz_model.r
# R script for Peak Model # -- generated by MACS p <- c(0.0380848212526,0.0446991644003,0.051030211659,0.0577307752946,0.0637046233889,0.0635691340507,0.0637538922392,0.0633720586496,0.0639263332151,0.0636184029009,0.0639632848528,0.0637662094517,0.0635198652004,0.0635691340507,0.0639140160025,0.0645298766308,0.0643081668046,0.0645298766308,0.0643204840172,0.0648747585826,0.064948661858,0.0648870757952,0.0652689093847,0.0651087856214,0.0649240274329,0.063815478302,0.0635937684758,0.0632981553742,0.0633227897994,0.0635075479879,0.0634582791376,0.063445961925,0.0633104725868,0.0632242520989,0.0636430373261,0.0639756020654,0.0641110914036,0.0642219463167,0.0642342635292,0.0636060856884,0.0631749832486,0.0629902250601,0.0629779078475,0.0625344881952,0.0624482677072,0.0630887627606,0.063248886524,0.0631503488235,0.063248886524,0.0635814512633,0.0637785266643,0.0639509676402,0.0646407315439,0.0655275708486,0.0656384257617,0.0657862323125,0.0654167159355,0.0661064798392,0.0664020929408,0.0666607544046,0.06673465768,0.0668824642308,0.0662912380277,0.0660941626266,0.0660818454141,0.0657000118245,0.0663158724528,0.0659833077135,0.0660448937764,0.0662666036025,0.0666484371921,0.0669317330811,0.067104174057,0.0670302707816,0.0667592921052,0.0672642978203,0.0672889322455,0.0666853888298,0.0667962437429,0.0665991683418,0.0664759962162,0.0660818454141,0.0664883134287,0.0666977060423,0.0671288084821,0.0665129478538,0.0663158724528,0.0669810019313,0.0665868511292,0.0663528240905,0.0662050175397,0.0664883134287,0.0660572109889,0.0659833077135,0.0659833077135,0.0661557486894,0.0652073233219,0.0648747585826,0.0650595167711,0.0651703716842,0.0652196405345,0.0651703716842,0.0652442749596,0.0649363446455,0.0649363446455,0.0651826888968,0.0655645224863,0.065884770013,0.0659463560758,0.0662419691774,0.0657000118245,0.0659217216507,0.0656384257617,0.0655522052737,0.0656137913366,0.0652812265973,0.065515253636,0.0657492806748,0.0655768396989,0.065601474124,0.0658724528004,0.0653551298727,0.0656261085491,0.0656630601868,0.0658108667376,0.0654783019983,0.0660202593512,0.065687694612,0.065601474124,0.0651087856214,0.0653551298727,0.0655891569114,0.0657615978874,0.0658108667376,0.065515253636,0.0657615978874,0.0653920815104,0.0650471995586,0.0654906192109,0.0659956249261,0.0655891569114,0.065404398723,0.0652073233219,0.0653920815104,0.0657123290371,0.065970990501,0.0661803831146,0.0663897757282,0.0658970872256,0.0656630601868,0.0663158724528,0.0669070986559,0.0665745339167,0.0666114855544,0.0663158724528,0.0661803831146,0.065884770013,0.0664883134287,0.0665006306413,0.0668331953806,0.0664390445785,0.0669070986559,0.0677200346853,0.0680033305743,0.0680525994245,0.068323578101,0.0684590674392,0.0684590674392,0.06860687399,0.0684097985889,0.0689517559418,0.0689148043041,0.068803949391,0.0683851641638,0.0679417445115,0.0682866264633,0.0683851641638,0.0682127231879,0.0686191912026,0.0683605297387,0.0683112608884,0.0677939379607,0.0677939379607,0.0678308895984,0.0683605297387,0.0678555240235,0.0680895510622,0.0679047928738,0.067104174057,0.0679786961491,0.0676338141973,0.0676830830476,0.067104174057,0.0670425879942,0.0672889322455,0.0678924756612,0.0683728469512,0.0686684600528,0.0700110362225,0.0697893263963,0.0697523747586,0.0696784714832,0.0701218911355,0.0706638484884,0.0702204288361,0.0696538370581,0.0696045682078,0.069456761657,0.0690502936423,0.0690256592172,0.0694074928067,0.0694444444444,0.0697031059083,0.0694074928067,0.0698632296717,0.0704051870246,0.0701465255607,0.0704175042371,0.0708116550392,0.0708978755272,0.0712550746916,0.0707993378267,0.070873241102,0.070873241102,0.0701711599858,0.069826278034,0.0697523747586,0.0692227346183,0.068520653502,0.0680895510622,0.0676091797722,0.0682989436759,0.0683358953135,0.0684713846518,0.06860687399,0.0689271215167,0.0693335895314,0.0701957944109,0.0707008001261,0.0710579992905,0.0713043435418,0.0714151984549,0.0711072681408,0.0718463008947,0.0723636238225,0.0724252098853,0.0723513066099,0.0722774033345,0.0719448385952,0.0718709353199,0.0718463008947,0.0721172795712,0.072178865634,0.0720433762958,0.0724252098853,0.0725360647984,0.0725114303733,0.0724128926727,0.0728932639628,0.0729302156005,0.0736938827796,0.0732627803398,0.0734475385282,0.0730657049387,0.0726099680738,0.0727947262623,0.0730903393638,0.0734721729534,0.0739894958811,0.0742358401324,0.0742604745576,0.0743466950455,0.0743959638958,0.0750734105869,0.0754798786016,0.0753197548382,0.0752088999251,0.074814749123,0.0744082811084,0.074161936857,0.0740633991565,0.0749871900989,0.0756276851523,0.0749871900989,0.0750610933743,0.0757878089157,0.0758001261283,0.0757878089157,0.0755414646644,0.0761573252927,0.0760095187419,0.0762435457806,0.075750857278,0.0764898900319,0.076686965433,0.0767731859209,0.0770072129597,0.0772781916361,0.0781773481534,0.0781527137283,0.0791134563084,0.0788178432068,0.0802835915021,0.0809610381932,0.0821681250246,0.0823405660006,0.0835846044697,0.0853213314414,0.0866023215482,0.0885607583461,0.0889672263608,0.0896323558393,0.0900018722163,0.09069163612,0.0907409049702,0.0916400614875,0.091911040164,0.0919479918017,0.0919849434394,0.0913321311734,0.0914799377242,0.0924899491545,0.0928717827441,0.092958003232,0.093241299121,0.0932659335462,0.0934014228844,0.0937093531985,0.0935738638603,0.0935492294352,0.0932166646959,0.0925761696425,0.0927116589807,0.0929826376572,0.0933398368216,0.093610815498,0.0940419179378,0.0938078908991,0.0934999605849,0.0939187458121,0.0947932679043,0.0950642465807,0.0950888810059,0.0957047416341,0.0953352252572,0.0955815695085,0.0957047416341,0.0960126719483,0.0968256079776,0.0973921997556,0.0976385440069,0.0990673406645,0.0993752709787,0.0983529423357,0.0996955185054,0.100089669307,0.100705529936,0.101124315163,0.101419928265,0.100680895511,0.101358342202,0.101001143037,0.100976508612,0.10192493398,0.101284438926,0.101124315163,0.10111199795,0.101321390564,0.101136632376,0.102011154468,0.101346024989,0.101025777462,0.101210535651,0.10144456269,0.102442256907,0.102442256907,0.102392988057,0.10240530527,0.103501537188,0.104117397816,0.104696306807,0.105583146112,0.106457668204,0.10624827559,0.106088151827,0.106876453431,0.107184383745,0.107849513224,0.107824878799,0.10764012061,0.10807122305,0.108145126325,0.108280615664,0.109179772181,0.109906487722,0.110300638524,0.110768692602,0.110891864727,0.111051988491,0.112049682709,0.112283709747,0.112332978598,0.11191419337,0.111667849119,0.111692483544,0.111741752394,0.111963462221,0.112382247448,0.112456150723,0.112209806472,0.11277639825,0.112985790864,0.113774092468,0.114279098183,0.113884947381,0.114488490797,0.114402270309,0.11464861456,0.114845689961,0.115116668637,0.115806432541,0.116644002996,0.11709973986,0.116644002996,0.117346084112,0.117493890663,0.118676343069,0.119242934847,0.119871112688,0.120523924954,0.120573193804,0.12084417248,0.121767963423,0.123344566631,0.12400969611,0.124083599385,0.124465432975,0.124724094439,0.1245886051,0.12444079855,0.124797997714,0.124687142801,0.124785680501,0.125155196878,0.125241417366,0.125783374719,0.125463127192,0.125943498483,0.126904241063,0.127064364826,0.126805703362,0.12775412873,0.127581687754,0.127717177092,0.12838230657,0.128985849986,0.129281463088,0.129958909779,0.12967561389,0.129897323716,0.130907335146,0.131449292499,0.132102104765,0.132237594104,0.133309191597,0.133481632573,0.133678707974,0.133062847345,0.134405423515,0.135784951322,0.135403117733,0.13582190296,0.135587875921,0.136191419337,0.135366166095,0.135846537385,0.136376177526,0.136942769304,0.136905817666,0.136659473415,0.137115210279,0.137669484845,0.138531689724,0.138876571676,0.138975109377,0.139467797879,0.140440857672,0.140724153561,0.141623310078,0.142226853494,0.142719541997,0.142226853494,0.142436246108,0.142731859209,0.143323085412,0.143446257538,0.143569429664,0.1434093059,0.142288439557,0.142534783808,0.143865042765,0.144197607505,0.144419317331,0.144480903394,0.145047495172,0.145084446809,0.145626404162,0.14619299594,0.147572523748,0.148040577825,0.147732647511,0.147301545071,0.148040577825,0.148422411415,0.148902782705,0.148890465492,0.149112175318,0.14950632612,0.149136809743,0.148668755666,0.14892741713,0.150183772811,0.148644121241,0.147794233574,0.14763410981,0.147905088487,0.147067518032,0.146919711482,0.146771904931,0.147350813921,0.146833490994,0.145995920539,0.146439340192,0.147067518032,0.145527866462,0.145059812384,0.145429328761,0.144431634543,0.143520160814,0.142633321509,0.141943557605,0.141512455165,0.141167573214,0.141401600252,0.141721847779,0.141352331402,0.140564029798,0.140921228962,0.140724153561,0.141032083875,0.141032083875,0.140674884711,0.141241476489,0.140650250286,0.140293051121,0.140145244571,0.140391588822,0.140280733909,0.1409581806,0.141241476489,0.141155256001,0.141241476489,0.140724153561,0.140687201923,0.141105987151,0.140256099484,0.139344625754,0.138876571676,0.138778033976,0.138162173348,0.137607898782,0.137509361082,0.137349237318,0.136856548816,0.135895806235,0.136634838989,0.136622521777,0.136918134878,0.136191419337,0.134996649718,0.134614816129,0.133814197312,0.133247605534,0.132397717867,0.132902723582,0.132188325253,0.131991249852,0.130402329431,0.129343049151,0.128579381972,0.128246817232,0.127815714792,0.126707165662,0.126768751724,0.125463127192,0.125376906705,0.122814926491,0.122346872413,0.121533936384,0.120388435615,0.118590122581,0.116816443971,0.115486185014,0.112837984313,0.111495408143,0.109364530369,0.108674766466,0.106999625557,0.10518899531,0.103686295377,0.103144338024,0.102085057743,0.101321390564,0.100791750424,0.10015125537,0.0993260021284,0.0991781955776,0.0989811201766,0.0991166095148,0.0996462496551,0.0992028300028,0.0986608726499,0.0977740333452,0.0975153718813,0.0970473178038,0.0964684088132,0.0957170588467,0.0952120531315,0.0958032793347,0.0953844941074,0.0944853375902,0.0942882621891,0.0941897244886,0.093610815498,0.0935738638603,0.0931673958457,0.0925269007922,0.0927732450436,0.0916646959127,0.0909502975839,0.0906423672697,0.0903590713807,0.0901989476174,0.0902112648299,0.0891519845493,0.0887824681723,0.0886716132592,0.0877847739545,0.0870580584131,0.0867870797367,0.0875014780655,0.0870457412006,0.0864914666351,0.086380611722,0.0862574395964,0.0862204879587,0.0861465846833,0.0856908478184,0.0854814552048,0.0844714437744,0.0832766741555,0.0825992274644,0.0825992274644,0.0821927594498,0.0823528832131,0.0819340979859,0.0815768988215,0.0811211619566,0.0805668873911,0.0809979898309,0.0807023767293,0.0812443340822,0.0807270111545,0.0803328603524,0.0791750423712,0.079322848922,0.0793474833471,0.079692365299,0.0790888218833,0.0788301604194,0.078472961255,0.0780049071775,0.0782019825785,0.0777216112885,0.0780664932403,0.0776107563754,0.0775245358874,0.0772781916361,0.0774259981869,0.0771427022979,0.0772658744236,0.0773397776989,0.0770195301722,0.0770564818099,0.0769579441094,0.0769579441094,0.0767855031335,0.0762804974183,0.076403669544,0.0765884277325,0.0762065941429,0.0765268416696,0.0763544006937,0.0761080564424,0.0761573252927,0.0759602498916,0.0758740294036,0.0758247605534,0.0752581687754,0.0750734105869,0.0745930392968,0.0738540065429,0.073681565567,0.0737554688424,0.0733736352528,0.0728070434748,0.0725114303733,0.0722281344843,0.0725114303733,0.0721665484214,0.0726222852864,0.0723389893973,0.0722035000591,0.0723143549722,0.0722158172717,0.0726961885617,0.0724867959481,0.0730410705136,0.0727824090497,0.072548382011,0.0725360647984,0.0724867959481,0.0721911828466,0.0715630050057,0.071526053368,0.071242757479,0.0708116550392,0.0702327460486,0.0704667730874,0.0707377517638,0.0702204288361,0.0702820148989,0.0707747034015,0.0709471443774,0.0709471443774,0.0700479878602,0.0699617673722,0.0699248157345,0.0700849394979,0.071045682078,0.0708609238895,0.0703559181743,0.0698878640968,0.0699617673722,0.0699001813094,0.0700849394979,0.0701711599858,0.070392869812,0.069542982145,0.0682619920382,0.0683605297387,0.0683605297387,0.0683851641638,0.0683482125261,0.0680033305743,0.0685822395649,0.0689640731544,0.0687793149659,0.0691241969177,0.0690133420047,0.0694690788696,0.0701218911355,0.0699617673722,0.0699864017973,0.0701588427732,0.0696784714832,0.0692720034685,0.069542982145,0.0691118797052,0.0694074928067,0.0693705411691,0.0685822395649,0.0685083362895,0.0683112608884,0.0684960190769,0.0688532182413,0.0689517559418,0.0687177289031,0.0696292026329,0.0692966378937,0.0694074928067,0.0698139608214,0.070109573923,0.0699371329471,0.0694813960821,0.0691118797052,0.0690749280675,0.0692473690434,0.0686930944779,0.0690010247921,0.0689887075795,0.0690133420047,0.0687546805408,0.068976390367,0.0693459067439,0.0693951755942,0.0690995624926,0.0689394387293,0.0690749280675,0.0687793149659,0.068040282212,0.067756986323,0.0680649166371,0.0680279649994,0.0676830830476,0.0675106420717,0.0674244215837,0.067387469946,0.0672150289701,0.0670672224193,0.0673751527334,0.0675352764968,0.0674490560088,0.0677077174727,0.0678678412361,0.0683482125261,0.0682004059753,0.0680772338497,0.0678678412361,0.0677939379607,0.0675229592842,0.0674367387963,0.0673135666706,0.0667716093177,0.0665745339167,0.0667592921052,0.0671411256947,0.0666853888298,0.0669686847188,0.0670795396319,0.0674367387963,0.0673751527334,0.067387469946,0.067670765835,0.0676830830476,0.0676091797722,0.0673628355209,0.0676954002601,0.0678678412361,0.0677446691104,0.0672150289701,0.0672273461826,0.0668824642308,0.0662912380277,0.0663405068779,0.0658108667376,0.0662173347523,0.0662173347523,0.0659340388633,0.06625428639,0.0661927003271,0.0665498994915,0.0665622167041,0.0670302707816,0.0669810019313,0.06625428639,0.0655768396989,0.0652442749596,0.065404398723,0.0652565921722,0.0655768396989,0.0652935438099,0.0652565921722,0.0651950061093,0.0651457372591,0.065970990501,0.0665991683418,0.0670056363565,0.0670056363565,0.06673465768,0.0668455125931,0.0670918568444,0.0673997871586,0.0669070986559,0.0667962437429,0.0670056363565,0.0669933191439,0.0664267273659,0.0659094044381,0.0663528240905,0.0659956249261,0.0656630601868,0.0658601355879,0.0659217216507,0.0660818454141,0.0654413503606,0.0647885380947,0.0653428126601,0.0654536675732,0.0648993930078,0.0651211028339,0.0648131725198,0.064012553703,0.0638647471523,0.0637169406015,0.0635814512633,0.0640248709156,0.0637538922392,0.0641357258287,0.0646284143313,0.0647639036695,0.0652442749596,0.0662050175397,0.0661064798392,0.0653674470853,0.0656630601868,0.0658231839502,0.0659463560758,0.0653428126601,0.0655522052737,0.065601474124,0.0652565921722,0.0646037799062,0.0643574356549,0.0650102479209,0.0653920815104,0.0651334200465,0.0650595167711,0.065601474124,0.0649363446455,0.0647023176067,0.0648993930078,0.0650964684088,0.0656630601868,0.0660202593512,0.0655891569114,0.0654413503606,0.0650595167711,0.0646900003942,0.0648993930078,0.0650595167711,0.0652196405345,0.0650595167711,0.0651087856214,0.0645914626936,0.0657739150999,0.0657739150999,0.0661803831146,0.0664144101533,0.0664020929408,0.0658478183753,0.0653058610224,0.0657246462497,0.0658724528004,0.0663158724528,0.0650964684088,0.065034882346,0.0645298766308,0.064468290568,0.0645545110559,0.0649979307083,0.0656753773994,0.0655029364235,0.0657246462497,0.0654783019983,0.0663405068779,0.0665745339167,0.0666361199795,0.0666853888298,0.0665745339167,0.0664759962162,0.0659463560758,0.0657615978874,0.0657123290371,0.0657369634622,0.0651211028339,0.0653058610224,0.065884770013,0.0662173347523,0.0658108667376,0.0656137913366,0.0662666036025,0.0666853888298,0.0666853888298,0.0673382010957,0.067301249458,0.0671164912696,0.0675599109219,0.0679417445115,0.0681880887628,0.0685576051397,0.0685576051397,0.0685083362895,0.067954061724,0.0675599109219,0.0675968625596,0.0675106420717,0.0669194158685,0.0657615978874,0.0660572109889,0.0659340388633,0.0653797642978,0.0647269520318,0.0651211028339,0.0646530487565,0.0647269520318,0.0644559733554,0.064098774191,0.064184994679,0.064012553703,0.0637169406015,0.0633227897994,0.063248886524,0.0631257143983,0.0633843758622,0.0637169406015,0.0641357258287,0.0646900003942,0.0645914626936,0.0646160971188,0.0645175594182,0.0646407315439,0.0648501241575,0.0648870757952,0.0647639036695,0.0645421938434,0.0644313389303,0.0638524299397,0.0642712151669,0.064098774191,0.0643081668046,0.0644929249931,0.0651950061093,0.065231957747,0.0654413503606,0.0653058610224,0.0653674470853,0.0659094044381,0.0665129478538,0.0664144101533,0.0663651413031,0.0665252650664,0.0658108667376,0.0657246462497,0.0655891569114,0.0656507429743,0.0655275708486,0.0654536675732,0.0653674470853,0.0654783019983,0.0660202593512,0.0661187970518,0.0663405068779,0.0668085609554,0.0671288084821,0.0666607544046,0.0666607544046,0.0661064798392,0.0656630601868,0.0661557486894,0.0659217216507,0.0660695282015,0.0657862323125,0.0653058610224,0.0650964684088,0.064948661858,0.0650718339837,0.0655891569114,0.0655275708486,0.0651826888968,0.0647639036695,0.0647639036695,0.0654906192109,0.0660941626266,0.0656630601868,0.065798549525,0.0660079421387,0.0660695282015,0.0660941626266,0.0661557486894,0.0662912380277,0.0657739150999,0.0648501241575,0.0650964684088,0.0656753773994,0.065798549525,0.0657739150999,0.0655522052737,0.0656630601868,0.0660572109889,0.0663528240905,0.0663528240905,0.0672273461826,0.0660941626266,0.0663528240905,0.0665745339167,0.0666361199795,0.0671534429073,0.0672396633952,0.0669194158685,0.0673628355209,0.0677816207481,0.0677939379607,0.068323578101,0.0682496748256,0.0687177289031,0.0681265026999,0.0680895510622,0.0679047928738,0.0682743092507,0.0675722281345,0.067190394545,0.066451361791,0.0664390445785,0.0668455125931,0.066451361791,0.0670302707816,0.0670425879942,0.0678924756612,0.0678185723858,0.0680033305743,0.0684221158015,0.068976390367,0.0684837018643,0.0676830830476,0.0676830830476,0.0675599109219,0.0672766150329,0.0667469748926,0.0666730716172,0.0665991683418,0.0664267273659,0.0663651413031,0.0666114855544,0.0664759962162,0.0663897757282,0.0665498994915,0.0663774585156,0.0659094044381,0.0658108667376,0.0657123290371,0.0653304954476,0.0653797642978,0.0648501241575,0.065404398723,0.0653551298727,0.0657123290371,0.0659217216507,0.0661311142643,0.0659833077135,0.0662419691774,0.0663035552402,0.065798549525,0.0662789208151,0.0660079421387,0.0663651413031,0.0658970872256,0.0654536675732,0.0654413503606,0.0654659847858,0.0657492806748,0.0664636790036,0.066537582279,0.067017953569,0.0670549052067,0.0667839265303,0.0664020929408,0.0669070986559,0.0669194158685,0.0671657601198,0.0676584486224,0.067387469946,0.0676338141973,0.0674367387963,0.0677323518978,0.0677077174727,0.0681880887628,0.067584545347,0.0679047928738,0.0675229592842,0.0663897757282,0.0664144101533,0.0662666036025,0.0663158724528,0.0662912380277,0.0664020929408,0.0664883134287,0.0673997871586,0.067584545347,0.0682866264633,0.0684097985889,0.0687300461156,0.0689640731544,0.0689271215167,0.0684097985889,0.0686438256277,0.0681388199125,0.0681141854874,0.0675722281345,0.0669194158685,0.0673505183083,0.0666977060423,0.0667469748926,0.0672889322455,0.0678308895984,0.0674490560088,0.0610194710496,0.0539617082496,0.0473473651019,0.0407699735919,0.0) m <- c(0.0395514630351,0.0465144888758,0.0529485215872,0.0595793889514,0.0661610476524,0.066788458108,0.0669852927608,0.0658534935075,0.0654844285336,0.0660257238287,0.0662348606472,0.0655951480258,0.0658042848443,0.0659519108339,0.0660503281603,0.0659150043365,0.0659642129997,0.067096012253,0.0668253646054,0.0659888173313,0.0655459393626,0.065644356689,0.0651768743887,0.0651645722229,0.0644879531041,0.0646601834253,0.0639466578091,0.0631716213639,0.0633315495193,0.0638113339853,0.0641311902961,0.0639835643065,0.0645125574357,0.0647093920885,0.065644356689,0.0658904000049,0.0663947888026,0.0667023429475,0.0668868754344,0.0664070909684,0.0667146451133,0.0668622711028,0.0668622711028,0.0665916234553,0.0664316953,0.0659642129997,0.0663824866368,0.0665178104605,0.0656566588548,0.0655582415284,0.0652014787203,0.0659273065023,0.0659396086681,0.0652752917151,0.0648816224096,0.0651891765545,0.0650292483992,0.0647339964201,0.0652752917151,0.0657304718496,0.0661979541498,0.0655951480258,0.0652506873835,0.0657181696838,0.0659027021707,0.0658780978391,0.0652752917151,0.0653737090415,0.0660626303261,0.0668130624396,0.0662963714762,0.0665424147921,0.0663332779736,0.066370184471,0.0663209758078,0.0665055082947,0.0664562996316,0.0665670191237,0.0661979541498,0.0652629895493,0.0653368025441,0.065521335031,0.0658411913417,0.0658904000049,0.065705867518,0.0651522700571,0.0654844285336,0.0654106155389,0.0652752917151,0.0653121982125,0.065521335031,0.0654106155389,0.065103061394,0.0647832050833,0.0646847877569,0.065041550565,0.0652875938809,0.0653368025441,0.0654598242021,0.0656320545232,0.0655459393626,0.0658780978391,0.066247162813,0.0664316953,0.066911479766,0.0668376667712,0.0659150043365,0.0658780978391,0.065521335031,0.0657919826786,0.0659519108339,0.0651522700571,0.0651522700571,0.0653368025441,0.0653121982125,0.0655582415284,0.0656812631864,0.0655705436942,0.0659396086681,0.0656320545232,0.0653983133731,0.0651399678913,0.0656566588548,0.0658165870101,0.065521335031,0.0651891765545,0.0658534935075,0.0662963714762,0.0663332779736,0.0660011194971,0.0663578823052,0.0669237819318,0.066849968937,0.0663578823052,0.0659519108339,0.0660749324919,0.0655459393626,0.0656074501916,0.0655090328652,0.0661610476524,0.0656197523574,0.0655459393626,0.0647586007517,0.0652137808861,0.0662348606472,0.0657796805128,0.0656074501916,0.0649923419018,0.0647832050833,0.0638728448143,0.0640327729697,0.0640450751355,0.0642419097882,0.0640081686381,0.063589895001,0.06365140583,0.0637498231564,0.0636021971668,0.0637621253222,0.0643649314462,0.0645125574357,0.0648324137464,0.065041550565,0.0652260830519,0.0648693202438,0.0650784570624,0.0653121982125,0.0657550761812,0.0655705436942,0.0656812631864,0.0652875938809,0.0646970899227,0.0645986725963,0.0642665141198,0.0645125574357,0.0648939245754,0.0647339964201,0.064438744441,0.0640450751355,0.0637252188248,0.0641065859645,0.0645863704305,0.0647832050833,0.0644141401094,0.0641803989592,0.0637867296538,0.0638482404827,0.0641803989592,0.064315722783,0.0648324137464,0.064918528907,0.0642788162856,0.0639343556433,0.0643895357778,0.0651399678913,0.0646970899227,0.0653368025441,0.0653860112073,0.0656320545232,0.0652014787203,0.065041550565,0.0653737090415,0.0657181696838,0.0658042848443,0.0655459393626,0.0659150043365,0.0658411913417,0.0659396086681,0.0661733498182,0.0658657956733,0.0662717671446,0.0663455801394,0.0660380259945,0.0659765151655,0.0660503281603,0.0663947888026,0.0657796805128,0.0651891765545,0.0656935653522,0.0659396086681,0.0656074501916,0.0654106155389,0.0656812631864,0.0656935653522,0.065705867518,0.0651645722229,0.0658042848443,0.0663455801394,0.066185651984,0.0664193931342,0.0666039256211,0.0668253646054,0.0667515516107,0.0671698252477,0.0668253646054,0.0676250053822,0.067760329206,0.0674404728953,0.066911479766,0.0667392494449,0.066849968937,0.0671575230819,0.0674896815584,0.0668991776002,0.0667146451133,0.0669606884292,0.0663947888026,0.0665301126263,0.0672559404083,0.0674773793926,0.0671821274135,0.0668745732686,0.0666408321185,0.0665916234553,0.0673051490715,0.0670837100872,0.0673051490715,0.0673297534031,0.0669483862634,0.0666531342843,0.0665424147921,0.0663578823052,0.0664562996316,0.0665055082947,0.0667638537765,0.0662963714762,0.0660257238287,0.0663455801394,0.0660257238287,0.0662102563156,0.0667638537765,0.0668007602738,0.0660380259945,0.0663209758078,0.0661610476524,0.0658534935075,0.0662963714762,0.0659642129997,0.0657796805128,0.0656320545232,0.0656689610206,0.065705867518,0.0660503281603,0.0663455801394,0.0659150043365,0.0664439974658,0.0660257238287,0.0656320545232,0.065705867518,0.0661733498182,0.0660503281603,0.0665670191237,0.0667023429475,0.066185651984,0.0661364433208,0.0666531342843,0.0670714079214,0.0668622711028,0.0668007602738,0.0666039256211,0.0657919826786,0.0652383852177,0.0655336371968,0.0653860112073,0.065041550565,0.065041550565,0.064980039736,0.0653860112073,0.0659273065023,0.0656320545232,0.0660257238287,0.0657181696838,0.0652998960467,0.0654598242021,0.0660503281603,0.0651768743887,0.0645863704305,0.0650784570624,0.0646970899227,0.0650169462334,0.0645494639331,0.0650169462334,0.0655459393626,0.0656197523574,0.0653491047099,0.065521335031,0.066185651984,0.0662594649788,0.0671821274135,0.0668376667712,0.0678464443665,0.0680432790193,0.0678833508639,0.0684123439932,0.0687075959723,0.0686706894749,0.0688060132986,0.0680186746877,0.0673789620663,0.0677726313718,0.0672436382425,0.0665178104605,0.0666408321185,0.0657796805128,0.0650784570624,0.0648447159122,0.0648078094148,0.0654598242021,0.0655582415284,0.0652260830519,0.064857018078,0.065644356689,0.0653614068757,0.0661364433208,0.0666654364501,0.0671944295793,0.0668376667712,0.0668868754344,0.0670714079214,0.0672928469057,0.0676250053822,0.0677726313718,0.0680678833509,0.0682770201694,0.0683508331642,0.068240113672,0.0686091786459,0.0685476678169,0.0685353656511,0.0683139266668,0.0690643587804,0.0685230634853,0.0679448616929,0.0671821274135,0.0672067317451,0.0679079551955,0.0676004010506,0.0670591057556,0.0674281707295,0.0674650772268,0.0670591057556,0.0671821274135,0.0673789620663,0.0675511923874,0.067698818377,0.0671083144188,0.0673789620663,0.0678095378691,0.0675511923874,0.0675265880558,0.0673666599005,0.068424646159,0.0682893223352,0.068842919796,0.0685722721485,0.068240113672,0.0681539985114,0.0680678833509,0.0678956530297,0.0683139266668,0.0684615526563,0.067575796719,0.0679817681903,0.067637307548,0.0676004010506,0.0680555811851,0.0683754374958,0.0687075959723,0.0690643587804,0.0692611934331,0.0697901865623,0.0697163735676,0.0696179562412,0.0697409778992,0.0700731363757,0.0703191796916,0.0702576688626,0.0701346472046,0.0693719129253,0.069507236749,0.0690643587804,0.0693842150911,0.0695441432464,0.0699870212151,0.0702699710284,0.0700239277125,0.0694334237543,0.0698763017229,0.0699624168835,0.0696794670702,0.0700239277125,0.0699255103861,0.0699747190493,0.0698147908939,0.0698270930597,0.0700116255467,0.070356086189,0.069691769236,0.0701346472046,0.0697409778992,0.069088963112,0.0695195389148,0.069630258407,0.0695195389148,0.068904430625,0.0686337829775,0.0691012652778,0.0692488912673,0.0690151501172,0.0695933519096,0.0700239277125,0.069691769236,0.0694703302516,0.0688552219618,0.069568747578,0.0701592515362,0.0696425605728,0.0701223450388,0.0700854385415,0.0704298991838,0.0704545035153,0.071020403142,0.0711557269657,0.0719676699083,0.0714017702817,0.0706390360023,0.0709465901472,0.0709219858156,0.071684720095,0.071684720095,0.0717954395871,0.0718692525819,0.0715740006028,0.0721522023952,0.0727057998561,0.0736284622908,0.0737268796172,0.0735423471302,0.0738622034409,0.0736407644566,0.0741205489226,0.0739975272647,0.0751170243521,0.0744281030675,0.0740098294305,0.0738375991093,0.0737760882803,0.0745757290571,0.0746003333887,0.0745757290571,0.0738745056067,0.0737760882803,0.0740590380937,0.0743542900728,0.0752400460101,0.0759535716263,0.0759658737921,0.0757567369735,0.0754983914918,0.0757936434709,0.0767409102372,0.0770853708795,0.076334938766,0.0764948669213,0.07608889545,0.0757813413051,0.0765932842477,0.0771591838743,0.0768024210662,0.0767655145688,0.0762980322686,0.0760642911185,0.0758182478025,0.0760519889527,0.07608889545,0.0757813413051,0.0752031395127,0.0748340745388,0.0753384633365,0.0751539308495,0.075486089326,0.0758305499683,0.0769623492216,0.0771468817085,0.0773683206929,0.0780449398117,0.0785985372725,0.0791275304017,0.0798533581837,0.0808375314474,0.0811942942555,0.0812681072503,0.0811573877581,0.0812558050845,0.0818709133743,0.0821538631876,0.0824614173325,0.0822030718508,0.0818832155401,0.0817847982137,0.0824245108351,0.0828058779748,0.0829535039644,0.0833594754357,0.0834701949278,0.0837285404095,0.0842206270414,0.084122209715,0.0842821378704,0.084909548326,0.0849341526576,0.0847619223364,0.0846758071759,0.0845896920153,0.0849464548234,0.085573865279,0.0853770306262,0.0860905562424,0.0865211320453,0.0864719233821,0.0863858082215,0.0870747295061,0.088046600604,0.0882557374226,0.0882188309252,0.0882434352568,0.0887601262202,0.0893998388416,0.0898919254735,0.0902363861158,0.0909622138978,0.0914666026954,0.0918356676693,0.092094013151,0.0930658842489,0.0931150929121,0.0935210643834,0.0936686903729,0.0943699138233,0.0942961008286,0.0943699138233,0.0938778271915,0.0938040141967,0.0950342307763,0.0945790506419,0.0951818567659,0.0951326481027,0.0951941589317,0.0951449502685,0.096141425698,0.09686725348,0.0980236570648,0.0987002761836,0.0987863913442,0.100004305758,0.100373370732,0.101406752659,0.102452436751,0.103399703518,0.103793372823,0.104076322637,0.104900567745,0.106819705609,0.108148339515,0.109563088582,0.110264312032,0.111826687088,0.11331524915,0.114754602548,0.116353884101,0.11802697865,0.11934331039,0.120352087985,0.121594606731,0.12259108216,0.124313385371,0.124694752511,0.125789645267,0.127167487836,0.127819502623,0.129800151317,0.131091878725,0.131325619875,0.131510152362,0.131682382683,0.132826484103,0.13456108948,0.135040873946,0.135692888733,0.137292170287,0.137009220473,0.1371076378,0.137464400608,0.138928358337,0.13974030128,0.138608502027,0.13927281898,0.139346631975,0.139162099488,0.13974030128,0.140035553259,0.140429222565,0.141302676336,0.140576848554,0.141167352512,0.1422868496,0.142446777755,0.142446777755,0.142114619279,0.141327280668,0.141155050347,0.141634834813,0.142323756097,0.142422173424,0.142631310242,0.143418648853,0.142926562221,0.143418648853,0.144673469764,0.144538145941,0.144710376262,0.14430440479,0.143504764014,0.144279800459,0.144378217785,0.14383692249,0.144205987464,0.145091743401,0.144698074096,0.14614972966,0.146727931452,0.147478363566,0.148659371482,0.149200666777,0.150541602849,0.151181315471,0.151402754455,0.151624193439,0.152448438548,0.151624193439,0.152374625553,0.151624193439,0.151624193439,0.151525776113,0.150307861699,0.149988005388,0.15039397686,0.150037214052,0.149200666777,0.150369372528,0.14939750143,0.149828077233,0.148868508301,0.148597860653,0.148524047659,0.148474838995,0.147429154903,0.147281528913,0.147970450198,0.146814046613,0.147256924582,0.147773615545,0.14831491084,0.147306133245,0.147293831079,0.147023183431,0.147207715918,0.146469585971,0.145386995381,0.145227067225,0.144821095754,0.143640087837,0.143295627195,0.143824620324,0.142778936232,0.142397569092,0.142225338771,0.142471382087,0.142483684253,0.142016201952,0.141524115321,0.141536417486,0.140527639891,0.140490733394,0.14129037417,0.141966993289,0.141487208823,0.140749078875,0.140847496202,0.140158574917,0.139826416441,0.139641883954,0.139457351467,0.138965264835,0.137882674245,0.136172673199,0.136172673199,0.135902025552,0.134905550122,0.135385334588,0.134831737127,0.133552311885,0.132506627792,0.132543534289,0.132223677979,0.132469721294,0.131485548031,0.130575187762,0.130575187762,0.12970173399,0.129369575514,0.129664827493,0.130095403296,0.129308064685,0.129037417037,0.129037417037,0.12885288455,0.128643747732,0.127610365805,0.126613890375,0.126540077381,0.125863458262,0.125592810614,0.125125328314,0.125272954304,0.124534824356,0.124387198366,0.124178061548,0.124411802698,0.125359069464,0.124461011361,0.124485615693,0.124743961174,0.124165759382,0.12367367275,0.12305856446,0.122431154005,0.121914463041,0.121533095902,0.120671944296,0.12004453384,0.119281799561,0.118199208971,0.117744028836,0.116907481562,0.117239640039,0.116722949075,0.116612229583,0.115775682309,0.115517336827,0.115960214796,0.115677264983,0.114902228537,0.114889926372,0.114557767895,0.113610501129,0.114090285595,0.113032299336,0.112872371181,0.111752874093,0.110756398664,0.110793305161,0.111580643772,0.111150067969,0.110547261845,0.110375031524,0.109624599411,0.11076870083,0.109661505908,0.109563088582,0.109784527566,0.109563088582,0.107951504862,0.107668555049,0.107582439889,0.10690582077,0.106659777454,0.105650999859,0.106253805983,0.106549057962,0.105835532345,0.105429560874,0.105491071703,0.105404956543,0.105331143548,0.10474063959,0.103854883652,0.103424307849,0.102846106057,0.101997256617,0.10172660897,0.101591285146,0.102107976109,0.101086896348,0.100459485892,0.100926968193,0.101603587312,0.101529774317,0.101874234959,0.101665098141,0.101702004638,0.101849630627,0.100656320545,0.100754737872,0.100508694556,0.100299557737,0.0997459602763,0.0999797014264,0.0997951689395,0.0997828667737,0.100410277229,0.0997951689395,0.100164233913,0.100484090224,0.1003487664,0.100151931748,0.0995737299552,0.0988109956758,0.0979867505674,0.0979744484016,0.0970763902985,0.0969779729721,0.0969902751379,0.0967688361536,0.0972363184539,0.0971379011275,0.0967073253246,0.0959814975426,0.096141425698,0.0954525044134,0.0953786914186,0.0948620004552,0.0940992661758,0.0929920712541,0.0928567474304,0.0928075387672,0.092819840933,0.0929551647568,0.0919832936588,0.0924015672959,0.0917864590061,0.0918725741667,0.0917618546745,0.0916757395139,0.0907161705818,0.0901994796184,0.0897196951523,0.090888400903,0.0911590485505,0.0902486882816,0.0903225012763,0.0898796233077,0.0894613496706,0.0894121410074,0.0893998388416,0.0893506301784,0.0895351626654,0.0885263850701,0.0884402699095,0.0883910612463,0.0876775356301,0.0868040818586,0.0863119952268,0.0863489017241,0.085450843621,0.0844297638599,0.0826951584827,0.0811327834265,0.0797180343599,0.078992206578,0.0786354437699,0.0779342203195,0.0773683206929,0.0757936434709,0.0752277438443,0.0748709810362,0.0752646503417,0.0751908373469,0.0752769525075,0.0756829239788,0.0753507655023,0.0753384633365,0.0753138590049,0.0760519889527,0.0759904781237,0.0758182478025,0.0753138590049,0.0758797586315,0.0756829239788,0.0751662330153,0.0746864485493,0.0749324918652,0.0747356572125,0.0741082467568,0.0736530666224,0.0737637861145,0.0745142182281,0.0736284622908,0.0732840016485,0.0729026345088,0.0731363756589,0.0728534258456,0.0723982457112,0.0727057998561,0.0732101886537,0.0733947211407,0.0728165193482,0.0725704760323,0.0722752240532,0.0719430655767,0.0716478135976,0.0711434247999,0.070958892313,0.0706390360023,0.0703191796916,0.0703683883548,0.0707620576603,0.0713279572869,0.0716109071002,0.0716724179292,0.0711434247999,0.0717585330898,0.0716478135976,0.0713033529553,0.0713648637843,0.0699993233809,0.0691381717751,0.0686091786459,0.0683754374958,0.0680432790193,0.0680555811851,0.0680801855167,0.0684492504905,0.0686337829775,0.0678218400349,0.0684123439932,0.0683508331642,0.068178602843,0.0683139266668,0.0684984591537,0.0685230634853,0.0679571638587,0.0675019837242,0.067760329206,0.0687198981381,0.06836313533,0.0689290349566,0.0690151501172,0.0686337829775,0.0680063725219,0.0682893223352,0.0682032071746,0.0684492504905,0.0681416963456,0.0675019837242,0.0680801855167,0.0677111205428,0.0680678833509,0.0684369483248,0.069088963112,0.0684861569879,0.0685599699827,0.0689536392882,0.0689782436198,0.0689290349566,0.068424646159,0.0683508331642,0.0677972357033,0.0682278115062,0.0683754374958,0.0686952938065,0.0694334237543,0.0686829916407,0.0688798262934,0.068965941454,0.0685722721485,0.0686952938065,0.0687937111328,0.0681663006772,0.0675511923874,0.0679202573613,0.0673789620663,0.0677234227086,0.0670591057556,0.067034501424,0.067096012253,0.0668991776002,0.066849968937,0.0671206165845,0.0677234227086,0.0676127032164,0.0675634945532,0.0674896815584,0.0676619118796,0.0681416963456,0.068240113672,0.0685599699827,0.0685107613195,0.0680186746877,0.0678095378691,0.0676619118796,0.0675634945532,0.0673666599005,0.0673789620663,0.06751428589,0.0682032071746,0.0673543577347,0.0672928469057,0.067452775061,0.0672559404083,0.0667761559423,0.0664686017973,0.0667269472791,0.066911479766,0.0662348606472,0.0652629895493,0.0658165870101,0.0654475220363,0.0652629895493,0.0652260830519,0.0657427740154,0.0658042848443,0.0654229177047,0.0650907592282,0.0651153635598,0.066247162813,0.0659396086681,0.0667269472791,0.067034501424,0.0667638537765,0.0663209758078,0.066308673642,0.066911479766,0.0670837100872,0.0668868754344,0.0664562996316,0.0663824866368,0.0660134216629,0.0656812631864,0.0657919826786,0.0662840693104,0.0666162277869,0.0666900407817,0.0667761559423,0.0666408321185,0.0665670191237,0.066849968937,0.066911479766,0.0675265880558,0.0682893223352,0.0681539985114,0.0678710486981,0.0672559404083,0.0671083144188,0.0672313360767,0.067760329206,0.0675511923874,0.0674650772268,0.0670837100872,0.066370184471,0.0662594649788,0.0663578823052,0.0661610476524,0.0660872346577,0.0661610476524,0.0651399678913,0.0650661548966,0.0648693202438,0.0645494639331,0.0644264422752,0.0644264422752,0.0643280249488,0.0646601834253,0.064438744441,0.0645494639331,0.0649554354044,0.0649062267412,0.0654352198705,0.0654721263678,0.0662348606472,0.0664686017973,0.0662594649788,0.0656812631864,0.0653368025441,0.0652137808861,0.0650538527308,0.0652875938809,0.065041550565,0.0654967306994,0.064918528907,0.064254211954,0.0641680967934,0.064315722783,0.0647216942543,0.0644756509383,0.0645494639331,0.0649431332386,0.0647093920885,0.0648816224096,0.0652260830519,0.0653121982125,0.0655582415284,0.0657427740154,0.0657181696838,0.0661733498182,0.065705867518,0.0650661548966,0.0650538527308,0.0645986725963,0.0645863704305,0.0649431332386,0.0653491047099,0.065521335031,0.0655582415284,0.0654844285336,0.0655336371968,0.0655705436942,0.0659273065023,0.0659027021707,0.0658904000049,0.0658165870101,0.0652875938809,0.0650907592282,0.0653121982125,0.0650169462334,0.0660626303261,0.0660380259945,0.0660995368235,0.0660626303261,0.065521335031,0.0660749324919,0.0663455801394,0.0666162277869,0.0665178104605,0.0658657956733,0.065103061394,0.0651645722229,0.0652383852177,0.0654106155389,0.0653614068757,0.0643280249488,0.0644018379436,0.0642173054566,0.0650538527308,0.0651768743887,0.0651768743887,0.0651891765545,0.0646724855911,0.0645002552699,0.064980039736,0.0655459393626,0.0655459393626,0.0653121982125,0.0644264422752,0.0653860112073,0.0650907592282,0.0651768743887,0.0653614068757,0.0653368025441,0.0654721263678,0.0648201115806,0.0649431332386,0.0652752917151,0.0653737090415,0.0648693202438,0.0652629895493,0.0587797481747,0.052234995971,0.045837869757,0.03901016774,0.0) ycorr <- c(5.91530285832e-05,5.89770304874e-05,5.84557657347e-05,5.75815143027e-05,5.63575373305e-05,5.47811122724e-05,5.28590386941e-05,5.09203786508e-05,4.89647370387e-05,4.69848995752e-05,4.49856327646e-05,4.29662082185e-05,4.09302061391e-05,3.88687289289e-05,3.67879295444e-05,3.46987544105e-05,3.25971105329e-05,3.04682574725e-05,2.83137465871e-05,2.61505104331e-05,2.39797302431e-05,2.18091389748e-05,1.96312456785e-05,1.7443676629e-05,1.52570692535e-05,1.30617209967e-05,1.0851567488e-05,8.64090445835e-06,6.432842409e-06,4.21622996768e-06,1.97930498163e-06,-2.69453804817e-07,-2.52441218633e-06,-4.78133584305e-06,-7.03540798597e-06,-9.29314970287e-06,-1.15565509081e-05,-1.3816398086e-05,-1.60843708718e-05,-1.83572442736e-05,-2.06216119642e-05,-2.28867547057e-05,-2.51675005887e-05,-2.74586964344e-05,-2.97673249082e-05,-3.20878711042e-05,-3.44079319426e-05,-3.67323667543e-05,-3.90619121489e-05,-4.13950802798e-05,-4.37338511583e-05,-4.60866792512e-05,-4.84389986635e-05,-5.0794988246e-05,-5.31638240843e-05,-5.5548055151e-05,-5.79588344128e-05,-6.040382737e-05,-6.28818675593e-05,-6.53885126739e-05,-6.79207611433e-05,-7.04759433219e-05,-7.30501691046e-05,-7.56367848885e-05,-7.82327626862e-05,-8.08309147918e-05,-8.34264365551e-05,-8.60117559552e-05,-8.85775728941e-05,-9.11220338311e-05,-9.36555489416e-05,-9.61783422645e-05,-9.86853309545e-05,-0.000101195163411,-0.000103703757809,-0.000106204789152,-0.000108698760565,-0.000111189539942,-0.000113677795616,-0.000116172308036,-0.000118661372801,-0.000121143218118,-0.000123625890654,-0.000126098685621,-0.000128554864908,-0.000131017684226,-0.000133483452471,-0.000135943172901,-0.000138395357129,-0.000140836696555,-0.000143269660638,-0.000145693145376,-0.000148101939408,-0.000150493589063,-0.000152878060855,-0.000155233042011,-0.000157556361628,-0.000159860175603,-0.00016215220906,-0.000164432658337,-0.000166706062896,-0.000168970693526,-0.000171232652066,-0.000173493102728,-0.000175750129502,-0.000178007856601,-0.000180268995998,-0.000182531915879,-0.000184791459293,-0.00018705604675,-0.000189317204937,-0.00019157079103,-0.000193819190075,-0.000196054709385,-0.000198279399444,-0.000200491398399,-0.000202690979287,-0.000204885163854,-0.000207065694427,-0.000209214744043,-0.00021133855057,-0.000213448204709,-0.000215539575895,-0.000217620632264,-0.000219693817726,-0.000221754461997,-0.000223795688723,-0.000225815961466,-0.000227819274334,-0.000229818185874,-0.000231816666539,-0.000233801427253,-0.000235772241142,-0.000237728921606,-0.000239661549652,-0.000241579285693,-0.000243491621801,-0.000245403176591,-0.000247312391583,-0.00024921737426,-0.00025110894621,-0.000252991087042,-0.000254864982029,-0.000256724575323,-0.000258578289921,-0.000260422936245,-0.000262257081737,-0.000264071687052,-0.000265874054784,-0.000267662641426,-0.000269437966326,-0.000271203943938,-0.00027296497547,-0.000274733217877,-0.000276499993231,-0.000278266294529,-0.000280037568307,-0.000281807175978,-0.000283576313143,-0.000285336697843,-0.000287088763247,-0.000288828751547,-0.000290550979534,-0.000292247949223,-0.000293915287409,-0.000295562633781,-0.000297182223749,-0.000298770861907,-0.00030032958582,-0.000301865747987,-0.000303382001786,-0.000304881059446,-0.000306364030407,-0.000307837241165,-0.000309308154566,-0.000310770941178,-0.000312221842029,-0.00031367147566,-0.000315119140864,-0.000316564711991,-0.0003180099983,-0.000319450240057,-0.000320886569453,-0.000322310408795,-0.000323717648702,-0.000325109298362,-0.00032649874841,-0.000327885325563,-0.000329258712709,-0.00033061971376,-0.000331967237781,-0.000333307392398,-0.000334635126447,-0.000335953986613,-0.000337276113744,-0.000338600046732,-0.000339907025131,-0.000341191252256,-0.000342459971612,-0.000343713277671,-0.000344952189297,-0.000346173727424,-0.000347372986407,-0.000348562730869,-0.000349732382339,-0.000350879094446,-0.000352010660103,-0.00035314181585,-0.000354265706307,-0.00035537642154,-0.000356471499989,-0.000357550986924,-0.000358622351709,-0.000359673329761,-0.000360701619103,-0.000361712532965,-0.000362710910148,-0.000363682155195,-0.00036462809609,-0.000365559176413,-0.000366483685966,-0.000367403836053,-0.000368320357015,-0.000369228841359,-0.000370137288452,-0.000371050190088,-0.000371954244362,-0.000372850181099,-0.000373746758867,-0.00037464223485,-0.000375528012262,-0.000376406865326,-0.000377279234834,-0.000378144882451,-0.000379015226319,-0.000379877299714,-0.000380734952075,-0.000381601842011,-0.000382468934345,-0.000383335522346,-0.000384196634178,-0.000385044854901,-0.000385874755003,-0.000386694819629,-0.000387492867701,-0.000388267772741,-0.000389030743917,-0.000389772000932,-0.000390496363588,-0.000391206659828,-0.000391903800175,-0.00039259112752,-0.000393279242801,-0.000393961074865,-0.000394634971661,-0.000395304808211,-0.00039596172076,-0.00039660137635,-0.000397232017342,-0.000397849173292,-0.000398454436688,-0.00039905124532,-0.000399633179807,-0.000400204837004,-0.000400768347209,-0.000401325476077,-0.000401881466591,-0.000402440300052,-0.000402996277727,-0.000403541967098,-0.000404075752993,-0.000404607063573,-0.000405134814959,-0.000405658760522,-0.00040617165927,-0.000406673649886,-0.000407162502727,-0.000407641379583,-0.000408111004917,-0.000408579385439,-0.000409046380021,-0.000409506566565,-0.000409950674284,-0.000410378500515,-0.000410793346869,-0.000411192309433,-0.000411571559263,-0.000411929966018,-0.000412256361608,-0.000412545113842,-0.00041279165803,-0.000412990809529,-0.000413146035751,-0.000413256053512,-0.000413327909587,-0.000413363460826,-0.000413369577558,-0.000413342593559,-0.000413284009109,-0.000413203809765,-0.000413113898851,-0.000413020654149,-0.000412929860724,-0.000412850182477,-0.000412776916881,-0.000412705182795,-0.000412635459239,-0.000412570651089,-0.000412518057708,-0.000412474111084,-0.000412431344823,-0.000412386348589,-0.000412337603233,-0.000412279762678,-0.000412201536069,-0.000412112839718,-0.000412011007398,-0.000411896730108,-0.000411762862878,-0.000411615320272,-0.000411459826253,-0.000411291310889,-0.000411103435581,-0.000410896105478,-0.000410679773545,-0.000410457230944,-0.000410221265382,-0.000409976447151,-0.000409728989263,-0.000409479011862,-0.000409220080424,-0.000408951397648,-0.000408684405408,-0.000408418359215,-0.000408154318549,-0.000407882691262,-0.000407607949001,-0.000407329324193,-0.000407042894719,-0.000406747632122,-0.000406446161484,-0.000406143690316,-0.000405838033016,-0.00040552814678,-0.000405210941187,-0.000404892169576,-0.00040457248227,-0.000404248569625,-0.000403925369433,-0.000403591406732,-0.00040324129503,-0.000402870219307,-0.000402474602736,-0.000402055363563,-0.000401616271549,-0.000401163295216,-0.000400692983975,-0.000400208203578,-0.000399700213013,-0.000399173957341,-0.000398638816144,-0.000398096719544,-0.000397552220187,-0.000397007308912,-0.000396457332263,-0.000395898601128,-0.000395330956756,-0.000394758247694,-0.000394190171128,-0.000393630639181,-0.000393078245766,-0.00039253423203,-0.000391993977709,-0.000391451407191,-0.000390911629171,-0.000390373043537,-0.000389838975664,-0.000389305173195,-0.000388760286101,-0.000388203370565,-0.000387634079607,-0.00038705042957,-0.000386456500452,-0.000385858856313,-0.0003852537186,-0.000384636071278,-0.000384012285611,-0.000383379509511,-0.000382741686493,-0.000382100414377,-0.00038145091555,-0.000380796182159,-0.00038013552608,-0.000379464378039,-0.000378782835846,-0.000378103723807,-0.000377419366785,-0.000376725587856,-0.000376022038425,-0.000375303270182,-0.000374572893858,-0.000373829803856,-0.000373073498216,-0.000372300894249,-0.000371519028172,-0.000370720745306,-0.000369901549818,-0.000369065200919,-0.000368215704144,-0.000367353283432,-0.000366485343765,-0.000365608656512,-0.000364723044314,-0.000363836606216,-0.00036294848216,-0.000362053814284,-0.000361156880733,-0.000360256177733,-0.000359358463159,-0.000358460234129,-0.000357561303139,-0.000356660191599,-0.000355757214697,-0.000354850704952,-0.000353935201736,-0.000353008436952,-0.000352069650009,-0.000351120454402,-0.000350163037187,-0.000349197817743,-0.000348215350161,-0.000347218385889,-0.000346207825029,-0.000345180656441,-0.000344133611209,-0.000343069841755,-0.000341996098457,-0.00034091507917,-0.000339817618456,-0.000338699303082,-0.000337565425019,-0.00033642385709,-0.000335271709141,-0.000334110239039,-0.000332946456324,-0.000331780341859,-0.000330608105527,-0.000329425145014,-0.000328229872888,-0.000327038919879,-0.000325848300485,-0.000324652870623,-0.000323454760777,-0.000322251796934,-0.000321038566434,-0.000319815385261,-0.000318586157544,-0.000317350214875,-0.000316107735392,-0.000314855235102,-0.000313582800182,-0.000312296608565,-0.000310989240939,-0.000309660839487,-0.00030831616119,-0.000306957991932,-0.000305586328026,-0.000304200375978,-0.000302800821072,-0.000301384343056,-0.000299955500999,-0.000298513407266,-0.000297062632961,-0.000295609846355,-0.000294153359038,-0.000292685545586,-0.000291200677314,-0.00028969748724,-0.000288175874422,-0.000286640844426,-0.000285095259711,-0.000283536044786,-0.000281963109066,-0.000280367219288,-0.000278744214688,-0.000277100890368,-0.000275439154465,-0.000273764373435,-0.000272075018514,-0.000270361682719,-0.000268623422793,-0.000266860177275,-0.000265072347335,-0.000263264447105,-0.000261443334616,-0.000259608232092,-0.000257757621322,-0.000255891523343,-0.000254014165356,-0.000252131882152,-0.000250250741944,-0.000248372455118,-0.000246497002182,-0.000244630124411,-0.000242766598247,-0.000240901289674,-0.000239030601106,-0.000237151708342,-0.000235264588056,-0.000233365624095,-0.000231453182677,-0.000229525988108,-0.000227581281993,-0.000225610859422,-0.000223606182209,-0.000221572712176,-0.000219516301908,-0.000217442958647,-0.000215349444825,-0.000213238694882,-0.000211110390531,-0.000208956812902,-0.00020678507323,-0.000204594459831,-0.000202392095219,-0.000200179272834,-0.000197952384071,-0.000195706025172,-0.000193443769887,-0.000191159950876,-0.000188851440043,-0.000186518752276,-0.00018416085464,-0.000181778963353,-0.000179372889584,-0.000176945275143,-0.000174494153671,-0.000172018902697,-0.00016951748604,-0.00016698512193,-0.00016442871227,-0.000161853465714,-0.000159252783544,-0.00015662709669,-0.00015397175154,-0.000151280473766,-0.000148552723544,-0.000145792780511,-0.000142998703909,-0.000140183506157,-0.000137339933553,-0.000134468482552,-0.00013156664849,-0.000128633476011,-0.000125677499318,-0.000122700172269,-0.000119706554592,-0.000116692827796,-0.000113650180762,-0.000110576047989,-0.000107462183266,-0.00010431296983,-0.000101131245783,-9.79180296598e-05,-9.46707531164e-05,-9.13881424779e-05,-8.80672143723e-05,-8.47134091277e-05,-8.1329567338e-05,-7.79224813354e-05,-7.45017246275e-05,-7.10625626764e-05,-6.76057121131e-05,-6.41299514764e-05,-6.06375009575e-05,-5.7133868986e-05,-5.36109157512e-05,-5.00658051408e-05,-4.65016836962e-05,-4.29134537014e-05,-3.92995628278e-05,-3.56552705991e-05,-3.19832957358e-05,-2.82859004515e-05,-2.45548067763e-05,-2.07875686497e-05,-1.69885668735e-05,-1.3157816258e-05,-9.29595802483e-06,-5.39746639816e-06,-1.41465297934e-06,2.70234755368e-06,6.99817416055e-06,1.15105706847e-05,1.65175177175e-05,2.1022678153e-05,2.5321788944e-05,2.94553834029e-05,3.34669643161e-05,3.74152284883e-05,4.13564604923e-05,4.5246017001e-05,4.90271770166e-05,5.2651369511e-05,5.60817058454e-05,5.90491428247e-05,6.25357723839e-05,6.62505844307e-05,7.0159645091e-05,7.42137129346e-05,7.83559473635e-05,8.25323732355e-05,8.67463076684e-05,9.10048764887e-05,9.53091732615e-05,9.96560691558e-05,0.000104042322475,0.000108471844816,0.000112944028953,0.000117445792648,0.00012198039435,0.000126538237296,0.000131116628145,0.000135702819839,0.000140298138457,0.000144900764628,0.000149518046529,0.000154151529611,0.000158800874373,0.000163473132033,0.000168172784895,0.000172900666385,0.000177658948959,0.000182455632228,0.000187286048484,0.000192152440781,0.000197056020664,0.00020198741308,0.000206940341397,0.000211911689437,0.000216890440507,0.00022188409287,0.00022689138774,0.000231905137527,0.000236920726161,0.000241935583835,0.000246943394568,0.000251944363909,0.000256935306525,0.000261914202601,0.000266892833739,0.000271865273361,0.000276828091543,0.000281775491944,0.000286721079962,0.000291666724947,0.00029661316393,0.000301560878267,0.000306512358137,0.000311473278221,0.00031644060655,0.000321407461873,0.000326371362563,0.000331335573481,0.000336304723856,0.000341272600578,0.000346238918452,0.000351208141161,0.000356181917582,0.000361159799251,0.000366139475526,0.000371123986988,0.000376117343156,0.000381122622463,0.000386129115205,0.000391134084107,0.000396135820385,0.000401128802941,0.00040611555404,0.000411093108558,0.000416057224582,0.000421007041332,0.000425945062117,0.000430872806536,0.000435790116218,0.000440701267333,0.000445604822483,0.000450503629404,0.000455390461352,0.000460261076616,0.000465108088043,0.000469935279405,0.000474737465769,0.000479506055118,0.00048423730106,0.000488929956278,0.000493588748103,0.000498210626053,0.000502793460247,0.000507346871082,0.000511877432075,0.000516382418083,0.000520860349822,0.00052530953442,0.000529736087746,0.000534135189801,0.000538500551481,0.000542827085716,0.000547117884772,0.000551364426032,0.000555564740333,0.00055971122877,0.000563805451142,0.000567859134703,0.000571868522613,0.000575829493869,0.000579739710645,0.000583607152958,0.000587428426572,0.000591202256323,0.000594931153987,0.000598615902554,0.000602253422773,0.000605841918024,0.000609371206207,0.000612856956698,0.000616301975556,0.000619707398041,0.000623070949517,0.000626392133353,0.000629670867979,0.00063290602222,0.000636099955479,0.000639253069451,0.000642368013615,0.000645435161736,0.000648448598034,0.000651405028496,0.000654309333268,0.000657163634527,0.000659965637994,0.00066271420148,0.000665410937293,0.000668051273688,0.000670635720754,0.00067316505627,0.000675646414049,0.000678072074317,0.000680441880464,0.000682754116109,0.000685006298786,0.000687205800152,0.00068935062832,0.000691440976462,0.000693476673365,0.00069546128794,0.000697393219722,0.000699269297515,0.000701097325422,0.000702875627306,0.000704601765517,0.00070627724809,0.000707899908272,0.000709469102747,0.000710993541513,0.000712469306554,0.000713892678254,0.00071526946942,0.000716593704668,0.000717860095373,0.00071907287445,0.000720233101896,0.000721338497635,0.000722387041206,0.000723375192898,0.000724296316978,0.000725153131329,0.000725951211224,0.000726681831382,0.000727353859188,0.000727968268526,0.000728523474579,0.000729020672567,0.000729463013555,0.000729850210602,0.000730188656906,0.000730476010826,0.000730709356186,0.000730889801952,0.000731024664949,0.000731106697335,0.000731138595234,0.000731116949139,0.000731040869648,0.000730908195739,0.000730719126695,0.000730476324266,0.000730186798906,0.000729852788621,0.000729468987262,0.000729038119573,0.000728563670969,0.000728049427152,0.000727493535406,0.000726894561959,0.000726259434101,0.000725589929469,0.000724873665969,0.00072411113825,0.000723309020124,0.000722471762543,0.000721590563008,0.000720667169644,0.000719703496973,0.000718706825829,0.000717676854944,0.000716606436457,0.000715495661814,0.000714354049864,0.00071317250815,0.000711943802923,0.000710670751196,0.000709356837545,0.000708004881844,0.000706609638426,0.000705166310688,0.000703676662188,0.000702146985239,0.000700577598283,0.000698964373213,0.000697312232834,0.000695630067076,0.000693909705989,0.000692151082169,0.000690351315624,0.000688514497486,0.000686646832008,0.000684752080988,0.000682825108268,0.000680864226948,0.000678878427176,0.000676857122688,0.000674798407261,0.000672706179322,0.000670589892567,0.000668447247583,0.000666269715988,0.000664051537926,0.000661786453279,0.000659484262176,0.000657140448733,0.000654764132172,0.000652363048296,0.000649932677287,0.000647465252958,0.000644954983353,0.000642409360825,0.00063983611578,0.000637239173412,0.000634618665043,0.000631969963666,0.000629286865537,0.000626564102694,0.000623801838752,0.000621003695633,0.000618178751631,0.000615327791019,0.000612440941577,0.000609519008353,0.000606564774576,0.000603579994685,0.000600569896115,0.000597542642773,0.000594488411553,0.00059140820034,0.000588297527795,0.000585154111297,0.000581986244397,0.000578798871795,0.000575587816581,0.000572355666547,0.000569099599349,0.000565805372897,0.00056247501432,0.000559117136934,0.000555735985952,0.000552335138656,0.000548911535383,0.00054545805041,0.000541975186448,0.000538466164584,0.000534923607219,0.000531356645264,0.000527777528666,0.000524182645993,0.000520560241826,0.000516907178127,0.000513220361032,0.00050949697919,0.000505733869312,0.00050192611226,0.000498070173865,0.000494168480805,0.000490215393886,0.000486209115247,0.000482159560968,0.000478067261979,0.000473935863407,0.000469769796962,0.000465574625051,0.000461351643813,0.000457110012406,0.000452852461066,0.000448576013303,0.000444279174276,0.000439957540825,0.00043561340552,0.000431250657064,0.000426868981664,0.000422467527558,0.00041804929037,0.000413615789556,0.000409163650402,0.000404702745198,0.000400232751328,0.000395759339668,0.000391284233123,0.000386803289677,0.000382325174695,0.000377850964318,0.000373378540451,0.00036890261073,0.000364422442971,0.00035993672119,0.000355438835695,0.000350935602584,0.000346419426261,0.000341894338269,0.000337352541122,0.000332786655371,0.000328197289539,0.000323592166823,0.0003189804671,0.000314362425663,0.000309741793988,0.00030511159141,0.00030047367508,0.000295827964434,0.000291177909012,0.000286533596621,0.000281894889049,0.000277261844042,0.00027262736009,0.000267990448914,0.00026335473828,0.000258718507767,0.000254091005764,0.000249470823297,0.000244863241781,0.000240258883672,0.000235655734342,0.000231059303882,0.000226467529029,0.000221880355917,0.000217294637077,0.000212713997051,0.000208135081135,0.000203552231943,0.000198956447413,0.000194351969109,0.00018974336348,0.000185125918071,0.00018049517225,0.000175857198249,0.000171215143146,0.000166567959582,0.000161914286028,0.000157260521245,0.000152611507969,0.000147977960991,0.000143357624469,0.000138749295961,0.000134159230664,0.000129587788596,0.000125030213009,0.000120485727335,0.000115957862047,0.000111444131332,0.000106948078158,0.000102466824813,9.79961046316e-05,9.3535616293e-05,8.90891752756e-05,8.46560286412e-05,8.02391509117e-05,7.58386531312e-05,7.14576950272e-05,6.70996132133e-05,6.27608871073e-05,5.84372820248e-05,5.41351750261e-05,4.98582335457e-05,4.56062488818e-05,4.13748804245e-05,3.7166433772e-05,3.29832874051e-05,2.88242201199e-05,2.46815771687e-05,2.05563735329e-05,1.64520350147e-05,1.23681213151e-05,8.30028470195e-06,4.24927386169e-06,2.16124271375e-07,-3.79788561925e-06,-7.79991472352e-06,-1.17908617862e-05,-1.5761925554e-05,-1.97136093823e-05,-2.36473158884e-05,-2.75620633165e-05,-3.14613357276e-05,-3.53466564354e-05,-3.92199600653e-05,-4.30844243058e-05,-4.69307201032e-05,-5.07540858028e-05,-5.45588701843e-05,-5.83478946865e-05,-6.21181807114e-05,-6.58710939144e-05,-6.96004902381e-05,-7.33041676552e-05,-7.69780532203e-05,-8.06204781589e-05,-8.42348301072e-05,-8.78297376846e-05,-9.14022559791e-05,-9.49523392498e-05,-9.84835073438e-05,-0.000101994389487,-0.000105490544201,-0.00010897712883,-0.000112453436752,-0.000115919835864,-0.000119377496996,-0.000122827820687,-0.000126264171231,-0.000129684468534,-0.000133084799833,-0.000136465203252,-0.00013982901652,-0.000143169915464,-0.000146493583545,-0.000149796332726,-0.000153076814263,-0.000156328596233,-0.000159550618269,-0.000162748852513,-0.000165930097726,-0.000169099747115,-0.000172250451684,-0.000175377886335,-0.000178480575623,-0.000181559265042,-0.000184619078895,-0.000187660755906,-0.000190696479433,-0.000193720069519,-0.000196728255653,-0.00019971358335,-0.000202669443404,-0.00020560585593,-0.000208517452105,-0.000211406251021,-0.000214264483613,-0.000217089394533,-0.000219876927197,-0.000222622102014,-0.000225330964497,-0.000228004895417,-0.00023065227458,-0.000233270534649,-0.000235858117731,-0.000238419645743,-0.000240957765812,-0.000243482159099,-0.000245989365877,-0.000248490114173,-0.000250980221754,-0.00025345108769,-0.000255905103404,-0.000258337765028,-0.000260757610388,-0.000263165205093,-0.000265552901012,-0.000267916382251,-0.000270254013944,-0.000272565045589,-0.000274849209466,-0.000277112533346,-0.000279351016129,-0.000281564385992,-0.000283754232836,-0.000285914620353,-0.0002880501372,-0.000290165677835,-0.000292267276327,-0.00029435159663,-0.000296419253341,-0.000298467103334,-0.000300496734708,-0.000302515341094,-0.000304522362651,-0.000306516843865,-0.000308501515019,-0.000310472916878,-0.000312427494491,-0.000314366008436,-0.00031628621341,-0.000318192007181,-0.000320078937153,-0.000321947596692,-0.000323792607164,-0.000325615122687,-0.000327412728711,-0.000329183034668,-0.000330925655471,-0.000332641999065,-0.000334330304381,-0.000335990945295,-0.000337628854524,-0.000339242867434,-0.000340830185084,-0.00034239158785,-0.000343931133899,-0.000345448890193,-0.000346953169229,-0.000348439333906,-0.000349910769495,-0.000351365563671,-0.000352799595919,-0.000354213817808,-0.000355612518782,-0.000356996322949,-0.000358369084754,-0.000359723615918,-0.000361057776177,-0.000362366596678,-0.000363650959979,-0.000364910705996,-0.000366149192412,-0.000367368219675,-0.000368562287148,-0.000369733443177,-0.000370877049999,-0.000371998266889,-0.000373098820444,-0.000374183106064,-0.000375244488951,-0.000376288061093,-0.000377316985338,-0.000378320723626,-0.000379304728561,-0.000380268323548,-0.000381210178525,-0.000382134411081,-0.000383034755494,-0.000383904588473,-0.000384747406359,-0.000385566637194,-0.00038635705419,-0.000387119841607,-0.000387856022019,-0.000388565341048,-0.000389250916265,-0.000389912540874,-0.000390546471195,-0.000391156820758,-0.000391754276456,-0.000392332156813,-0.000392890830013,-0.000393432969373,-0.000393960504955,-0.000394473190447,-0.000394964254967,-0.000395421656003,-0.000395851025486,-0.000396259884236,-0.000396642986535,-0.000397001853354,-0.0003973365372,-0.000397643269527,-0.00039792084703,-0.000398167385595,-0.000398377931607,-0.00039854464438,-0.000398678800834,-0.000398775368826,-0.000398824792704) xcorr <- c(-600.0,-598.999165972,-597.998331943,-596.997497915,-595.996663887,-594.995829858,-593.99499583,-592.994161802,-591.993327773,-590.992493745,-589.991659716,-588.990825688,-587.98999166,-586.989157631,-585.988323603,-584.987489575,-583.986655546,-582.985821518,-581.98498749,-580.984153461,-579.983319433,-578.982485405,-577.981651376,-576.980817348,-575.979983319,-574.979149291,-573.978315263,-572.977481234,-571.976647206,-570.975813178,-569.974979149,-568.974145121,-567.973311093,-566.972477064,-565.971643036,-564.970809008,-563.969974979,-562.969140951,-561.968306922,-560.967472894,-559.966638866,-558.965804837,-557.964970809,-556.964136781,-555.963302752,-554.962468724,-553.961634696,-552.960800667,-551.959966639,-550.959132611,-549.958298582,-548.957464554,-547.956630525,-546.955796497,-545.954962469,-544.95412844,-543.953294412,-542.952460384,-541.951626355,-540.950792327,-539.949958299,-538.94912427,-537.948290242,-536.947456214,-535.946622185,-534.945788157,-533.944954128,-532.9441201,-531.943286072,-530.942452043,-529.941618015,-528.940783987,-527.939949958,-526.93911593,-525.938281902,-524.937447873,-523.936613845,-522.935779817,-521.934945788,-520.93411176,-519.933277731,-518.932443703,-517.931609675,-516.930775646,-515.929941618,-514.92910759,-513.928273561,-512.927439533,-511.926605505,-510.925771476,-509.924937448,-508.92410342,-507.923269391,-506.922435363,-505.921601334,-504.920767306,-503.919933278,-502.919099249,-501.918265221,-500.917431193,-499.916597164,-498.915763136,-497.914929108,-496.914095079,-495.913261051,-494.912427023,-493.911592994,-492.910758966,-491.909924937,-490.909090909,-489.908256881,-488.907422852,-487.906588824,-486.905754796,-485.904920767,-484.904086739,-483.903252711,-482.902418682,-481.901584654,-480.900750626,-479.899916597,-478.899082569,-477.89824854,-476.897414512,-475.896580484,-474.895746455,-473.894912427,-472.894078399,-471.89324437,-470.892410342,-469.891576314,-468.890742285,-467.889908257,-466.889074229,-465.8882402,-464.887406172,-463.886572143,-462.885738115,-461.884904087,-460.884070058,-459.88323603,-458.882402002,-457.881567973,-456.880733945,-455.879899917,-454.879065888,-453.87823186,-452.877397832,-451.876563803,-450.875729775,-449.874895746,-448.874061718,-447.87322769,-446.872393661,-445.871559633,-444.870725605,-443.869891576,-442.869057548,-441.86822352,-440.867389491,-439.866555463,-438.865721435,-437.864887406,-436.864053378,-435.863219349,-434.862385321,-433.861551293,-432.860717264,-431.859883236,-430.859049208,-429.858215179,-428.857381151,-427.856547123,-426.855713094,-425.854879066,-424.854045038,-423.853211009,-422.852376981,-421.851542952,-420.850708924,-419.849874896,-418.849040867,-417.848206839,-416.847372811,-415.846538782,-414.845704754,-413.844870726,-412.844036697,-411.843202669,-410.842368641,-409.841534612,-408.840700584,-407.839866555,-406.839032527,-405.838198499,-404.83736447,-403.836530442,-402.835696414,-401.834862385,-400.834028357,-399.833194329,-398.8323603,-397.831526272,-396.830692244,-395.829858215,-394.829024187,-393.828190158,-392.82735613,-391.826522102,-390.825688073,-389.824854045,-388.824020017,-387.823185988,-386.82235196,-385.821517932,-384.820683903,-383.819849875,-382.819015847,-381.818181818,-380.81734779,-379.816513761,-378.815679733,-377.814845705,-376.814011676,-375.813177648,-374.81234362,-373.811509591,-372.810675563,-371.809841535,-370.809007506,-369.808173478,-368.80733945,-367.806505421,-366.805671393,-365.804837364,-364.804003336,-363.803169308,-362.802335279,-361.801501251,-360.800667223,-359.799833194,-358.798999166,-357.798165138,-356.797331109,-355.796497081,-354.795663053,-353.794829024,-352.793994996,-351.793160967,-350.792326939,-349.791492911,-348.790658882,-347.789824854,-346.788990826,-345.788156797,-344.787322769,-343.786488741,-342.785654712,-341.784820684,-340.783986656,-339.783152627,-338.782318599,-337.78148457,-336.780650542,-335.779816514,-334.778982485,-333.778148457,-332.777314429,-331.7764804,-330.775646372,-329.774812344,-328.773978315,-327.773144287,-326.772310259,-325.77147623,-324.770642202,-323.769808173,-322.768974145,-321.768140117,-320.767306088,-319.76647206,-318.765638032,-317.764804003,-316.763969975,-315.763135947,-314.762301918,-313.76146789,-312.760633862,-311.759799833,-310.758965805,-309.758131776,-308.757297748,-307.75646372,-306.755629691,-305.754795663,-304.753961635,-303.753127606,-302.752293578,-301.75145955,-300.750625521,-299.749791493,-298.748957465,-297.748123436,-296.747289408,-295.746455379,-294.745621351,-293.744787323,-292.743953294,-291.743119266,-290.742285238,-289.741451209,-288.740617181,-287.739783153,-286.738949124,-285.738115096,-284.737281068,-283.736447039,-282.735613011,-281.734778982,-280.733944954,-279.733110926,-278.732276897,-277.731442869,-276.730608841,-275.729774812,-274.728940784,-273.728106756,-272.727272727,-271.726438699,-270.725604671,-269.724770642,-268.723936614,-267.723102585,-266.722268557,-265.721434529,-264.7206005,-263.719766472,-262.718932444,-261.718098415,-260.717264387,-259.716430359,-258.71559633,-257.714762302,-256.713928274,-255.713094245,-254.712260217,-253.711426188,-252.71059216,-251.709758132,-250.708924103,-249.708090075,-248.707256047,-247.706422018,-246.70558799,-245.704753962,-244.703919933,-243.703085905,-242.702251877,-241.701417848,-240.70058382,-239.699749791,-238.698915763,-237.698081735,-236.697247706,-235.696413678,-234.69557965,-233.694745621,-232.693911593,-231.693077565,-230.692243536,-229.691409508,-228.69057548,-227.689741451,-226.688907423,-225.688073394,-224.687239366,-223.686405338,-222.685571309,-221.684737281,-220.683903253,-219.683069224,-218.682235196,-217.681401168,-216.680567139,-215.679733111,-214.678899083,-213.678065054,-212.677231026,-211.676396997,-210.675562969,-209.674728941,-208.673894912,-207.673060884,-206.672226856,-205.671392827,-204.670558799,-203.669724771,-202.668890742,-201.668056714,-200.667222686,-199.666388657,-198.665554629,-197.664720601,-196.663886572,-195.663052544,-194.662218515,-193.661384487,-192.660550459,-191.65971643,-190.658882402,-189.658048374,-188.657214345,-187.656380317,-186.655546289,-185.65471226,-184.653878232,-183.653044204,-182.652210175,-181.651376147,-180.650542118,-179.64970809,-178.648874062,-177.648040033,-176.647206005,-175.646371977,-174.645537948,-173.64470392,-172.643869892,-171.643035863,-170.642201835,-169.641367807,-168.640533778,-167.63969975,-166.638865721,-165.638031693,-164.637197665,-163.636363636,-162.635529608,-161.63469558,-160.633861551,-159.633027523,-158.632193495,-157.631359466,-156.630525438,-155.62969141,-154.628857381,-153.628023353,-152.627189324,-151.626355296,-150.625521268,-149.624687239,-148.623853211,-147.623019183,-146.622185154,-145.621351126,-144.620517098,-143.619683069,-142.618849041,-141.618015013,-140.617180984,-139.616346956,-138.615512927,-137.614678899,-136.613844871,-135.613010842,-134.612176814,-133.611342786,-132.610508757,-131.609674729,-130.608840701,-129.608006672,-128.607172644,-127.606338616,-126.605504587,-125.604670559,-124.60383653,-123.603002502,-122.602168474,-121.601334445,-120.600500417,-119.599666389,-118.59883236,-117.597998332,-116.597164304,-115.596330275,-114.595496247,-113.594662219,-112.59382819,-111.592994162,-110.592160133,-109.591326105,-108.590492077,-107.589658048,-106.58882402,-105.587989992,-104.587155963,-103.586321935,-102.585487907,-101.584653878,-100.58381985,-99.5829858215,-98.5821517932,-97.5813177648,-96.5804837364,-95.5796497081,-94.5788156797,-93.5779816514,-92.577147623,-91.5763135947,-90.5754795663,-89.5746455379,-88.5738115096,-87.5729774812,-86.5721434529,-85.5713094245,-84.5704753962,-83.5696413678,-82.5688073394,-81.5679733111,-80.5671392827,-79.5663052544,-78.565471226,-77.5646371977,-76.5638031693,-75.562969141,-74.5621351126,-73.5613010842,-72.5604670559,-71.5596330275,-70.5587989992,-69.5579649708,-68.5571309425,-67.5562969141,-66.5554628857,-65.5546288574,-64.553794829,-63.5529608007,-62.5521267723,-61.551292744,-60.5504587156,-59.5496246872,-58.5487906589,-57.5479566305,-56.5471226022,-55.5462885738,-54.5454545455,-53.5446205171,-52.5437864887,-51.5429524604,-50.542118432,-49.5412844037,-48.5404503753,-47.539616347,-46.5387823186,-45.5379482902,-44.5371142619,-43.5362802335,-42.5354462052,-41.5346121768,-40.5337781485,-39.5329441201,-38.5321100917,-37.5312760634,-36.530442035,-35.5296080067,-34.5287739783,-33.52793995,-32.5271059216,-31.5262718932,-30.5254378649,-29.5246038365,-28.5237698082,-27.5229357798,-26.5221017515,-25.5212677231,-24.5204336947,-23.5195996664,-22.518765638,-21.5179316097,-20.5170975813,-19.516263553,-18.5154295246,-17.5145954962,-16.5137614679,-15.5129274395,-14.5120934112,-13.5112593828,-12.5104253545,-11.5095913261,-10.5087572977,-9.50792326939,-8.50708924103,-7.50625521268,-6.50542118432,-5.50458715596,-4.50375312761,-3.50291909925,-2.50208507089,-1.50125104254,-0.500417014179,0.500417014178,1.50125104254,2.50208507089,3.50291909925,4.50375312761,5.50458715596,6.50542118432,7.50625521268,8.50708924103,9.50792326939,10.5087572977,11.5095913261,12.5104253545,13.5112593828,14.5120934112,15.5129274395,16.5137614679,17.5145954962,18.5154295246,19.516263553,20.5170975813,21.5179316097,22.518765638,23.5195996664,24.5204336947,25.5212677231,26.5221017515,27.5229357798,28.5237698082,29.5246038365,30.5254378649,31.5262718932,32.5271059216,33.52793995,34.5287739783,35.5296080067,36.530442035,37.5312760634,38.5321100917,39.5329441201,40.5337781485,41.5346121768,42.5354462052,43.5362802335,44.5371142619,45.5379482902,46.5387823186,47.539616347,48.5404503753,49.5412844037,50.542118432,51.5429524604,52.5437864887,53.5446205171,54.5454545455,55.5462885738,56.5471226022,57.5479566305,58.5487906589,59.5496246872,60.5504587156,61.551292744,62.5521267723,63.5529608007,64.553794829,65.5546288574,66.5554628857,67.5562969141,68.5571309425,69.5579649708,70.5587989992,71.5596330275,72.5604670559,73.5613010842,74.5621351126,75.562969141,76.5638031693,77.5646371977,78.565471226,79.5663052544,80.5671392827,81.5679733111,82.5688073394,83.5696413678,84.5704753962,85.5713094245,86.5721434529,87.5729774812,88.5738115096,89.5746455379,90.5754795663,91.5763135947,92.577147623,93.5779816514,94.5788156797,95.5796497081,96.5804837364,97.5813177648,98.5821517932,99.5829858215,100.58381985,101.584653878,102.585487907,103.586321935,104.587155963,105.587989992,106.58882402,107.589658048,108.590492077,109.591326105,110.592160133,111.592994162,112.59382819,113.594662219,114.595496247,115.596330275,116.597164304,117.597998332,118.59883236,119.599666389,120.600500417,121.601334445,122.602168474,123.603002502,124.60383653,125.604670559,126.605504587,127.606338616,128.607172644,129.608006672,130.608840701,131.609674729,132.610508757,133.611342786,134.612176814,135.613010842,136.613844871,137.614678899,138.615512927,139.616346956,140.617180984,141.618015013,142.618849041,143.619683069,144.620517098,145.621351126,146.622185154,147.623019183,148.623853211,149.624687239,150.625521268,151.626355296,152.627189324,153.628023353,154.628857381,155.62969141,156.630525438,157.631359466,158.632193495,159.633027523,160.633861551,161.63469558,162.635529608,163.636363636,164.637197665,165.638031693,166.638865721,167.63969975,168.640533778,169.641367807,170.642201835,171.643035863,172.643869892,173.64470392,174.645537948,175.646371977,176.647206005,177.648040033,178.648874062,179.64970809,180.650542118,181.651376147,182.652210175,183.653044204,184.653878232,185.65471226,186.655546289,187.656380317,188.657214345,189.658048374,190.658882402,191.65971643,192.660550459,193.661384487,194.662218515,195.663052544,196.663886572,197.664720601,198.665554629,199.666388657,200.667222686,201.668056714,202.668890742,203.669724771,204.670558799,205.671392827,206.672226856,207.673060884,208.673894912,209.674728941,210.675562969,211.676396997,212.677231026,213.678065054,214.678899083,215.679733111,216.680567139,217.681401168,218.682235196,219.683069224,220.683903253,221.684737281,222.685571309,223.686405338,224.687239366,225.688073394,226.688907423,227.689741451,228.69057548,229.691409508,230.692243536,231.693077565,232.693911593,233.694745621,234.69557965,235.696413678,236.697247706,237.698081735,238.698915763,239.699749791,240.70058382,241.701417848,242.702251877,243.703085905,244.703919933,245.704753962,246.70558799,247.706422018,248.707256047,249.708090075,250.708924103,251.709758132,252.71059216,253.711426188,254.712260217,255.713094245,256.713928274,257.714762302,258.71559633,259.716430359,260.717264387,261.718098415,262.718932444,263.719766472,264.7206005,265.721434529,266.722268557,267.723102585,268.723936614,269.724770642,270.725604671,271.726438699,272.727272727,273.728106756,274.728940784,275.729774812,276.730608841,277.731442869,278.732276897,279.733110926,280.733944954,281.734778982,282.735613011,283.736447039,284.737281068,285.738115096,286.738949124,287.739783153,288.740617181,289.741451209,290.742285238,291.743119266,292.743953294,293.744787323,294.745621351,295.746455379,296.747289408,297.748123436,298.748957465,299.749791493,300.750625521,301.75145955,302.752293578,303.753127606,304.753961635,305.754795663,306.755629691,307.75646372,308.757297748,309.758131776,310.758965805,311.759799833,312.760633862,313.76146789,314.762301918,315.763135947,316.763969975,317.764804003,318.765638032,319.76647206,320.767306088,321.768140117,322.768974145,323.769808173,324.770642202,325.77147623,326.772310259,327.773144287,328.773978315,329.774812344,330.775646372,331.7764804,332.777314429,333.778148457,334.778982485,335.779816514,336.780650542,337.78148457,338.782318599,339.783152627,340.783986656,341.784820684,342.785654712,343.786488741,344.787322769,345.788156797,346.788990826,347.789824854,348.790658882,349.791492911,350.792326939,351.793160967,352.793994996,353.794829024,354.795663053,355.796497081,356.797331109,357.798165138,358.798999166,359.799833194,360.800667223,361.801501251,362.802335279,363.803169308,364.804003336,365.804837364,366.805671393,367.806505421,368.80733945,369.808173478,370.809007506,371.809841535,372.810675563,373.811509591,374.81234362,375.813177648,376.814011676,377.814845705,378.815679733,379.816513761,380.81734779,381.818181818,382.819015847,383.819849875,384.820683903,385.821517932,386.82235196,387.823185988,388.824020017,389.824854045,390.825688073,391.826522102,392.82735613,393.828190158,394.829024187,395.829858215,396.830692244,397.831526272,398.8323603,399.833194329,400.834028357,401.834862385,402.835696414,403.836530442,404.83736447,405.838198499,406.839032527,407.839866555,408.840700584,409.841534612,410.842368641,411.843202669,412.844036697,413.844870726,414.845704754,415.846538782,416.847372811,417.848206839,418.849040867,419.849874896,420.850708924,421.851542952,422.852376981,423.853211009,424.854045038,425.854879066,426.855713094,427.856547123,428.857381151,429.858215179,430.859049208,431.859883236,432.860717264,433.861551293,434.862385321,435.863219349,436.864053378,437.864887406,438.865721435,439.866555463,440.867389491,441.86822352,442.869057548,443.869891576,444.870725605,445.871559633,446.872393661,447.87322769,448.874061718,449.874895746,450.875729775,451.876563803,452.877397832,453.87823186,454.879065888,455.879899917,456.880733945,457.881567973,458.882402002,459.88323603,460.884070058,461.884904087,462.885738115,463.886572143,464.887406172,465.8882402,466.889074229,467.889908257,468.890742285,469.891576314,470.892410342,471.89324437,472.894078399,473.894912427,474.895746455,475.896580484,476.897414512,477.89824854,478.899082569,479.899916597,480.900750626,481.901584654,482.902418682,483.903252711,484.904086739,485.904920767,486.905754796,487.906588824,488.907422852,489.908256881,490.909090909,491.909924937,492.910758966,493.911592994,494.912427023,495.913261051,496.914095079,497.914929108,498.915763136,499.916597164,500.917431193,501.918265221,502.919099249,503.919933278,504.920767306,505.921601334,506.922435363,507.923269391,508.92410342,509.924937448,510.925771476,511.926605505,512.927439533,513.928273561,514.92910759,515.929941618,516.930775646,517.931609675,518.932443703,519.933277731,520.93411176,521.934945788,522.935779817,523.936613845,524.937447873,525.938281902,526.93911593,527.939949958,528.940783987,529.941618015,530.942452043,531.943286072,532.9441201,533.944954128,534.945788157,535.946622185,536.947456214,537.948290242,538.94912427,539.949958299,540.950792327,541.951626355,542.952460384,543.953294412,544.95412844,545.954962469,546.955796497,547.956630525,548.957464554,549.958298582,550.959132611,551.959966639,552.960800667,553.961634696,554.962468724,555.963302752,556.964136781,557.964970809,558.965804837,559.966638866,560.967472894,561.968306922,562.969140951,563.969974979,564.970809008,565.971643036,566.972477064,567.973311093,568.974145121,569.974979149,570.975813178,571.976647206,572.977481234,573.978315263,574.979149291,575.979983319,576.980817348,577.981651376,578.982485405,579.983319433,580.984153461,581.98498749,582.985821518,583.986655546,584.987489575,585.988323603,586.989157631,587.98999166,588.990825688,589.991659716,590.992493745,591.993327773,592.994161802,593.99499583,594.995829858,595.996663887,596.997497915,597.998331943,598.999165972,600.0) altd <- c(191) x <- seq.int((length(p)-1)/2*-1,(length(p)-1)/2) pdf('SLX-12998.D707_D507.HH772BBXX.s_2.r_1.fq.gz_model.pdf',height=6,width=6) plot(x,p,type='l',col=c('red'),main='Peak Model',xlab='Distance to the middle',ylab='Percentage') lines(x,m,col=c('blue')) legend('topleft',c('forward tags','reverse tags'),lty=c(1,1,1),col=c('red','blue')) plot(xcorr,ycorr,type='l',col=c('black'),main='Cross-Correlation',xlab='Lag between + and - tags',ylab='Correlation') abline(v=altd,lty=2,col=c('red')) legend('topleft','alternative lag(s)',lty=2,col='red') legend('right','alt lag(s) : 191',bty='n') dev.off()
640746c63f7be8aa735cf18230c88536ef222b54
5476725a7a3ea2c8e4396edd59e6d8d565f8d28d
/0.Tidy_data_boss.R
f80c205c1b674100437d14a5d72e55fdaf5b5678
[]
no_license
UWA-Marine-Ecology-Group-projects/GB_Habitat_Classification
49ecff1424abb1654f88ba5855b34d7528d8e702
9392d5e89ea60a440c6f5831ab571d594a09f077
refs/heads/master
2023-07-09T18:10:31.794091
2021-08-19T04:40:07
2021-08-19T04:40:07
375,555,452
0
0
null
2021-06-10T03:15:21
2021-06-10T03:15:20
null
UTF-8
R
false
false
5,670
r
0.Tidy_data_boss.R
### # Project: Geographe Bay # Data: BOSS # Task: Cleaning boss habitat data and adding spatial covariates # author: Kingsley Griffin # date: Aug 2021 # modified: Anita Giraldo 13/08/2021 # just added lines for directories and to save xy ## # library(reshape2) library(dplyr) # library(googlesheets4) library(raster) library(sp) # Clear memory ---- rm(list=ls()) ### Set directories ---- w.dir<- dirname(rstudioapi::getActiveDocumentContext()$path) d.dir <- paste(w.dir, "data", sep ='/') dt.dir <- paste(w.dir, "data/tidy", sep ='/') dr.dir <- paste(w.dir, "data/raw", sep ='/') setwd(w.dir) # get metadata from survey tracker googlesheet # bossd <- as.data.frame(read_sheet("https://docs.google.com/spreadsheets/d/1ZfW-XJKP0BmY2UXPNquTxnO5-iHnG9Kw3UuJbALCcrs/edit#gid=814068592", # sheet = "2021-03_Geographe_BOSS")) # saveRDS(bossd, 'data/2103_Geographe_BOSS_metadata.rds') # read in data bosmet <- readRDS('data/2103_Geographe_BOSS_metadata.rds') # boss metadata habdat <- read.table('data/raw/2021-03_Geographe_BOSS_Habitat_Dot Point Measurements.txt', skip = 5, sep = "\t") # habitat annotations downdat <- read.table('data/raw/2021-03_Geographe_BOSS_Downwards_Habitat_Dot Point Measurements.txt', skip = 5, sep = "\t") # downwards habitat annotations # clean all and merge to combine with metadata bosmet <- bosmet[, colnames(bosmet) %in% c("Date", "Time.bottom", "Latitude", "Longitude", "Site", "Sample", "Location", "Status", "Depth", "Type")] # only cols of interest summary(habdat) habdat <- habdat[ , c(1, 4, 5, 18:21, 23, 26)] # omit bare columns colnames(habdat) <- c("Filename", "Image row", "Image col", "Broad", "Morphology", "Type", "FOV", "CODE", "Radius") # fix colnames habdat$Site <- gsub(".jpg", "", habdat$Filename) downdat <- downdat[ , c(1, 4, 5, 18:21, 23, 26)] # omit bare columns colnames(downdat) <- c("Filename", "Image row", "Image col", "Broad", "Morphology", "Type", "FOV", "CODE", "Radius") # fix colnames downdat$Site <- gsub(".jpg", "", downdat$Filename) allhab <- merge(bosmet, habdat,by.x = "Sample", by.y = "Site") allhab$pa <- c(1) head(allhab) alldwn <- merge(bosmet, downdat,by.x = "Sample", by.y = "Site") alldwn$pa <- c(1) head(alldwn) # save #write.csv(alldwn, paste(dr.dir, "BOSS_downwards.xy.csv", sep ='/')) # convert to wide percent cover data allhabw <- dcast(allhab, Sample + Latitude + Longitude + Depth ~ Broad, value.var = "pa", fun.aggregate = sum, drop = TRUE) allhabw$totpts <- rowSums(allhabw[, 6:14]) - (allhabw$Unknown + allhabw$Var.5) head(allhabw) allhabw_pc <- allhabw allhabw_pc[6:14] <- sapply(allhabw_pc[, 6:14], FUN = function(x){ round((x/allhabw_pc$totpts)*100, 2)}) # calculate percent cover alldwnw <- dcast(alldwn, Sample + Latitude + Longitude + Depth ~ Broad, value.var = "pa", fun.aggregate = sum, drop = TRUE) alldwnw$totpts <- rowSums(alldwnw[, 5:12]) - (alldwnw$Unscorable + alldwnw$Var.5) alldwnw_pc <- alldwnw alldwnw_pc[6:11] <- sapply(alldwnw_pc[, 6:11], FUN = function(x){ round((x/alldwnw_pc$totpts)*100, 2)}) # calculate percent cover # bring in bathy raster and check alignment b2 <- raster('spatial_data/GBmultib_lidar_CMR.tif') allhab_sp <- SpatialPointsDataFrame(coords = cbind(allhabw_pc$Longitude, allhabw_pc$Latitude), data = allhabw_pc) alldwn_sp <- SpatialPointsDataFrame(coords = cbind(alldwnw_pc$Longitude, alldwnw_pc$Latitude), data = alldwnw_pc) plot(b2) plot(allhab_sp, add = T) # calculate bathy derivatives slope4 <- terrain(b2, "slope", unit = "degrees", neighbors = 4) slope8 <- terrain(b2, "slope", unit = "degrees", neighbors = 8) aspect4 <- terrain(b2, "aspect", unit = "degrees", neighbors = 4) aspect8 <- terrain(b2, "aspect", unit = "degrees", neighbors = 8) tpi <- terrain(b2, "TPI") tri <- terrain(b2, "TRI") rough <- terrain(b2, "roughness") flowdir <- terrain(b2, "flowdir") preds <- stack(b2, slope4, slope8, aspect4, aspect8, tpi, tri, roughness, flowdir) names(preds)[c(1:4, 8)] <- c("slope4", "slope8", "aspect4", "aspect8", "roughness") namesp <- names(preds) # extract predictor data allhab <- cbind(allhabw_pc, extract(preds, allhab_sp)) head(allhab) summary(allhab) alldwn <- cbind(alldwnw_pc, extract(preds, alldwn_sp)) head(alldwn) summary(alldwn) # exclude sites outside of bathy area allhab <- na.omit(allhab) alldwn <- na.omit(alldwn) # # if we want presence/absence at the image scale # allhab[, 6:14] <- sapply(allhab[, 6:14], # FUN = function(x){ifelse(x > 1, 1, 0)}) # convert to binomial # alldwn[, 6:11] <- sapply(alldwn[, 6:11], # FUN = function(x){ifelse(x > 1, 1, 0)}) # convert to binomial # saveRDS(allhab, "data/tidy/2103_Geographe_BOSS_habitat.rds") saveRDS(alldwn, "data/tidy/2103_Geographe_BOSS_downwardshabitat.rds")
fbd95b008caa1e107365a3dbd9b0ad424373c36b
a0ceb8a810553581850def0d17638c3fd7003895
/scripts/scripts_analysis/all_merged_analysis/2-downstream_LDA.R
662d5955b5d5eec1d9528c92517919480d5670ab
[]
no_license
jakeyeung/sortchicAllScripts
9e624762ca07c40d23e16dbd793ef9569c962473
ecf27415e4e92680488b6f228c813467617e7ee5
refs/heads/master
2023-04-15T22:48:52.272410
2022-10-24T10:45:24
2022-10-24T10:45:24
556,698,796
0
0
null
null
null
null
UTF-8
R
false
false
2,612
r
2-downstream_LDA.R
# Jake Yeung # Date of Creation: 2019-12-07 # File: ~/projects/scchic/scripts/scripts_analysis/all_merged_analysis/2-downstream_LDA.R # Downstream LDA rm(list=ls()) library(dplyr) library(tidyr) library(ggplot2) library(data.table) library(Matrix) library(hash) library(igraph) library(umap) library(scchicFuncs) # Load ------------------------------------------------------------------- # all marks jmark <- "H3K27me3" inf <- paste0("/Users/yeung/data/scchic/from_cluster/ldaAnalysisBins_B6BM_All_allmarks_mergedtagged_dedupfixed_redo/lda_outputs.B6BM_AllMerged_", jmark, ".TAcutoff_0.5.countscutoff_1000.binfilt_cellfilt.2019-12-05.K-30.binarize.TRUE/ldaOut.B6BM_AllMerged_", jmark, ".TAcutoff_0.5.countscutoff_1000.binfilt_cellfilt.2019-12-05.K-30.Robj") assertthat::assert_that(file.exists(inf)) load(inf, v=T) tm.result <- posterior(out.lda) topics.mat <- tm.result$topics jsettings <- umap.defaults jsettings$n_neighbors <- 30 jsettings$min_dist <- 0.1 jsettings$random_state <- 123 umap.out <- umap(topics.mat, config = jsettings) dat.umap.long <- data.frame(cell = rownames(umap.out$layout), umap1 = umap.out$layout[, 1], umap2 = umap.out$layout[, 2], stringsAsFactors = FALSE) %>% rowwise() %>% mutate(experi = strsplit(cell, split = "-")[[1]][[5]]) # ggplot(dat.umap.long, aes(x = umap1, y = umap2, color = experi)) + geom_point() + theme_bw() + theme(aspect.ratio=1, panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + # theme_bw() + theme(aspect.ratio=1, panel.grid.major = element_blank(), panel.grid.minor = element_blank()) ggplot(dat.umap.long, aes(x = umap1, y = umap2, color = experi)) + geom_point() + theme_bw() + theme(aspect.ratio=1, panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + theme_bw() + theme(aspect.ratio=1, panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + facet_wrap(~experi) # get variance jchromos <- paste("chr", c(seq(19), "X", "Y"), sep = "") dat.impute.log <- log2(t(tm.result$topics %*% tm.result$terms)) dat.var <- CalculateVarAll(dat.impute.log, jchromos) dat.merge <- left_join(dat.umap.long, dat.var) ggplot(dat.merge, aes(x = umap1, y = umap2, color = cell.var.within.sum.norm)) + geom_point() + theme_bw() + theme(aspect.ratio=1, panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + theme_bw() + theme(aspect.ratio=1, panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + scale_color_viridis_c(direction = -1) + facet_wrap(~experi) # Find topics ------------------------------------------------------------
f5619a9af1828da5d92f5c9be7e5830779c0ba97
ab1730e13eb49478aa0cc443d40c68921cbe1662
/man/StockChanges.Rd
0dfd309de691316adc7632356f583f9234a676f5
[]
no_license
cran/Lock5Data
688fa73667eacea4f4a325763907bba30f55c030
770f5fd2b8956dbb0c822133223f9c811561f130
refs/heads/master
2021-08-02T06:23:39.102769
2021-07-22T21:40:10
2021-07-22T21:40:10
17,680,339
0
0
null
null
null
null
UTF-8
R
false
false
727
rd
StockChanges.Rd
\name{StockChanges} \alias{StockChanges} \docType{data} \title{ Stock Changes } \description{ Stock price change for a sample of stocks from the S&P 500 (August 2-6, 2010) } %\usage{data(StockChanges)} \format{ A dataset with 50 observations on the following variable. \tabular{rl}{ \code{SPChange} \tab {Change in stock price (in dollars)} \cr } } \details{ A random sample of 50 companies from Standard & Poor's index of 500 companies was selected. The change in the price of the stock (in dollars) over the 5-day period from August 2 - 6, 2010 was recorded for each company in the sample. } \source{ Data obtained from \emph{http://money.cnn.com/data/markets/sandp/} } \keyword{datasets}
4afc8950caa21de07e084c5ae739b2ed7cdb5525
261e86602bc68e647ce1c2335694bb186a18952d
/man/tor_ppo.Rd
5775180585ca0c2d4931ba5d1519e13114fb839a
[]
no_license
vullioud/torpor
9b600eebe41f3904f72a7b6c7c2c9bbc7743cb1c
f7fbf134e1ae7fd7c9b6d2ee31c803e79d59c91b
refs/heads/master
2023-06-24T11:42:09.732894
2023-06-16T09:01:00
2023-06-16T09:01:00
139,414,327
0
0
null
2023-06-16T08:36:40
2018-07-02T08:33:03
R
UTF-8
R
false
true
856
rd
tor_ppo.Rd
% Generated by roxygen2: do not edit by hand % Please edit documentation in R/tor_summarise.R \name{tor_ppo} \alias{tor_ppo} \title{Check priors/posteriors overlap} \usage{ tor_ppo(tor_obj) } \arguments{ \item{tor_obj}{a fitted model from \code{\link[=tor_fit]{tor_fit()}}} } \value{ a data.frame } \description{ \code{\link[=tor_ppo]{tor_ppo()}} generates prior/posterior overlap values for Tlc, Tt and Betat. Values larger than 0.3 should lead to the conclusion that conforming torpor, regulated torpor or thermoregulation respectively could not be modeled with the data provided (Fasel et al. (in prep)). \code{\link[=tor_ppo]{tor_ppo()}} can be used independently but is also used internally in \code{\link[=tor_summarise]{tor_summarise()}}. } \seealso{ Other summary: \code{\link{get_parameters}()}, \code{\link{tor_summarise}()} } \concept{summary}
8e6131efce72582aeb1c50f20a544b14c02754a7
859a2bdab8ba9943fffde77a0a930ba877c80fd9
/R/create_background_panel_instance.R
a0f5c0fe6cb9957b246dd635c84328b04cb35a56
[ "MIT" ]
permissive
alkodsi/ctDNAtools
e0ed01de718d3239d58f1bfd312d2d91df9f0f0d
30bab89b85951282d1bbb05c029fc333a139e044
refs/heads/master
2022-03-20T11:47:06.481129
2022-02-20T11:25:48
2022-02-20T11:25:48
208,288,617
30
9
null
null
null
null
UTF-8
R
false
false
4,027
r
create_background_panel_instance.R
#' Creates a background panel instance from a bam file (e.g. healthy samples) #' #' This function scans the targets regions in one bam file, and reports the number of reference, non-reference reads for each loci #' in addition to the non-reference (VAF) allele frequency. Loci with VAF higher than vaf_threshold are masked with NA. This function is #' used internally by create_background_panel #' @param bam A character specifying the path to bam file. #' @param targets The targets data frame must have the columns chr, start and end. #' @param reference The reference genome as BSgenome object. #' @param vaf_threshold Loci with the fraction of non-reference reads above this value are masked with NA. #' @param tag The RG tag in the bam file. Empty string defaults to using the whole bam. #' @param min_base_quality The minimum base quality to count a read for a loci. #' @param max_depth Maximum depth for the pileup #' @param min_mapq The minimum mapping quality to count a read for a loci #' @param substitution_specific logical, whether to have the loci by substitutions. #' @return A named list having depth, alt and vaf data frames. Each has the same order of loci in rows and the input sample in columns. #' @keywords internal create_background_panel_instance <- function(bam, targets, reference, vaf_threshold = 0.05, tag = "", min_base_quality = 20, max_depth = 1e+05, min_mapq = 30, substitution_specific = TRUE) { gr <- GenomicRanges::reduce(GenomicRanges::GRanges(targets$chr, IRanges::IRanges(targets$start, targets$end))) if (tag == "") { sbp <- Rsamtools::ScanBamParam(which = gr) } else { sbp <- Rsamtools::ScanBamParam(which = gr, tagFilter = list(RG = tag)) } pileup_param <- Rsamtools::PileupParam( max_depth = max_depth, min_base_quality = min_base_quality, min_mapq = min_mapq, distinguish_strands = FALSE, include_deletions = FALSE, include_insertions = FALSE ) p <- Rsamtools::pileup(bam, scanBamParam = sbp, pileupParam = pileup_param) %>% tidyr::pivot_wider( names_from = .data$nucleotide, values_from = .data$count, values_fill = list(count = 0) ) %>% as.data.frame() %>% dplyr::mutate(ref = as.character(BSgenome::getSeq( reference, GenomicRanges::GRanges(.data$seqnames, IRanges::IRanges(.data$pos, .data$pos)))) ) %>% dplyr::mutate(depth = .data$A + .data$C + .data$G + .data$T) if (substitution_specific) { p_ann <- p %>% dplyr::mutate( VAFC = .data$C / .data$depth, VAFT = .data$T / .data$depth, VAFG = .data$G / .data$depth, VAFA = .data$A / .data$depth ) %>% tidyr::pivot_longer(names_to = "alt", cols = dplyr::starts_with("VAF"), values_to = "vaf") %>% dplyr::mutate(alt = gsub("VAF", "", .data$alt)) %>% dplyr::filter(.data$ref != .data$alt) %>% dplyr::mutate( Locus = paste(.data$seqnames, .data$pos, .data$ref, .data$alt, sep = "_"), nonRefCount = .data$depth * .data$vaf ) %>% dplyr::select(.data$Locus, .data$depth, .data$nonRefCount, .data$vaf) } else { p_ann <- dplyr::mutate(p, refCount = purrr::map2_dbl(c(1:nrow(p)), p$ref, ~ p[.x, .y]), nonRefCount = .data$depth - .data$refCount, vaf = .data$nonRefCount / .data$depth ) %>% dplyr::mutate( nonRefCount = ifelse(.data$vaf >= vaf_threshold, NA, .data$nonRefCount), depth = ifelse(.data$vaf >= vaf_threshold, NA, .data$depth), vaf = ifelse(.data$vaf >= vaf_threshold, NA, .data$vaf), Locus = paste(.data$seqnames, .data$pos, sep = "_") ) %>% dplyr::select(.data$Locus, .data$depth, .data$nonRefCount, .data$vaf) } out <- list( depth = data.frame(Locus = p_ann$Locus, depth = p_ann$depth, stringsAsFactors = FALSE), alt = data.frame(Locus = p_ann$Locus, alt = p_ann$nonRefCount, stringsAsFactors = FALSE), vaf = data.frame(Locus = p_ann$Locus, vaf = p_ann$vaf, stringsAsFactors = FALSE) ) return(out) }
467d3504cf26b28bfe72299d5b153362fa0650db
0c6032eb0f9711b6de7ef08e7349197c620952f0
/STabundance/man/d_logP_Z.Rd
16592368ead9f2c8e0de51232d706f9635a96569
[]
no_license
pconn/STabundance
75c3b8efc27112b086711442a854ce8d27a914e3
ef6ccccf0fae635d7a9f6b1a49d3c1bc34dd6f44
refs/heads/master
2021-01-01T05:35:05.392653
2016-01-29T21:45:07
2016-01-29T21:45:07
15,171,892
3
1
null
2016-01-29T21:45:07
2013-12-13T19:19:16
TeX
UTF-8
R
false
false
923
rd
d_logP_Z.Rd
% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/util_funcs.R \name{d_logP_Z} \alias{d_logP_Z} \title{Calculate partial derivative vector for for Langevin Z MH updates (for OPRS model) (Assuming function is called separately for each multinomial update)} \usage{ d_logP_Z(Z, Log.offset, Counts, Mu, tau) } \arguments{ \item{Z}{Current values of Z} \item{Log.offset}{The log of offset values (e.g. proportion of area surveyed)} \item{Counts}{Animal counts for current time step being updated} \item{Mu}{Expected value for Omega} \item{tau}{precision for exchangable errors} } \value{ Vector of partial derivates evaluated at Omega } \description{ Calculate partial derivative vector for for Langevin Z MH updates (for OPRS model) (Assuming function is called separately for each multinomial update) } \author{ Paul Conn \email{paul.conn@noaa.gov} } \keyword{expit} \keyword{logit,}
e386af4957dccd2409a42df3bc5510c567c8d077
aad2ba18223ae709bd1ae8546a8cbf1cc8e1af4a
/scripts/functions/cache_RDS.R
bf00914d9e5a5e2c2c44d8874ed9dd2f06497cdc
[ "MIT" ]
permissive
rubysaltbush/pollination-macroevolution
b20c3d43d4db18ef61e49a02b323705b0db3750f
1693b63a60f0d4fdb27e9fe2627af83b2239950f
refs/heads/main
2023-06-25T01:37:12.459831
2023-06-20T00:57:55
2023-06-20T00:57:55
551,184,048
2
0
null
null
null
null
UTF-8
R
false
false
412
r
cache_RDS.R
# function to cache pre-prepared R data. If RDS already in cache will read data # from cache, if not will run defined script to produce and then cache data cache_RDS <- function(path, fetch_function, read_function = readRDS, save_function = saveRDS) { if (file.exists(path)) { read_function(path) } else { data <- fetch_function() save_function(data, path) data } }