Match values in 2 dataframes, NA error - r

It is necessary to use the data presented here, for the sake of the problem.
I would like to match values from 2 dataframes. however some values are not "matched", and I cannot see why!
I will try to concisely explain my problem.
1) dataframe with theoretical values
#1.1) I have the following vector
Pos<-c(8.75, 9.3, 8.8, 9.6, 9.4, 11, NA, 13, 10.5, 12.31, 11.18, 13.06, 10.71, 12.5, 15.03, 15.26, 13.22, 15.25, 13.03, 15.28, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 9.2, NA, 9.6, NA, 10.93, NA, 11.19, NA, 10.86, 10.3, 9.4, 9.1, 9.1, 9.4, 9.7, 8.9, 9.86, 9.2, 9.2, NA, NA, NA, NA, NA, NA, NA, 10.9, NA, NA, 10.92, 10.69, 9.91, 10.01, NA, 10.66, NA, 10.38, NA, 11.4, 7.4, 7.3, 9, 9.6, NA, NA, 8, 9.3, NA, NA, 9.33, 9.9, 9.9, 11.2, 6.9, 7.3, 7, 8.7, 7.4, 8.6, 7.6, 9.24, 8.59, 8.6, 8.46, NA, 8.21, 9, 6.6, 8.5, 8.5, 10.2, 9.6, 9.55, NA, NA, 7.8, 9.6, NA, NA, 10.5, 11.4, 11.81, 9.7, NA, NA, 7.8, 8.9, NA, NA, NA, 12.29, NA, 11, NA, NA, NA, 11.11, NA, NA, 8.1, 8.1, 8.3, 10.2, NA, NA, 8.2, 11, NA, NA, NA, 8.7, NA, 8.9, NA, 11.3, NA, 12.2, NA, 12.5, 10.76, 14, 11.19, 15.4, NA, NA, 8.9, 10.9, NA, NA, 9.04, 9.74, 9.41, 9.43, 10.96, 10.93, 13.06, 10.31, 11.69, 8.66, 9.11, 8.87, 9.61, 8.99, 9.48, 9.58, 9.26, 9.29, 8.4, 8.5, 8.2, 8.3, 12.1, 8.7, 13.9, 8.8, 7.79, 10.45, 9.56, 9.66, 10.55, 11.76, 9.31, 12.36, 9.33, 10.71, 13.03, 12.36, 11.88, 11.94, 12.83, 13.51, 12.54, 14.29, 11.43, 11.19, 11.4, 9.9, 13.21, 11.1, 12.75, 12.03, 11.55, 10.3, 10.26, 10.31, 8.9, 8.8, 9.12, 10.35, 9.2, 9.3, 8.9, 7.7, 8.51, 8.2, 8.2, 8.54, 8.6, NA, 8, 8.5, 8.84, 8.22, 9.78, 7.8, 7.5, 7.7, 7.7, 9.68, 8.1, 8.21, 7.91, 8.11, 9.21, 9.01, 9.89, 8.2, 8.56, 10.19, 9.1, 9, 10.46, 8.7, 10.16, 8.9, 8.7, 9.6, 7.76, 7.76, 8.51, 10.26, 7.2, 11.71, 11.43, 11.24, 7.3, 9.13, 8.74, 8.81, 8.61, 8.63, 9.43, 8.93, 9.13, 9.33, 7.47, 7.21, 7.71, 8.28, 7.48, NA, 7.44, 8.81, 7.42, 7.25, 6.1, 8.74, 8.51, 6.7, 8.76, 6.2, 7.94, 8.51, 6.8, 13.03, 13.09, 12.9, 13.34, 13.07, 12.02, 12.94, 12, 12.61, 9.96, 8.79, 8.91, 9.2, 8.73, 8.61, 7.89, 8.17, 11.71, 8.99, 11.35, 10.36, 9.67, 8.86, 10.2, 11.17, 12.75, 12.49, 7.6, 9.62, 8.1, 9.93, 12.4, NA, NA, 8.3, 9.95, 7.4, 9.21, 9.34, 10.09, 7.9, 9.64, 7.6, 10.19, 12.65, 10.3, 10.3, 11, 11.66, 16, 11, 12.7, 11, 11.4, 11.49, 12.79, 16.65, NA, 11.75, 12.94, 13.3, 11.3, 9.86, 10.9, 12.08, 11, 9.99, 12.81, 12.36, NA, NA, 7.66, 6.5, 6.3, 6.4, 7, 7.1, 8.48, 6.8, 7.75, 12.97, 12.88, 12.49, 12.59, 12.83, 11.59, 8.9, 13.93, 13.35, 13.63, 14.64, 13.53, 13.64, 13.68, 13.38, 13.97, 12.98, 12.35, 12.89, 9.54, 9.3, 10.16, 10.71, 11.95, 12.03, 9.26, 10.15, 10.26, 6.7, 6.6, 7, 6.3, 7.76, 8.21, 7.7, 7.6, 13.49, 12.2, NA, 12.76, 12.78, 12.5, 13.57, 12.3, 12.84, 15.85, 11.26, 9.4, 11.16, 10.69, 11.43, 10.17, 10.51, 13.27, 11.39, 10.9, 10.54, NA, 10, 11.64, 10.6, 10.1, NA, 11.29, 7.61, 7.3, 7, 9.3, 13.33, 8.01, 8.16, 7.1, 9.91, 8.08, 11.33, 7.4, 10.39, 9, 11.5, 10.68, 8.53, 9.3, 11.19, 15.62, 11.02, 10.3, 9.7, 11.3, 10.5, 10.84, 13.86, 7.9, 7.6, 9.46, 7.9, 7.8, 9.33, 9.79, 7.7, 8.5, 8.3, 8.2, 8.1, 8.1, 10.2, 7.9, 8.3, 9.56, 9.34, 8.6, 9.6, 9.27, 8.1, 11.8, 9.74, 8.9, 8.3, 9.7, 7.6, 7.2, 9.21, 7.8, 7, 7.1, 8.1, 8.85, 9.4, 9.91, 9.44, 10.06, 8.6, 10.2, 10.55, NA, NA, 12.79, NA, NA, 9.75, 13.11, 14.54, NA, 14.36, 10.18, 14, 12.1, 15.26, NA, 10.99, 9.59, 10.9, 10.81, 9.3, 8.2, 8.75, 9.6, 8.9, 11.11, 11, 12, 10.9, 10.96, 8.99, 12.1, 11.76, 12.83, 11.1, 9.12, 8.54, 7.5, 9.01, 10.16, 11.71, 9.43, NA, 8.76, 13.07, 8.73, 8.86, 12.4, 7.9, 16, 11.75, 12.81, 7.1, 11.59, 13.38, 11.95, 7.76, 12.5, 11.43, 11.64, 13.33, 9, 9.7, 7.8, 10.2, 11.8, 7, 10.2, 14.54)
#1.2) Height, is the column to be filled
Pos.table<-data.frame(Pos=Pos,Height=NA)
2) dataframe with theoretical values
#2.1) the whole range of values that "Pos" can get
Source<- seq(0,17,0.01) #possible values that weight can get [0,17]
#2.2)height.0, the adjusted value of Height according to the Loop below
Table.match<- data.frame(Source=Source,Height.0=NA)
# loop for Source (real values)
for (i in 1:dim(Table.match)[1])
{
Table.match[i,"Height.0"] <- -57.5+5*(Table.match[i,"Source"])
}
2) Problem
The following Loop looks for respective matches.
for (i in 1:dim(Pos.table)[1])
{
H.i<-match(Pos.table[i,"Pos"], Table.match[,"Source"], nomatch = 0)
Pos.table[i,"Height"] <-ifelse(H.i,Table.match[H.i,"Height.0"],0)
# Rev.table[i,"Rev.Prot"]<-Rev.table[i,"Rev.Prot"]*Rev.table[i,"Yield"]
}
However, some values ares disregarded. for example, position 15 and 20 (among many others):
# both return NAs
match(15.03, Table.match[,"Source"])
match(15.28, Table.match[,"Source"])
Could you please advice me on how to overcome this problem?

I agree with Nicole that exact comparison between floating numbers should be avoided.
To solve that, I've just added a round() with 2 significant digits in the code:
for (i in 1:dim(Pos.table)[1])
{
H.i<-match(round(Pos.table[i,"Pos"],2), round(Table.match[,"Source"],2), nomatch = 0)
Pos.table[i,"Height"] <-ifelse(H.i,Table.match[H.i,"Height.0"],0)
# Rev.table[i,"Rev.Prot"]<-Rev.table[i,"Rev.Prot"]*Rev.table[i,"Yield"]
}
I guess this solves the problem.

Related

Why do quantile function in R gives unequal count of values in each group

I am trying to group a continuous value data into tertile. I am using the function quantile to do this. following is my code
dd$wbc_tert = with(dd,
cut(wbc,
vTert,
include.lowest = T,
labels = c("Low", "Medium", "High")))
Isn't it supposed to give equal count of values in each group? I am getting different count in the groups.
> dd %>% filter(wbc_tert == 'High') %>% select('wbc') %>% nrow()
[1] 143
> dd %>% filter(wbc_tert == 'Low') %>% select('wbc') %>% nrow()
[1] 148
> dd %>% filter(wbc_tert == 'Medium') %>% select('wbc') %>% nrow()
[1] 139
This is the dput of the values
c(10.9, 5.4, 9.1, 7.4, 6.6, 5.5, 4.4, 6.7, 7.8, 6.7, 6.6, 8.6,
8.4, 4.8, 7, 5.2, 7, 6.7, 10.4, 7.5, 8.5, 6.8, 8.5, 9.4, 4.6,
6.8, 10.2, 6.7, 4.6, 4.9, 6.7, 8.9, 5.9, 5.9, 9.9, 4.1, 8.4,
9, 7.7, 8.2, 5.7, 8.4, 7.7, 4.6, 6.5, 7.3, 4.9, 3.8, 6.2, 7.9,
5.3, 8.9, 6, 4.8, 5.9, 5.4, 8.6, 6.1, 9.5, 5.8, 6.2, 5.8, 7.9,
9.6, 6.6, 9.6, 7, 10.1, 9, 6.9, 9.1, 6.8, 8.4, 9.6, 4.4, 10.5,
7.9, 5.6, 5.1, 6.6, 6.5, 12.7, 5.3, 7.7, 4.8, 4.7, 6.1, 4.3,
6.1, 11.6, 5.9, 7.4, 5.7, 4.7, 4.8, 8.5, 5.6, 7.9, 9.1, 7.8,
5.3, 5, 8.1, 8.3, 4.7, 5.4, 7.6, 7.2, 5.7, 7.9, 7.9, 6.4, 3.8,
4.7, 6.2, 5, 7.6, 5.8, 5.4, 4.3, 6, 4.7, 6, 6.1, 5.8, 5.6, 4.7,
5, 11.5, 6.3, 4.4, 6.8, 6.6, 6.8, 6.1, 4.8, 5.4, 5.8, 5.2, 7.1,
5.4, 9.1, 6.9, 5.4, 8.5, 5.3, 7.3, 6.9, 9, 6.3, 8.4, 7.8, 5.7,
6.4, 5.3, 9.6, 6.4, 9.9, 8.9, 7.7, 6.2, 7.2, 4.6, 5.4, 4.6, 11.2,
3.1, 12.3, 5.9, 11.1, 6.2, 6.6, 4.1, 7.4, 9.4, 4.1, 6.7, 6.7,
6.1, 6.3, 5.6, NA, 3.7, 6.8, 6.7, 6.4, 7.3, 5.7, 6.7, 6.9, 5.7,
5.3, 4, 5.6, 4.8, 5.5, 6, 6.6, 3.6, 5.6, 8.9, 6.3, 5.8, 8.2,
8.6, 8.5, 5.7, 8.6, 6, 5.1, 5.7, 8.2, 5.4, 6.9, 6.9, 8.3, 9.5,
5.4, 10.2, 8.8, 7.2, 4.8, 9.8, 4.6, 6.3, 5.8, 4.9, 12.7, 7.5,
10.6, 9.3, 5.5, 10.7, 6.2, 9.3, 8.3, 7.8, 8.05, 9.57, 6.62, 6.21,
5.34, 6.11, 10.37, 4.45, 5.55, 8.05, 8.31, 5.06, 6.05, 4.76,
9.09, 9.11, 9.04, 6.99, 6.33, 9.47, 6.48, 4.46, 9.44, 6.88, 7.09,
5.75, 10.89, 6.68, 3.64, 6.55, 8.69, 5.89, 9.05, 6.38, 11.62,
9.11, 9.22, 7.97, 9.64, 12.76, 8.39, 6.57, 8.1, 7.3, 10.1, 4.7,
6.4, 7.2, 5.5, 3.7, 5.1, 9.8, 7.6, 7.7, 6, 3.9, 6.8, 5.4, 5.4,
9.7, 9, 6, 7.3, 6.3, 5.8, 8.3, 7, 4.1, 11.2, 5, 7.6, 6.5, 4.8,
8, 10.1, 7.1, 7.4, 4.3, 4, 10.12, 4.3, 7.26, 8.84, 8.44, 8.44,
8.12, 6.5, 8.58, 8.55, 8.82, 4.53, 9.51, 4.93, 4.42, 4.69, 8.69,
5.77, 3.37, 6.58, 3.72, 3.09, 7.13, 8.11, 7.2, 12.18, 6.52, 7.91,
5.69, 8.24, 7.67, 5.69, 4.85, 7.03, 4.16, 3.57, 8.1, 4.61, 5.98,
5.13, 7.68, 5.47, 5.54, 4.59, 6, 11.62, 7.38, 7.06, 8.74, 8.02,
6.73, 7.19, 6.36, 4.86, 6.55, 8.4, 7.76, 4.73, 4.8, 5.73, 8.53,
4.6, 7.96, 9.48, 6.59, 5.75, 6.61, 6.49, 7.91, 6.92, 7.14, 6.24,
12.53, 7.03, 4.73, 8.05, 7.26, 4.07, 6.7, 5.7, 7.39, 5.2, 6.61,
6.8, 6.77, 5.65, 6.08, 7.24, 6.13, 7.92, 7.37, 7.99, 3.31, 9.72,
8.71, 8.35, 5.05, 8.15, 5.1, 5.4, 8.8, 4.9, 5, 7.43, 10.3, 6.3,
9.5, 6.9, 6.7, 5.4, 7.7, 8, 6.5, 5.6, 9.7)
Can someone please help what could be the reason
Here is an example that shows that quantiles are not necessarily symmetric in the number of values.
# Define some data
x <- 1:10
y <- rep(1:2, 10)
# Look at the quantiles
quantile(x)
#> 0% 25% 50% 75% 100%
#> 1.00 3.25 5.50 7.75 10.00
# Due to the added y we now have asymmetry in sizes
quantile(c(y,x))
#> 0% 25% 50% 75% 100%
#> 1.00 1.00 2.00 2.75 10.00
# Notice how the number of values below 50 % and 75 % changes.
## Without y we get roughly the same bin size
sum(x<quantile(x, .5))
#> [1] 5
sum(x<quantile(x, .75))
#> [1] 7
## But when we add y, there is a doubling of values despite we only increase
## the percentile with 25 %
sum(c(y,x)<quantile(c(y,x), .5))
#> [1] 11
sum(c(y,x)<quantile(c(y,x), .75))
#> [1] 22
Created on 2022-08-18 by the reprex package (v2.0.1)
There are 9 ways to compute the quantiles with function quantile, the default is type = 7.
Use findInterval instead of cut.
vTert <- quantile(dd$wbc, (0:3)/3, na.rm = TRUE)
dd$wbc_tert <- findInterval(dd$wbc, vTert, rightmost.closed = TRUE, all.inside = TRUE)
dd$wbc_tert <- factor(dd$wbc_tert, labels = c("Low", "Medium", "High"))
table(dd$wbc_tert, useNA = "always")
#>
#> Low Medium High <NA>
#> 143 143 144 1
Created on 2022-08-18 by the reprex package (v2.0.1)

Count the number of EVENTS which "var" is between "level1" and "level2" for "n" hours

Hi I have a question some of you could help me out.
My vector is temperature collected hourly:
a<-c(7.95, 7.8, 7.85, 7.6, 7.1, 5.55, 4.35, 4.1, 7.35, 10.7, 14.2,
17.25, 19.1, 19.8, 20.1, 20.15, 19.9, 18.95, 16.7, 14.4, 13.75,
12.1, 12.3, 11.4, 10.3, 8.55, 7.45, 7.05, 5.6, 5.95, 4.85, 5.3,
9.35, 12.7, 16.15, 19.1, 20.5, 21.05, 21.4, 21.4, 21.35, 20.1,
16.95, 15.8, 15.6, 14.95, 14.15, 13.85)
I want to determine how many events there are which a is above 20 and below 10 for a certain period of time.
Pictorially, this is what I am looking for. Here there are two events (blue and green) where temperature amplitude threshold was achieved. Result should be 2.
============
Another example:
Here temperature was below 10 & above 20 for at least 1 hour, two times (or two events).
Result should be 2.
Data for example 2:
b<-c(20.2, 20.55, 20.85, 21.7, 20.7, 18.7, 17.5, 17.4, 16.65, 17.15,
15.8, 13.85, 12.55, 11.45, 10.2, 9.3, 8.2, 7.4, 7.25, 6.65, 5.9,
4.75, 4.5, 4.15, 4.4, 6.25, 8.1, 10.35, 12.4, 14.3, 15.3, 16.3,
17.25, 17.25, 16.85, 14.45, 12.85, 11.35, 10.2, 9.1, 8.6, 7.35,
5.9, 4.85, 3.65, 3.3, 2.95, 2.65, 2.45, 4.85, 6.45, 8.25, 9.95,
11.1, 12.3, 13.2, 13.95, 14.05, 13.15, 10.35, 8.15, 6.6, 6.3,
6, 7.55, 5.85, 5.05, 4.75, 4.5, 4.75, 4.75, 4.55, 5.15, 8.45,
12.05, 16.35, 18.9, 20.55, 21.6, 21.45, 21.75, 21.15, 20.05,
17.75, 16.5, 18.2, 18.05, 17.95, 17.8, 17.55, 17.25, 16.95, 16.6,
16.35, 16.1, 16.25, 16.4, 17.1, 17.8)
I update my answer using your new example b. I found a solution based on: Find a numeric pattern R .
# Get out of range (10,20)
x = ifelse(b<=10,1,0) # Don't need nested ifelse
# Specify if 2 for upper limit [20,inf)
x[b>=20]=2
z = rle(x)
> z
Run Length Encoding
lengths: int [1:10] 5 10 12 12 14 7 14 3 6 16
values : num [1:10] 2 0 1 0 1 0 1 0 2 0
Like your plot, there is two combinations of going lower limit to upper limit or the other way round: 2-0-1 or 1-0-2. You can do:
ranges = z$values
# This line looks for 0 -groups of T in range (10,20)- and the looks if the group before is 1 and the next 2 (low to up) or 2 and 1 (up to low)
x = as.integer(ranges == 0 & ( (lag(ranges)==2 & lead(ranges)==1) | (lag(ranges)==1 & lead(ranges)==2) ) )
x
[1] 0 1 0 0 0 0 0 1 0 NA
You can sum, omitting the NAs, to return 2:
sum(x, na.rm=TRUE)
You could remove 0s and just look for 1 followed by 2 or the other way round but it is the same concept. If you want to keep the z$lengths to work with them later, you could transform rle() output to a dataframe and adapt the code to mutate a new column.

Using a Unique Identifier, Match Row Values with Column Names in R

Master
StoreNumber Online Pressure MON TUE WED ... SUN ...
1 0.2 50 0 0 0 ... 0
2 0.8 20 0 0 0 ... 0
3 1.2 10 0 0 0 ... 0
...
Hours
BranchNumber Day ... Time
1 MON 7.50
1 TUE 6.00
1 WED 8.50
3 MON 2.00
3 TUE 1.00
3 WED 2.50
...
NB There are many branch numbers about 10,500 due to being 7 days in a week so one branch number may occur 7 times for each day of the week, but some may only have 6 or 5 etc.
The idea is I want to populate the days of the week "Mon", "Tue", "Wed"... "Sun" etc in the 'Master' table from the 'Time' data in the 'Hours' Table. The match should check that the StorenNumber matches the BranchNumber...then the day of the week, if there is 'Mon' in the hours table then it should match it to the column 'Mon' in the Master table.
So the output will look something like this
StoreNumber Online Pressure MON TUE WED ... Hours
1 0.2 50 7.50 6.00 8.50 ... 53
2 0.8 20 0 0 0 ... 30
3 1.2 10 2.00 1.00 2.50 ... 20
...
As an example BranchNumber 2 doesnt exist in the Hours table so it should just skip each column and leaves the inputs as 0
I have tried the R based code below but am struggling to get an output...Once running the code I get zero errors but the Master Table remains unchanged and all days of the week columns remain as 0
merged <- Master%>% select(-
c("MON","TUE","WED","THU","FRI","SAT","SUN")) %>%
left_join(
Hours %>% pivot_wider(names_from = Day, values_from =
Time),
by = c("StoreNumber" = "BranchNumber"))
merged <- merged %>% replace(is.na(.),0)
Dput(Master)
Pressure = c(0, 0, 0, 0, 0, 0, 0, 0, 0.23, 0,
0.19, 0, 0, 0, 0.56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0.42, 0, 0, 0, 0, 0.37, 0, 0, 0.92, 0, 0, 0, 0,
0.04, 0.15, 0.12, 0.12, 0.06, 0.02, 0.19, 0.12, 0.08, 0.15,
0.02, 0.46, 0.25, 0.02, 0.17, 0.06, 0.25, 0.08, 0, 0.08,
0, 0.12, 0.23, 0.02, 0.04, 0.02, 0.15, 0, 0.02, 0.1, 0, 0,
0.04, 0.02, 0.23, 0.48, 0.19, 0.06, 0.02, 0.02, 0.08, 0.13,
0, 0.02, 0.08, 0.06, 0.15, 0.42, 0.06, 0.04, 0.04, 0.44,
0.06, 0.42, 0.06, 0.13, 0.46, 0, 0.81, 0.12, 0.25, 0.5, 0.06,
0.23, 0.02, 0.19, 0.33, 0, 0.06, 0.13, 0.12, 0.27, 0.04,
0.17, 0.13, 0.08, 0.12, 0.1, 0.21, 0.31, 0.17, 0, 0, 0.04,
0.1, 0.29, 0.13, 0.38, 0.15, 0.17, 0.58, 0.02, 0.02, 0.08,
1.15, 0.08, 0.1, 0.4, 0.58, 0.35, 0.12, 0.12, 0.5, 0.17,
0.6, 0.04, 0.06, 0.13, 0.12, 0.06, 0.19, 0.25, 0.06, 0.06,
0.1, 0, 0.29, 0.58, 0.02, 0.08, 1.4, 0.15, 0.21, 0.15, 0.1,
0.02, 0, 0, 0.08, 0, 0.02, 0.23, 0.1, 0.6, 0, 0.08, 0.37,
0, 0.17, 0.21, 0.44, 0.77, 0.33, 0.42, 0, 0.12, 0.12, 0.1,
0.12, 0.06, 0.02, 0.04, 0.17, 0.13, 0.02, 0.12, 0.25, 0.06,
0.04, 0.04, 0.17, 0.17, 0.6, 0.06, 0.37, 0, 0.15, 0.13, 0.08,
0.21, 0, 0.13, 0.02, 0.15, 0, 0.4, 0.23, 0.27, 0.08, 0.1,
0.19, 0.04, 0.02, 0.1, 0.17, 0.85, 0.56, 0, 0.56, 0.56, 0.06,
0.06, 0, 0.21, 0.02, 0.33, 0, 0.04, 0.13, 0.1, 0.12, 0, 0,
0.13, 0.17, 0.08, 0.02, 0.12, 0.06, 0.38, 0.21, 0.1, 0, 0.13,
0.17, 0, 0.1, 0.12, 0.17, 0, 0.42, 0.15, 0.15, 0.42, 0.04,
0.04, 0.69, 0.15, 0, 0, 0.17, 0.4, 0.23, 0.27, 0.04, 0.17,
0.06, 0, 0, 0.06, 0.21, 0.04, 0.29, 0.04, 0.19, 0, 0.19,
0.02, 0.02, 0.29, 0.35, 0.19, 0.23, 0.42, 0.02, 0.35, 0.29,
0.02, 0.17, 0.1, 0.06, 0.17, 0.1, 0.38, 0.02, 0.15, 0.17,
0.29, 0.04, 0.02, 0.38, 0.12, 0.17, 0.02, 0, 0.06, 0.12,
0.08, 0.13, 0.12, 0.1, 0.33, 0.23, 0.29, 0.31, 0.19, 0.17,
0, 0.33, 0.17, 0.38, 0.02, 0.21, 0.17, 0.19, 0.06, 0.29,
0.12, 0.02, 0.15, 0.13, 0.17, 0.25, 0.02, 0.15, 0.65, 0.48,
0.29, 0.02, 0.19, 0.29, 0.27, 0.06, 0.02, 0.29, 0.21, 0.15,
0.12, 0.19, 0.44, 0.1, 0.04, 0.12, 0.15, 0.27, 0.1, 0.15,
0.1, 0.06, 0.15, 0.06, 0.15, 0.13, 0.54, 0.19, 0.04, 0.33,
0.06, 0.25, 0.17, 0.29, 0.12, 0.25, 0.1, 0.31, 0.13, 0.1,
0.1, 0.02, 0.25, 0.02, 0.15, 0.13, 0.29, 0.15, 0.77, 0.1,
0.08, 0.38, 0.4, 0.02, 0.37, 0, 0.12, 0.27, 0.25, 0.46, 0,
0.02, 0.12, 0, 0.27, 0.02, 0, 0.13, 0.04, 0.08, 0.13, 0.25,
0.08, 0.06, 0, 0.06, 0.12, 0.33, 0.15, 0.67, 0.04, 0.31,
0.21, 0.19, 0.25, 0.27, 0.02, 0.1, 0.1, 0.06, 0.44, 0.35,
0.23, 0.1, 0.15, 0.21, 0.08, 0.02, 0.37, 0.27, 0.17, 0.1,
0.04, 0.19, 0.42, 0.27, 0.29, 0.63, 0.54, 0.29, 0.02, 0.44,
0.35, 1.35, 0, 0.4, 0.25, 0.04, 0.02, 0.02, 0.17, 0.19, 0.17,
0.1, 0.42, 0.13, 0.13, 0.1, 0.1, 0.06, 0.04, 0.04, 0.44,
0.06, 0.04, 0.1, 0.21, 0.06, 0.02, 0.19, 0.27, 0.44, 0.02,
0.17, 0.06, 0.02, 0.17, 0.15, 0.15, 0.15, 0.12, 0.02, 0,
0, 0.21, 0.02), Online = c(1.63, 2.6, 0.48, 1.9, 5.27, 1.23,
1.87, 4.56, 3.71, 2.4, 9.62, 1.15, 1.5, 1.96, 2.5, 10.37,
2.62, 7.44, 2.71, 1.48, 16.94, 3.92, 2.9, 4.44, 2.69, 6.04,
2.69, 1.44, 0.52, 0.48, 1.44, 0.85, 4.56, 1.81, 9.25, 3.12,
5.56, 2.33, 4.67, 2.54, 3.73, 1.63, 3.4, 1.9, 1.15, 1.08,
6.27, 2.23, 3.13, 2.02, 0.63, 3.31, 2.96, 4.56, 3.19, 2.62,
6.21, 8.6, 2.23, 2.33, 0.9, 2.6, 0.94, 1.58, 0.85, 3.38,
4.04, 6.46, 3.17, 4.79, 7.92, 6.58, 1.63, 5.88, 5.06, 6.42,
2.69, 4.4, 2.08, 2.81, 3.23, 1.6, 3.08, 5.77, 1.65, 2.56,
3.81, 4.08, 3.65, 5.06, 1.15, 1.15, 1.08, 3.77, 2.75, 2.6,
2.56, 4.37, 4.92, 2.12, 1.58, 0.1, 1.87, 1.44, 4.02, 2.5,
1.29, 2.33, 6.12, 4.62, 1.98, 5.77, 3.19, 0.9, 1.5, 9.77,
7.63, 5.37, 0.79, 1.17, 4.23, 2.81, 4.31, 2.71, 3.4, 6.38,
2.75, 1.23, 4.77, 2.4, 6.04, 0.58, 0.79, 8.08, 2.13, 1.75,
0.87, 2.19, 1.38, 2.54, 2.71, 1.65, 3.5, 1.85, 18.52, 2.08,
0.33, 3.19, 6.69, 1.06, 3.08, 1.81, 1.06, 0.48, 0.85, 3.65,
1.44, 1.63, 1.71, 3.5, 2.12, 9.62, 1.96, 7.48, 1.65, 3.19,
11.04, 1.81, 3.4, 3.73, 6.1, 0.9, 10.31, 4.46, 2.27, 1.17,
0.94, 2.02, 2.75, 6.38, 3.83, 4.98, 3.77, 2.71, 5.63, 1.21,
3.31, 0, 9.35, 5.56, 1.79, 6.15, 1.9, 3.4, 6.52, 0.63, 1.37,
4.25, 1.71, 0.69, 0.75, 1.23, 2.69, 2.02, 1.79, 3.56, 0.75,
0.75, 0.52, 1.21, 1.12, 0.69, 1.79, 4.56, 1.23, 4.83, 5.04,
2.38, 1.23, 5.4, 3.13, 2.62, 1.08, 13.38, 3.52, 5.19, 3.62,
1.08, 4.5, 10.19, 2.33, 4.73, 1.87, 9.4, 11.21, 1.65, 2.29,
2.9, 35.94, 3.19, 2.4, 1.79, 7.58, 5.4, 4.73, 1.21, 1.54,
1.75, 2.98, 2.27, 2.08, 2.08, 4.35, 5.85, 3.12, 1.63, 5.06,
1.65, 4.92, 4.77, 5.06, 5, 5.27, 8.75, 3.56, 5.77, 6.21,
10.13, 6, 7.69, 1.92, 3.81, 7.92, 1.63, 4.29, 3.46, 7.65,
8.35, 1, 6.27, 6.96, 2.17, 14.81, 10.65, 0.04, 2.54, 1.38,
0.85, 5.79, 3.5, 6.6, 6.04, 2.13, 4.04, 5.63, 4.94, 1.27,
2.5, 6.42, 4.83, 4.35, 3.19, 4.1, 1.38, 1.63, 2.4, 6.96,
0.63, 2.12, 8.65, 3.67, 1.9, 2.08, 5.46, 3.71, 1.69, 2.81,
0.6, 2.06, 5.1, 2.87, 5.27, 6.54, 2.56, 0.42, 0.33, 1.12,
1.06, 1.6, 1.37, 2.23, 1.08, 1.75, 0.6, 0.9, 5.1, 2.27, 0.73,
1.33, 1.06, 1.96, 1.98, 3.98, 1.75, 1.87, 9.73, 12, 1.15,
1.23, 3.29, 1.92, 6.06, 4.44, 2.48, 1.37, 5.58, 2.12, 1.81,
1.17, 0.27, 1.6, 4.85, 1.17, 2.48, 1.63, 2.17, 1.71, 4.15,
0.48, 1.44, 1.08, 4.67, 4.56, 0.52, 6.06, 1.63, 2.35, 1.23,
1.96, 14.35, 0.58, 1.54, 1.5, 1.9, 2.54, 2.48, 2.77, 19.6,
3.35, 0.73, 1.69, 1.17, 0.85, 3.23, 0.17, 2.27, 3.71, 2.27,
2.4, 1.37, 1.5, 2.02, 0.12, 0.25, 0.38, 17.13, 2.65, 0.31,
1.85, 3.13, 1.54, 3.38, 2.98, 3.71, 2.23, 4.58, 3.29, 1.02,
7.12, 1.96, 1.85, 0.85, 2.69, 1.81, 1.21, 1.06, 3.13, 1.44,
2.71, 3.4, 3.98, 3.08, 0.9, 5, 0, 0, 0, 0, 0, 2.06, 0.75,
5.25, 2.06, 3.38, 3.04, 7.9, 4.73, 1.44, 10.67, 0.06, 7.42,
2.19, 4.5, 2.44, 3.13, 3.52, 2.75, 0.27, 7.1, 5.63, 0.52,
1.15, 2.48, 2.48, 3.71, 1.6, 1.98, 2.06, 1.5, 4.56, 1.08,
0.25, 1.15, 4.79, 2.6, 4.73, 2.6, 0.15, 0.15, 5.27, 1.21,
5, 1.29, 3.38, 0.85, 2.27, 0, 0.73, 0.38, 0.38, 0.94, 0.38,
2.08, 1.71, 4.29, 0.94, 5.62, 2.23, 0.38, 1.23, 2.06, 0.65,
4.71, 2.19, 3.08, 1.21, 1.38, 2.06, 0.54, 0.81, 1.08, 4.35,
12.6, 8.98, 1.87, 1.58, 0.27, 0.46, 19.65, 0.38, 1.37, 2.06,
1.98, 0.31, 0.46, 0.6, 0.38, 0.31, 3.77, 2.5, 15.56, 5.27,
12.58, 7.33, 11.06, 9.33, 12.79, 15.29, 7.12, 7.23, 14.17,
12.06, 12, 6.54, 6, 15.35, 10.71, 14.69, 6.94, 6.12, 5.73,
7.17, 4.15, 15.77, 7.02, 12.75, 11.56, 8.12, 6.46, 7.12,
9.02, 11.04, 10.79, 10.08, 8.08, 8.21, 9.81, 8.92, 10.73,
10.15, 9.35, 8.62, 6.27, 13.23, 14.02, 14.13, 6.25, 7.37,
6.06, 21.4, 6.63, 7.1, 8.62, 17.29, 8.4, 7.44, 5.77, 10.77,
56.38, 9.77, 11.98, 8.9, 6.06, 5.77, 13.48, 14.23, 8.17,
9.62, 11.62, 6, 12.38, 7.42, 7.23, 5.79, 8.08, 8.35, 4.73,
7.58, 6.15, 6.88, 15.65, 13.02, 7.71, 18.33, 5.69, 4.5, 7.96,
5.35, 21.17, 4.29, 9.17, 13.96, 8.69, 8.5, 12.94, 7.1, 6.15,
19.94, 7.54, 13.9, 11.56, 11.4, 11.31, 19.6, 8.83, 11.19,
9.94, 7.5, 8, 6, 4.85, 6.15, 9.94, 8.02, 11.15, 15.13, 7.06,
10.37, 10.04, 27.02, 8.17, 13.6, 11.04, 11.15, 6.1, 4.37,
7.02, 15.5, 13.15, 7.75, 9.19, 11.48, 8.81, 10.23, 12.1,
5.96, 8.13, 12.48, 8.21, 9.44, 13.15, 9.54, 19.9, 4.71, 4.63,
23.63, 24.31, 10.79, 15.35, 12.79, 10.31, 20.85, 9.02, 15.04,
9.4, 4.63, 11.27, 5.96, 40.12, 8.77, 7.79, 8.27, 7.1, 11.62,
3.81, 5.67, 5.35, 8.6, 7.33, 7.6, 8.87, 17.77, 7.92, 5.9,
6.85, 12.54, 21.08, 15.08, 9.02, 3.98, 11.67, 32.79, 5.21,
5, 6.38, 10.31, 21.35, 18.06, 13.17, 16.52, 17.04, 10.4,
4.29, 21.19, 8.71, 8.75, 14.5, 5, 8.29, 9.19, 19.87, 4.5,
3.87, 6.73, 6.75, 22.87, 8.4, 13.38, 16.79, 3.31, 8.5, 12.48,
6.33, 10.25, 9.87, 6.04, 14.33, 6.04, 5.79, 5.63, 10.73,
13.58, 8.87, 11.88, 9.12, 12.21, 10.08, 7.5, 13.9, 10.92,
8.4, 9.65, 9.25, 13.75, 9.46, 12.33, 10.02, 98.77, 11.21,
5.77, 5.19, 12.9, 10.1, 10.56, 6.12, 6.17, 7.44, 2.08, 0.65,
2.92, 0.42, 4.1, 8.62, 1.37, 2.35, 2.56, 1.15, 2.17, 0.69,
4.02, 1.81, 1.37, 2.87, 3.29, 2.96, 1.42, 2.62, 0.48, 2.35,
5.27, 2.23, 1.38, 3.31, 8.87, 3.25, 2.98, 3.94, 2.13, 1.85,
5.19, 2.9, 2.23, 2.38, 0.9, 2.92, 0.96, 0.75, 2.33, 4.88,
4.08, 3.65, 7.87, 11.35, 2.83, 3.62, 3.12, 4.79, 4.62, 5.27,
5.25, 6, 2.29, 1.44, 1.06, 2.44, 1.42, 2.6, 4.67, 4.1, 1.06,
2.83, 2.87, 1.5, 1.5, 0.87, 0.73, 3.83, 2.71, 0.65, 2.35,
1.37, 4.23, 2.17, 1.81, 2.77, 1.23, 1.96, 1.37, 4.44, 3.35,
1.96, 2.33, 1.33, 1.38, 6.67, 2.75, 1.48, 2.62, 1.65, 2.29,
5, 1.81, 2.08, 1.27, 3.4, 1.42, 2.23, 0.37, 1.69, 2.23, 2.83,
0.69, 4.71, 1.85, 1.23, 2.71, 8.12, 1.87, 2.62, 0.85, 3.12,
4.88, 1.23, 2.13, 0.52, 4.73, 4.31, 1.23, 0.38, 0.48, 0.58,
1.27, 3.31, 12.46, 2.4, 5.13, 2.81, 2.87, 2.44, 6.69, 1.85,
5.1, 2.29, 4.35, 1.6, 3.25, 3.13, 1.98, 1.79, 2.87, 2.33,
4.31, 0.73, 0.46, 2.83, 1.06, 0.73, 3.94, 0.42, 6.48, 2.4,
5.37, 2.71, 3.38, 1.81, 1.87, 5.13, 0.87, 0.9, 3.38, 0.81,
1.06, 0.96, 0.63, 2.87, 1.5, 1.29, 4.1, 1.54, 2.13, 6.42,
3.17, 3.25, 2.44, 3.19, 1.81, 2.4, 3.83, 3.71, 2.71, 3.04,
15.13, 4.73, 3.17, 2.62, 8.69, 7.1, 2.13, 2.02, 1.42, 2.19,
3.44, 3.56, 3.67, 8.17, 0.63, 3.35, 1.9, 0.87, 1.75, 4.4,
7.12, 3.46, 4.56, 2.81, 1.08, 0.81, 2.27, 2.23, 0.94, 4.92,
3.44, 2.87, 2.65, 6.31, 2.5, 1.85, 1.44, 1.71, 1.15, 1.37,
0.31, 2.9, 3.5, 3.17, 0.48, 0.85, 1.65, 3.56, 6.81, 1.17,
0, 4.02, 2.71, 1.96, 3.44, 10.23, 2.98, 2.54, 4.1, 1.65,
2.4, 4.88, 2.75, 1.9, 2.75, 1.69, 5.37, 7.33, 6.06, 4.19,
1.6, 0.75, 6.63, 2.87, 3.77, 1.85, 1.69, 1.6, 4.85, 5.35,
2.65, 2.75, 2.83, 0.42, 4.88, 3.04, 9.44, 11.79, 4.79, 1.5,
3.52, 0.87, 1.71, 1.15, 1.02, 0.87, 3.35, 7.06, 4.19, 0.94,
0.63, 2.06, 4.62, 2.6, 1.29, 3.73, 4.25, 3.87, 4.23, 1.92,
6.15, 2.12, 4.83, 2.35, 2.29, 6.67, 1.38, 1.15, 1.54, 1.92,
1.75, 1.15, 0, 0, 2.96, 1.08, 0.17, 4.98, 3.5, 4.62, 1.65,
0.1, 2.92, 3.77, 1.65, 0, 1.69, 6.04, 3.88, 3.25, 2.44, 2.75,
1.63, 2.6, 3.04, 0.63, 2.06, 0.15, 0.63, 3.35, 1.15, 0.69,
2.5, 2.6, 0.96, 1.27, 3.6, 2.5, 3.77, 0.81, 0.96, 5.96, 1.12,
0.81, 0.85, 1.38, 4.1, 1.63, 1.69, 0.12, 5.62, 2.98, 3.44,
0.87, 3.17, 1.98, 2.92, 9.54, 0.06, 3.88, 0.81, 1.27, 0.46,
1.12, 2.13, 3.83, 8.83, 1.48, 7.23, 0.48, 1.58, 0.54, 3.12,
3.44, 0.54, 0.17, 3.6, 0.33, 0.81, 0.6, 0.37, 1.17, 2.6,
2.92, 1.81, 3.62, 2.98, 2.06, 4.35, 1.69, 0.37, 1.06, 2.23,
1.42, 0.73, 2.06, 1.38, 1.12, 2.19, 1.15, 0.6, 0.31, 3.83,
1.6, 3.98, 2.35, 13.9, 0.37, 1.85, 3.6, 2.19, 4.5, 0.42,
0.27, 4.23, 5.21, 4.04, 1.33, 5.06, 0, 10.35, 3.19, 2.33,
7.17, 0.52, 0.69, 4.04, 8.21, 7.44, 5.69, 3.5, 2.62, 7.42,
1.85, 4.02, 2.27, 16.15, 7.33, 1.42, 12.31, 3.04, 1.17, 3.17,
9.33, 4.71, 4.67, 4.46, 3.87, 0.21, 2.17, 6.73, 11.88, 2.98,
1.29, 15.87, 0.42, 1.6, 2.23, 1.21, 1.33, 2.81, 3.67, 3.13,
4.71, 6.21, 7.15, 1.44, 3.46, 3.04, 1.85, 1.37, 2.69, 3.71,
5.85, 1.12, 16.58, 2.9, 9.46, 4.58, 2.27, 5.15, 3.94, 2.38,
1, 4.52, 0.65, 1.87, 2.02, 0.15, 1.9, 16.31, 2.5, 4.08, 4.08,
5.21, 5.62, 3.62, 2.56, 1.63, 9.87, 0.63, 1.85, 3.19, 9.62,
3.71, 2.06, 4.79, 9.25, 5.96, 1.63, 2.27, 0.37, 2.9, 3.88,
4.08, 5.63, 5.94, 2.27, 3.38, 4.85, 2.4, 2.35, 0.52, 1.29,
3.52, 1.6, 4.77, 22.02, 3.94, 1.33, 1.33, 1.33, 14.63, 1.98,
6.12, 7.9, 1.5, 1.15, 5.85, 0.9, 2.17, 0.81, 2.17, 4.56,
2.23, 6.27, 10.58, 4.5, 7.96, 2.33, 6.25, 2.44, 3.02, 4.31,
6.58, 2.06, 3.5, 5.4, 0.69, 8, 1.71, 1.44, 0.85, 1.69, 7.54,
2.33, 1.37, 2.17, 2.92, 1.65, 1.69, 3.83, 3.35, 0.79, 3.4,
1.81, 0.81, 2.77, 3.12, 6.75, 1.6, 1.69, 2.54, 3.65, 3.65,
12.6, 3.29, 1.44, 1.65, 5.94, 6, 6.38, 1.48, 9.25, 1.21,
8.98, 2.35, 2.19, 2.71, 14.23, 1.69, 8.12, 23.46, 2.77, 1,
2.44, 1.27, 1.9, 6.63, 0.96, 0.87, 6.33, 1.21, 0.73, 5.9,
0.69, 1.81, 3.65, 4.46, 12, 6.21, 3.35, 1.02, 0.46, 0.21,
0.04, 6.04, 2.23, 1.42, 1.63, 1.58, 6.94, 5.35, 2.33, 1.92,
1.12, 8.98, 2.56, 0.87, 2.27, 1.08, 2.19, 10.67, 6.21, 0.38,
1.44, 0.04, 1, 1.21, 7.33, 0), row.names = c(NA,
-1432L), class = "data.frame")
Dput(Hours)
Days = c(8.5, 8.5, 8.5, 8.5, 8.5, 8, 8.5,
8.5, 8.5, 8.5, 8.5, 8, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 8,
9, 9, 9, 9, 9, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 9, 9, 9, 9,
9, 8.5, 10, 13, 13, 13, 13, 13, 10, 9, 9, 9, 9, 9, 4, 9.25,
9.25, 9.25, 9.25, 9.25, 3, 8.75, 8.75, 8.75, 8.75, 8.75,
8.25, 8.5, 8.5, 8.5, 8.5, 9, 4, 4, 9, 9, 9, 9, 9, 8, 8.75,
8.75, 8.75, 8.75, 8.75, 4.25, 9, 9, 9, 9, 9, 8.5, 9, 9, 9,
13, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 9, 9, 9, 9, 9, 9.5, 9.5,
9.5, 9.5, 9.5, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 4, 9, 9, 9,
9, 9, 9, 9, 8.5, 8.5, 9, 3, 9, 9, 9, 9, 9, 10, 15, 15, 15,
15, 15, 15, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5,
8.5, 7, 10, 15, 15, 15, 15, 15, 15, 11, 11, 11, 11, 11, 9.5,
9.5, 9.5, 9.5, 9.5, 4, 9, 9, 9, 9, 9, 8.5, 9, 9, 9, 9, 9,
9, 9.5, 9.5, 9.5, 9.5, 9.5, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5,
8, 9, 9, 9, 9, 9, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5,
6, 12, 12, 12, 12, 12, 12, 6, 12, 12, 12, 12, 12, 12, 6,
12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 9, 9, 9, 9, 9, 10.5,
10.5, 10.5, 10.5, 10.5, 7.5, 6, 11.5, 11.5, 11.5, 11.5, 11.5,
11.5, 12, 12, 12, 12, 12, 5, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 3, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 5,
10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 8, 8.5, 8.5, 8.5, 8.5,
8.5, 8, 9.5, 9.5, 9.5, 9.5, 9.5, 3.5, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 3.5, 9.5, 9.5, 9.5, 9, 9.5, 8, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 8.5, 8.5, 8.5, 8.5, 8.5, 9, 9,
9, 9, 9, 10, 15, 15, 15, 15, 15, 15, 10, 10, 10, 10, 10,
10, 9, 9, 9, 9, 9, 9.5, 9.5, 9.5, 9.5, 9.5, 6, 14, 14, 14,
14, 14, 14, 6, 12, 12, 12, 12, 12, 12, 6, 12, 12, 12, 12,
12, 12, 6, 12, 12, 12, 12, 12, 12, 9, 9, 9, 9, 9, 4, 9, 9,
9, 9, 9, 8, 9.5, 9, 9, 9, 9, 3, 9.5, 9.5, 9.5, 9.5, 9.5,
3.5, 10, 10, 10, 10.5, 10, 4, 11, 11, 12, 11, 12, 10, 10,
10, 10, 10, 6, 10.5, 10.5, 10.5, 10.5, 10.5, 9, 9, 9, 9,
9, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 4, 9.5, 9.5,
9.5, 9.5, 9.5, 9.75, 9.75, 9.75, 9.75, 9.75, 9, 9, 9, 9,
9, 9.25, 9.25, 9.25, 9.25, 9.25, 4, 10.25, 10.25, 10.25,
10.25, 10.25, 6, 9.5, 9.5, 9.5, 9.5, 9.5, 8.5, 8.5, 8.5,
8.5, 8.5, 8.5, 9, 9, 9, 9, 9, 4, 8.5, 8.5, 8.5, 8.5, 8.5,
8.5, 8, 16, 16, 16, 16, 16, 12, 9, 9, 9, 9, 9, 9.5, 9.5,
9.5, 9.5, 9.5, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 8, 10.5,
10.5, 10.5, 10.5, 10.5, 10, 11.5, 11.5, 11.5, 10.5, 10.5,
4, 9, 9, 9, 9, 9, 9, 9.5, 9.5, 9.5, 9.5, 9.5, 3, 9.5, 9.5,
9.5, 9.5, 9.5, 3, 9.5, 9.5, 9.5, 9.5, 9.5, 9, 9, 9, 9, 9,
4, 10, 10, 10, 7.5, 10, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5,
9.5, 7.5, 9.5, 2.5, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 9.5,
9.5, 9.5, 9.5, 9.5, 3, 10.5, 10.5, 10.5, 10.5, 10.5, 9, 9,
9, 9, 9, 6, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 9.5, 9.5,
9.5, 4.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 9.5, 9.5, 9.5,
9.5, 9.5, 3, 9, 9, 9, 9, 9, 4, 10, 10, 10, 10, 10, 4, 9.75,
9.75, 9.75, 9.75, 9.75, 4, 9.75, 9.75, 9.75, 9.75, 9.75,
9.25, 9.25, 9.25, 4, 9.25, 9.5, 9.5, 9.5, 3.5, 9.5, 9.5,
9.5, 9.5, 9.5, 9.5, 9.75, 9.75, 9.75, 4.5, 9.75, 9, 9, 9,
9, 9, 4, 9.25, 9.25, 9.25, 9.25, 9.25, 2.5, 12, 10.5, 10.5,
10.5, 10.5, 9.75, 9.75, 9.75, 9.75, 9.75, 10, 10, 10, 10,
10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 6,
14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 6, 12, 12, 12, 12, 12,
12, 6, 12, 12, 12, 12, 12, 12, 6, 14.5, 14.5, 14.5, 14.5,
14.5, 14.5, 6, 12, 12, 12, 12, 12, 12, 9.25, 9.25, 9.25,
9.25, 9.25, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 9, 9, 9, 9,
9, 9.5, 9.5, 9.5, 9.5, 9.5, 10, 10, 10, 10, 10, 6, 10.75,
10.75, 10.75, 10.75, 10.75, 10, 10.75, 10.75, 10.75, 10.75,
10.75, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 10, 10, 10, 10, 10,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 5,
9, 9, 9, 9, 9, 5, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9.5, 9.5, 9.5, 9.5, 9.5, 9, 9, 4, 9, 9, 9, 9, 9,
9, 9, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 6, 14.5, 14.5, 14.5, 14.5,
14.5, 14.5, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 6, 14.5,
14.5, 14.5, 14.5, 14.5, 14.5, 6, 12, 12, 12, 12, 12, 12,
6, 12.5, 12.5, 12.5, 12.5, 12.5, 12, 6, 14, 14, 14, 14, 14,
14, 6, 12, 12, 12, 12, 12, 12, 6, 14.5, 14.5, 14.5, 14.5,
14.5, 14.5, 6, 4, 4, 4, 4, 4, 3, 9.75, 9.75, 9.75, 9.75,
9.75, 3.5, 9, 9, 9, 9, 9, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5,
9.5, 9.5, 9.5, 9.75, 9.75, 9.75, 9.75, 9.75, 9, 9, 9, 9,
9, 9.5, 9.5, 9.5, 9.5, 9.5, 10, 10, 10, 10, 10, 4, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9.5, 9.5, 9.5, 9.5, 9.5, 11, 11,
11, 11, 11, 9.75, 9.75, 9.75, 9.75, 9.75, 10, 10, 10, 10,
10, 4, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10,
10, 8, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 13.75, 14.5, 14.5,
14.5, 14.5, 14.5, 13.75, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 8.5,
9.5, 9.5, 9.5, 9.5, 9.5, 8, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 9.5,
9.5, 9.5, 9.5, 9.5, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 9,
9, 9, 9, 9, 8.5, 5, 14, 14, 14, 14, 14, 12, 10.5, 10.5, 10.5,
10.5, 10.5, 4, 10.5, 10.5, 10.5, 10.5, 10.5, 9, 9, 9, 9,
9, 8.5, 9, 9, 9, 9, 9, 8.5, 10, 10, 10, 10, 10, 3, 9, 9,
9, 9, 9, 8, 9, 9, 11, 11, 11, 8, 9, 9, 9, 9, 9, 8.5, 9, 9,
9, 9, 9, 4, 9, 9, 9, 9, 9, 8.5, 9, 9, 9, 9, 9, 4, 9, 9, 9,
9, 9, 9, 5, 9, 9, 12, 12, 12, 8.5, 9, 9, 9, 9, 9, 4, 8.5,
8.5, 8.5, 8.5, 8.5, 4, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5,
8.5, 8.5, 8.5, 8.5, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 3, 11,
11, 11, 11, 11, 9, 9.5, 9.5, 9.5, 9.5, 9.5, 5, 9, 9, 9, 9,
9, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 4, 8.5, 8.5, 8.5, 8.5, 8.5,
8, 8.5, 8.5, 8.5, 8.5, 8.5, 7.5, 9.5, 9.5, 9.5, 9.5, 9.5,
4, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 8.5, 8.5, 8.5, 8.5, 8.5, 8.5,
4, 9.5, 9.5, 9.5, 9.5, 9.5, 8.5, 9, 9, 9, 9, 9, 8.5, 6, 12.5,
12.5, 12.5, 12.5, 12.5, 11.5, 6, 11.5, 11.5, 11.5, 11.5,
11.5, 12, 6, 12, 12, 12, 12, 12, 12, 6, 12, 12, 12, 13, 13,
12, 6, 12, 12, 12, 12, 12, 12, 6, 15.5, 15.5, 15.5, 15.5,
15.5, 15.5, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 10, 10, 10, 10, 10,
4, 10, 10, 10, 10, 10, 8, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 9,
9, 9, 9, 9, 8, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 9.5, 9.5, 9.5,
9.5, 9.5, 3, 9, 9, 9, 9, 9, 7, 4, 9.5, 9.5, 9.5, 9.5, 9.5,
8.5, 13, 12.5, 12.5, 12.5, 12.5, 12.5, 13, 9.5, 9.5, 9.5,
9.5, 9.5, 8, 9, 9, 9, 9, 9, 8.5, 10.5, 10.5, 10.5, 10.5,
10.5, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 10.5, 10.5, 10.5, 10.5,
10.5, 8, 9, 9, 9, 9, 9, 4, 10, 10, 10, 10, 10, 8, 10, 10,
10, 10, 10, 8, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 9.5, 9.5, 9.5,
9, 9.5, 4, 10, 10, 10, 10, 10, 8, 10, 11, 10, 10, 10, 10,
10, 10, 10, 10, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 10.5, 10.5, 10.5,
10.5, 10.5, 8, 10.25, 10.25, 10.25, 10.25, 10.25, 9.5, 9.5,
9.5, 9.5, 9.5, 10, 10, 10, 10, 10, 4, 9.5, 9.5, 9.5, 9, 9.5,
4, 10, 10, 10, 10, 10, 4, 10, 10, 10, 10, 10, 8.5, 9, 9,
9, 9, 9, 4, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 6, 16,
16, 16, 16, 16, 15, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5,
6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 6, 14.5, 14.5, 14.5,
14.5, 14.5, 14.5, 6, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5,
6, 4, 4, 4, 4, 4, 3, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 9, 9, 9,
9, 9, 8.5, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 9, 9, 9, 9, 9, 4,
9.5, 9.5, 9.5, 9.5, 9.5, 4, 9, 9, 9, 9, 9, 4, 10.5, 10.5,
10.5, 10.5, 10.5, 8.5, 9.75, 9.75, 9.75, 9.75, 9.75, 4, 10,
10, 10, 10, 10, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 10, 10,
10, 10, 10, 8.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.25, 9.25, 9.25,
9.25, 9.25, 4, 9, 9, 9, 9, 9, 9.5, 9.5, 9.5, 9.5, 9.5, 13,
14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 10, 10, 10, 10, 10, 13,
14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 10, 10, 10, 10, 10, 9,
10, 10, 10, 10, 10, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 8.5, 9.5,
9.5, 9.5, 9.5, 9.5, 3, 9.5, 9.5, 9.5, 9.5, 9.5, 8.25, 10,
10, 10, 10, 10, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 8.5, 9.5, 9.5,
9.5, 9.5, 9.5, 8.5, 9.75, 9.75, 9.75, 9.75, 9.75, 4, 9, 9,
9, 9, 9, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 6, 14.5, 14.5, 14.5,
14.5, 14.5, 14.5, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5,
6, 12, 12, 12, 12, 12, 12, 6, 14.5, 14.5, 14.5, 14.5, 14.5,
14.5, 6, 14, 14, 14, 14, 14, 14, 6, 14.5, 14.5, 14.5, 14.5,
14.5, 14.5, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 9, 9,
9, 9, 9, 7, 6, 9.5, 9.5, 9.5, 10.5, 10.5, 8, 8.5, 8.5, 8.5,
8.5, 8.5, 8.5, 10, 10, 10, 10, 10, 9.5, 9.5, 9.5, 9.5, 9.5,
3, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 9, 9, 9, 9, 9, 8, 9.5, 9.25,
9.25, 9.25, 9.5, 8.5, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9,
4, 10, 10, 10, 10, 10, 8.5, 8.5, 8.5, 8.5, 8.5, 10, 10, 10,
10, 10, 9.5, 9.5, 9.5, 9.5, 9.5, 9, 9, 9, 9, 9, 8.5, 10,
10, 10, 10, 10, 8.5, 10.25, 10.25, 10.25, 10.25, 10.25, 4,
9, 9, 9, 9, 9, 5, 9.75, 9.75, 9.75, 9.75, 9.75, 4, 9, 9,
9, 9, 9, 8.5, 9, 9, 9, 9, 9, 8, 10, 10, 10, 10, 10, 9.5,
9.5, 9.5, 9.5, 9.5, 8.5, 9.75, 9.75, 9.75, 9.75, 9.75, 4,
8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 10, 10, 10, 10, 10, 9.5, 9.5,
9.5, 9.5, 9.5, 4, 10, 10, 10, 10, 10, 4, 9.5, 9.5, 9.5, 9.5,
9.5, 8, 10, 10, 10, 10, 10, 6, 12, 12, 12, 12, 12, 12, 6,
14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 6, 12, 12, 12, 12, 12,
11, 6, 16, 16, 16, 16, 16, 15, 6, 12, 12, 12, 12, 12, 12,
6, 12, 12, 12, 12, 12, 11, 6, 16, 16, 16, 16, 16, 15, 10.25,
10.25, 10.25, 10.25, 10.25, 4, 10.5, 10.5, 9.5, 9.5, 9.5,
4, 10, 10, 10, 10, 10, 4, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9,
4, 8, 15.5, 15.5, 15.5, 15.5, 15.5, 14.5, 9.5, 9.5, 9.5,
9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 10, 10, 10, 10, 10, 9,
9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 8.5,
9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 4.5, 10,
10, 10, 10, 10, 8.5, 9, 9, 9, 9, 9, 4, 10.5, 10.5, 10.5,
10.5, 10.5, 8.5, 8.5, 8.5, 8.5, 8.5, 8, 9, 9, 9, 9, 9, 8,
10.5, 10.5, 10.5, 12, 10.5, 10, 10.5, 10, 10.5, 10, 10, 10,
10, 10.5, 10, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 10, 10, 10, 10,
10, 10.5, 10.5, 10.5, 10.5, 10.5, 8, 9, 9, 9, 9, 9, 8, 10,
10, 10, 10, 10, 3.5, 10, 10, 10, 10, 10, 8, 10, 10, 10, 10,
10, 4, 10, 10, 10, 10, 10, 5, 9, 9, 9, 9, 9, 8.5, 9.5, 9.5,
9.5, 9.5, 9.5, 8, 10, 10, 10, 10, 10, 10.75, 10.75, 10.75,
11.75, 10.75, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 6, 14.5, 14.5,
14.5, 14.5, 14.5, 14.5, 6, 14.5, 14.5, 14.5, 14.5, 14.5,
14.5, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 6, 12, 12, 12,
13, 13, 12, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 10.5,
10.5, 10.5, 10.5, 10.5, 8.5, 10, 10, 10, 10, 10, 4, 10.75,
9.75, 10, 9.75, 9.75, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 9.5, 9.5,
9.5, 9.5, 9.5, 8.5, 10.5, 10.5, 8.5, 10.5, 10.5, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 8.5, 10, 10, 10, 10, 10,
8.5, 11.5, 11.5, 11.5, 11.5, 11.5, 10, 10, 10, 10, 10, 8.5,
10, 10, 10, 10, 10, 4, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9,
8.5, 8.5, 8.5, 8.5, 8.5, 8.5, 10, 10, 10, 10, 10, 9, 9, 9,
8, 9, 9.5, 9.5, 9.5, 9.5, 9.5, 12, 13, 13, 13, 13, 13, 13,
10.5, 10.5, 10, 10.5, 10.5, 9, 9, 9, 9, 9, 4, 10, 10, 10,
10, 10, 8.5, 10, 10, 10, 10, 10, 8.5, 10, 10, 10, 10, 10,
3, 10, 10, 10, 10, 10, 4, 10.5, 10.5, 10.5, 11.5, 10.5, 10,
10, 10, 10, 10, 10, 10, 10.5, 10.5, 10, 8.5, 10.5, 10.5,
10.5, 10.5, 10.5, 4, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5,
6, 12, 12, 12, 12, 12, 12, 6, 14.5, 14.5, 14.5, 14.5, 14.5,
14.5, 6, 13, 13, 13, 13, 13, 13, 6, 14.5, 14.5, 14.5, 14.5,
14.5, 14.5, 9.75, 9.5, 9.75, 9.5, 9.75, 4, 11.25, 9.75, 9.75,
9.75, 9.75, 11.5, 10, 10, 10, 10, 10, 15, 15, 15, 15, 15,
15, 10, 10, 10, 10, 10, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 10.5,
10.5, 10.5, 10.5, 10.5, 8.5, 13.5, 14.5, 14.5, 14.5, 14.5,
14.5, 14.5, 10, 10, 10, 11, 10, 8.5, 8.5, 8.5, 8.5, 8.5,
8.5, 8.5, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 9, 9, 9, 9, 9, 4, 10,
10, 10, 10, 10, 10.5, 10.5, 10.5, 10, 10, 8.5, 9.5, 9.5,
9.5, 9.5, 9.5, 4, 10, 10, 10, 10, 10, 8.5, 9, 9, 9, 9, 9,
4, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 7, 13, 13, 13, 13, 13, 13,
10.5, 11, 10.5, 10.5, 10.5, 4, 7, 11, 11, 11, 11, 11, 9,
9.5, 9.5, 9.5, 9.5, 9.5, 8.5, 9, 9, 9, 9, 9, 8.5, 11, 11,
11, 11, 11, 9, 7, 13, 13, 13, 13, 13, 13, 9.5, 9.5, 9.5,
9.5, 9.5, 8.5, 10, 10, 10, 10, 10, 9.5, 9.5, 9.5, 9.5, 9.5,
4, 9, 9, 9, 9, 9, 8.5, 9, 9, 9, 9, 9, 8.5, 9, 9, 9, 9, 9,
8.5, 9.5, 9.5, 9.5, 9.5, 9.5, 8.5, 9.5, 9.5, 9.5, 9.5, 9.5,
8, 10, 10, 10, 10, 10, 8.5, 9, 9, 9, 9, 9, 8.5, 9.5, 9.5,
9.5, 9.5, 9.5, 4, 9, 9, 9, 9, 9, 4, 6, 13, 13, 13, 13, 13,
12, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 6, 14.5, 14.5,
14.5, 14.5, 14.5, 14.5, 10, 10, 10, 10, 10, 9, 13, 14.5,
14.5, 14.5, 14.5, 14.5, 14.5, 10.5, 10.5, 10.5, 10.5, 10.5,
9.5, 9.5, 9.5, 9.5, 9.5, 8.5, 10, 10, 10, 10, 10, 3, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 4, 9.75, 9.75, 9.75,
9.75, 9.75, 3, 10, 10, 10, 10, 10, 8.5, 10, 10, 10, 10, 10,
8, 9, 9, 9, 9, 9, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 8, 9, 9, 9,
9, 9, 4, 10, 10, 10, 10, 10, 4, 9, 9, 9, 9, 9, 8, 9.5, 9.5,
9.5, 9.5, 9.5, 4, 12, 12, 12, 12, 12, 12, 12, 9.5, 9.5, 9.5,
9.5, 9.5, 4, 10, 10, 10, 8, 10, 8, 10, 10, 10, 10, 10, 9,
9, 9, 9, 9, 8.5, 10.5, 10.5, 10.5, 10.5, 10.5, 4, 10.5, 10.5,
10.5, 10.5, 10.5, 10, 10, 10, 10, 10, 9.5, 9.5, 9.5, 9.5,
9.5, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5,
8, 9, 9, 9, 9, 9, 8, 6, 12, 12, 12, 12, 12, 12, 6, 14.5,
14.5, 14.5, 14.5, 14.5, 14.5, 6, 12.5, 12.5, 12.5, 12.5,
12.5, 12, 6, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 6, 14.5,
14.5, 14.5, 14.5, 14.5, 14.5, 9.5, 9.5, 9.5, 9.5, 9.5, 9,
9, 9, 9, 9, 10, 10, 10, 10, 10, 3.5, 8.5, 8.5, 8.5, 8.5,
4, 9, 9, 9, 8.5, 9, 4, 9.5, 9.5, 9.5, 9.5, 9.5, 4, 9.5, 9.5,
8.5)), row.names = c(NA, -8658L), class = "data.frame")
Any help/guidance will be grateful
Many thanks
Maybe this tidyverse solution is close to what you want. But I am no sure where Hours variable comes. You can reshape your data to wide and then merge. Here the code, as days are present in both dataframes you can directly merge like this:
library(tidyverse)
#Code
#First reshape df2
merged <- df1 %>% select(StoreNumber,Online,Pressure) %>%
left_join(
df2 %>% pivot_wider(names_from = Day,values_from=Time),
by = c('StoreNumber'='BranchNumber'))
#Replace zeroes
merged <- merged %>% replace(is.na(.),0)
Output:
StoreNumber Online Pressure MON TUE WED
1 1 0.2 50 7.5 6 8.5
2 2 0.8 20 0.0 0 0.0
3 3 1.2 10 2.0 1 2.5
Some data used:
#Data 1
df1 <- structure(list(StoreNumber = 1:3, Online = c(0.2, 0.8, 1.2),
Pressure = c(50L, 20L, 10L), MON = c(0L, 0L, 0L), TUE = c(0L,
0L, 0L), WED = c(0L, 0L, 0L), SUN = c(0L, 0L, 0L)), class = "data.frame", row.names = c(NA,
-3L))
#Data 2
df2 <- structure(list(BranchNumber = c(1L, 1L, 1L, 3L, 3L, 3L), Day = c("MON",
"TUE", "WED", "MON", "TUE", "WED"), Time = c(7.5, 6, 8.5, 2,
1, 2.5)), class = "data.frame", row.names = c(NA, -6L))

Seasonal adjustment package (Census Bureau) in R only adjusting half the data

I've managed to get the library(seasonal) package to run perfectly on half my data (columns 2 and 8) but it refuses to seasonally adjust the other half. I'm really confused as the code runs fine and no error shows up, so I'm wondering if this is a feature of my data (I'm new to time-series) or are there hidden errors in my code?
head(x)
Date European Maori Pacific Peoples Asian MELAA Other Ethnicity Total
1 2004-09-30 7.9 17.9 14.8 15.4 13.4 14.1 9.7
2 2004-12-31 7.9 18.6 13.3 20.9 14.3 14.9 9.9
3 2005-03-31 7.8 17.8 14.6 21.1 12.6 16.1 9.8
4 2005-06-30 7.6 18.1 11.9 20.4 12.6 13.7 9.4
5 2005-09-30 7.1 17.4 10.5 16.1 9.4 19.2 9.0
6 2005-12-31 7.6 15.9 9.8 16.6 11.1 12.0 9.3
Code as follows:
*Note the seasonal adjustment runs smoothly in sub1 and sub2. No seasonal adjustment occurs in sub3 and sub4
library(tidyverse)
library(seasonal)
x <- read.csv("HLF524501_20191112_083700_50.csv", header = TRUE, check.names = FALSE, stringsAsFactors = FALSE)
x <- x %>%
mutate(Date = ifelse(substring(Date, 5, nchar(x)) == "Q3", paste(substring(Date, 0, 4), "09-30", sep = "-"),
ifelse(substring(Date, 5, nchar(x)) == "Q4", paste(substring(Date, 0, 4), "12-31", sep = "-"),
ifelse(substring(Date, 5, nchar(x)) == "Q1", paste(substring(Date, 0, 4), "03-31", sep = "-"),
paste(substring(Date, 0, 4), "06-30", sep = "-")))))
x$Date <- as.Date(x$Date)
sub1 <- x[,c(1,8)]
season0<-ts(sub1[,-1],frequency=4,start=c(2004,3))
sea1 <- seas(season0)
plot(sea1)
sub2 <- x[,c(1,2)]
season0<-ts(sub2[,-1],frequency=4,start=c(2004,3))
sea2 <- seas(season0)
plot(sea2)
sub3 <- x[,c(1,3)]
season0<-ts(sub3[,-1],frequency=4,start=c(2004,3))
sea3 <- seas(season0)
plot(sea3)
sub4 <- x[,c(1,4)]
season0<-ts(sub4[,-1],frequency=4,start=c(2004,3))
sea4 <- seas(season0)
plot(sea4)
Data as follows:
dput(x)
structure(list(Date = c("2004-09-30", "2004-12-31", "2005-03-31",
"2005-06-30", "2005-09-30", "2005-12-31", "2006-03-31", "2006-06-30",
"2006-09-30", "2006-12-31", "2007-03-31", "2007-06-30", "2007-09-30",
"2007-12-31", "2008-03-31", "2008-06-30", "2008-09-30", "2008-12-31",
"2009-03-31", "2009-06-30", "2009-09-30", "2009-12-31", "2010-03-31",
"2010-06-30", "2010-09-30", "2010-12-31", "2011-03-31", "2011-06-30",
"2011-09-30", "2011-12-31", "2012-03-31", "2012-06-30", "2012-09-30",
"2012-12-31", "2013-03-31", "2013-06-30", "2013-09-30", "2013-12-31",
"2014-03-31", "2014-06-30", "2014-09-30", "2014-12-31", "2015-03-31",
"2015-06-30", "2015-09-30", "2015-12-31", "2016-03-31", "2016-06-30",
"2016-09-30", "2016-12-31", "2017-03-31", "2017-06-30", "2017-09-30",
"2017-12-31", "2018-03-31", "2018-06-30", "2018-09-30", "2018-12-31",
"2019-03-31", "2019-06-30", "2019-09-30"), European = c(7.9,
7.9, 7.8, 7.6, 7.1, 7.6, 7.7, 6.7, 7.2, 8.5, 8.1, 7.8, 7.2, 7.7,
9, 8.1, 8.9, 9.6, 10.8, 11.5, 12.1, 12.5, 11.4, 11.3, 10.9, 11.4,
11.8, 11.7, 10.9, 11, 11.6, 11.8, 12.6, 12.4, 11.1, 10.7, 11.2,
12.2, 11.2, 10.8, 10.3, 11.7, 11.3, 10.9, 11, 10.7, 11.4, 10.9,
10.4, 11.1, 10.6, 10.1, 10, 11.1, 11, 10.4, 9.5, 11.4, 10.2,
9.5, 8.7), Maori = c(17.9, 18.6, 17.8, 18.1, 17.4, 15.9, 17.3,
16.1, 15.6, 18.1, 19.3, 17, 16.8, 15.9, 18.9, 16.2, 17.5, 18.9,
21.7, 22.4, 24.9, 26.3, 25, 25.5, 25.6, 25.1, 25.8, 25.5, 25.1,
24.5, 25, 25, 28.1, 28.4, 24, 24.7, 24.8, 25.7, 24.5, 22.9, 23.1,
25.1, 24.4, 24, 25.1, 23.5, 25.2, 22.8, 22.9, 23.1, 22.3, 21.4,
20.6, 21.7, 20.9, 20.3, 19, 20.9, 19.3, 17.6, 17.6), `Pacific Peoples` = c(14.8,
13.3, 14.6, 11.9, 10.5, 9.8, 15, 12.3, 12.3, 12.6, 11.6, 15,
9.5, 12.8, 17.6, 13.2, 15.6, 16.1, 21.3, 23.4, 25.1, 25.8, 24.4,
25.8, 26.1, 24.8, 24.2, 25.1, 25.2, 24.2, 27.6, 27.8, 29.6, 29.2,
27.7, 27.7, 27.2, 26.2, 24.8, 21.6, 22.4, 22.9, 23.7, 20.8, 23.9,
21.7, 21.8, 18.8, 18.7, 19.8, 19.9, 18.9, 18.4, 18.5, 16.9, 17.4,
14.8, 20.4, 18, 15.5, 14.1), Asian = c(15.4, 20.9, 21.1, 20.4,
16.1, 16.6, 11.1, 12.5, 8.9, 19.6, 17.3, 14.6, 15.5, 13.3, 13.9,
14.6, 13.4, 15.2, 16, 17, 20.6, 19.4, 18.2, 18.7, 17.9, 17.8,
18.2, 15.2, 15.3, 19, 18.4, 18.3, 18.5, 17.8, 14, 14.7, 14.4,
14.5, 14.9, 14.9, 13, 13.7, 15.6, 14.9, 13.7, 14.5, 17.5, 14.6,
13.4, 12.5, 13.1, 11.3, 11.1, 13.1, 11.9, 11.1, 11.1, 12.5, 11.1,
10.5, 9.5), MELAA = c(13.4, 14.3, 12.6, 12.6, 9.4, 11.1, 18.6,
7, 13.7, 15.4, 19.7, 20.5, 12.1, 15.9, 25.8, 21.7, 25.6, 26.4,
26.5, 26.9, 19.1, 28.5, 23, 21.4, 24.2, 14.5, 19.8, 25, 27.1,
14.2, 23.7, 22.4, 23.8, 21.8, 18.3, 14.5, 21.7, 20.7, 25.5, 21.4,
20.9, 26.2, 21.9, 25.9, 19.9, 18.7, 21.7, 19, 15.8, 23.9, 17.4,
18.3, 17, 20.3, 17.5, 17.9, 10.9, 16.1, 14.9, 22.6, 13.5), `Other Ethnicity` = c(14.1,
14.9, 16.1, 13.7, 19.2, 12, 9.8, 13.4, 10.1, 16.6, 10, 16.1,
18.5, 9.2, 9.2, 13, 8.2, 9.8, 6.7, 8.6, 10.2, 9.1, 12.6, 10.6,
8.8, 10.6, 11.1, 12.5, 12, 13.7, 15, 16.8, 12.2, 12.7, 7.9, 10.8,
12.5, 13.2, 12.1, 12.4, 8.5, 9.5, 13.1, 12.6, 10.2, 7.8, 9.4,
11.8, 11.9, 14.2, 13, 13.4, 12.3, 12.6, 13.4, 11.6, 13.7, 11.4,
11.2, 13.6, 9.3), Total = c(9.7, 9.9, 9.8, 9.4, 9, 9.3, 9.4,
8.5, 8.6, 10.3, 10.3, 9.7, 8.8, 9.2, 10.8, 9.8, 10.3, 11.2, 12.6,
13.4, 14.6, 14.9, 13.9, 13.8, 13.7, 13.9, 14.3, 13.8, 13.4, 13.6,
14.3, 14.4, 15.3, 14.9, 13.2, 13, 13.5, 14.4, 13.4, 12.9, 12.3,
13.7, 13.8, 13.2, 13.2, 12.8, 13.8, 12.7, 12.2, 12.8, 12.5, 11.6,
11.7, 12.6, 12.1, 11.7, 10.9, 12.8, 11.5, 10.8, 9.9)), class = "data.frame", row.names = c(NA,
-61L))
Would really appreciate any help :)
Thanks!
The seas function doesn't include seasonality if it doesn't detect seasonality in the data. This is based on QS statistics, which is discussed in detail here: https://stats.stackexchange.com/questions/148573/the-results-and-specifics-from-the-qs-function-in-r
You can use summary(sea1) and qs(sea1) vs. summary(sea3) and qs(sea3) to see ARIMA modeling details and the tests for seasonality on your data. More broadly, would recommend using summary on all 4 of your models to see the modeling details for each part of your data.

R: Unable to get reasonable estimates from optim()

Here is my data:
test <- structure(list(date = structure(c(16436, 16437, 16438, 16439,
16440, 16441, 16442, 16443, 16444, 16445, 16446, 16447, 16448,
16449, 16450, 16451, 16452, 16453, 16454, 16455, 16456, 16457,
16458, 16459, 16460, 16461, 16462, 16463, 16464, 16465, 16466,
16467, 16468, 16469, 16470, 16471, 16472, 16473, 16474, 16475,
16476, 16477, 16478, 16479, 16480, 16481, 16482, 16483, 16484,
16485, 16486, 16487, 16488, 16489, 16490, 16491, 16492, 16493,
16494, 16495, 16496, 16497, 16498, 16499, 16500, 16501, 16502,
16503, 16504, 16505, 16506, 16507, 16508, 16509, 16510, 16511,
16512, 16513, 16514, 16515, 16516, 16517, 16518, 16519, 16520,
16521, 16522, 16523, 16524, 16525, 16526, 16527, 16528, 16529,
16530, 16531, 16532, 16533, 16534, 16535, 16536, 16537, 16538,
16539, 16540, 16541, 16542, 16543, 16544, 16545, 16546, 16547,
16548, 16549, 16550, 16551, 16552, 16553, 16554, 16555, 16556,
16557, 16558, 16559, 16560, 16561, 16562, 16563, 16564, 16565,
16566, 16567, 16568, 16569, 16570, 16571, 16572, 16573, 16574,
16575, 16576, 16577, 16578, 16579, 16580, 16581, 16582, 16583,
16584, 16585, 16586, 16587, 16588, 16589, 16590, 16591, 16592,
16593, 16594, 16595, 16596, 16597, 16598, 16599, 16600, 16601,
16602, 16603, 16604, 16605, 16606, 16607, 16608, 16609, 16610,
16611, 16612, 16613, 16614, 16615, 16616, 16617, 16618, 16619,
16620, 16621, 16622, 16623, 16624, 16625, 16626, 16627, 16628,
16629, 16630, 16631, 16632, 16633, 16634, 16635, 16636, 16637,
16638, 16639, 16640, 16641, 16642, 16643, 16644, 16645, 16646,
16647, 16648, 16649, 16650, 16651, 16652, 16653, 16654, 16655,
16656, 16657, 16658, 16659, 16660, 16661, 16662, 16663, 16664,
16665, 16666, 16667, 16668, 16669, 16670, 16671, 16672, 16673,
16674, 16675, 16676, 16677, 16678, 16679, 16680, 16681, 16682,
16683, 16684, 16685, 16686, 16687, 16688, 16689, 16690, 16691,
16692, 16693, 16694, 16695, 16696, 16697, 16698, 16699, 16700,
16701, 16702, 16703, 16704, 16705, 16706, 16707, 16708, 16709,
16710, 16711, 16712, 16713, 16714, 16715, 16716, 16717, 16718,
16719, 16720, 16721, 16722, 16723, 16724, 16725, 16726, 16727,
16728, 16729, 16730, 16731, 16732, 16733, 16734, 16735, 16736,
16737, 16738, 16739, 16740, 16741, 16742, 16743, 16744, 16745,
16746, 16747, 16748, 16749, 16750, 16751, 16752, 16753, 16754,
16755, 16756, 16757, 16758, 16759, 16760, 16761, 16762, 16763,
16764, 16765, 16766, 16767, 16768, 16769, 16770, 16771, 16772,
16773, 16774, 16775, 16776, 16777, 16778, 16779, 16780, 16781,
16782, 16783, 16784, 16785, 16786, 16787, 16788, 16789, 16790,
16791, 16792, 16793, 16794, 16795, 16796, 16797, 16798, 16799,
16800), class = "Date"), radn = c(9.66, 9.54, 8.21, 5, 5.98,
9.39, 8.54, 9.68, 6.74, 2.95, 9.24, 7.39, 10.47, 9.04, 7.1, 4.12,
6.42, 6.89, 10.96, 9.49, 11.72, 8.83, 11.48, 11.42, 11.49, 10.98,
2.87, 11.92, 8.92, 4, 12.92, 8.37, 5.73, 4.47, 8.73, 5.76, 9.34,
10.41, 6.72, 8.44, 13.34, 11.95, 12.2, 10.94, 10.5, 15.72, 14.63,
15.67, 15.91, 14.79, 14.11, 15.89, 17.07, 17.62, 17.22, 14.93,
11.17, 4.83, 8.78, 17.46, 10.35, 19.09, 19.39, 19.48, 19.12,
18.94, 19.93, 20.24, 17.47, 6.07, 19.4, 18.26, 10, 6.33, 10.67,
15.2, 21.39, 22.43, 18.02, 19.4, 18.55, 14.91, 9.15, 21.84, 22.8,
23.16, 23.43, 24.16, 22.56, 23.58, 23.45, 25.09, 25.46, 22.85,
17.05, 23.87, 12.45, 8.88, 25.7, 25.86, 17.28, 24.77, 25.08,
15.62, 27.4, 27.35, 27.71, 26.91, 27.93, 27.99, 26.42, 20.49,
27.9, 11.89, 10.38, 28.43, 28.74, 29.2, 27.62, 28.88, 28.81,
28.92, 29.07, 24.41, 29.1, 26.43, 18, 23.94, 30.68, 29.47, 18.88,
18.58, 25.79, 18.76, 12.18, 12.92, 20.18, 10.75, 14.09, 19.86,
19.47, 15.9, 12.82, 22.62, 21.23, 24.62, 29.5, 30.21, 30.12,
21.87, 25.45, 31.68, 32.18, 29.67, 17.27, 22.41, 24.28, 31.27,
30, 30.12, 21.6, 32.76, 32.27, 32.24, 32.81, 32.45, 32.66, 30.52,
30.5, 32.68, 32.85, 30.42, 32.62, 32.45, 31.29, 32.15, 25.84,
26.21, 27.22, 26.36, 30.72, 26.26, 24.34, 21.45, 18.58, 25.95,
29.09, 21.53, 21.88, 20.76, 17.56, 24.69, 22.83, 27.72, 28.07,
31.18, 30.23, 28.86, 30.61, 30.79, 30.08, 27.28, 16.81, 23.82,
30.09, 30.29, 30.45, 30.8, 31.12, 30.89, 30.19, 25.01, 24.27,
18.93, 28.27, 26.62, 27.97, 22.9, 11.1, 22.29, 24.4, 27.78, 28.17,
28.41, 26.01, 27.18, 25.08, 26.65, 27.95, 27.67, 24.39, 26.59,
26.9, 26.54, 26.02, 25.31, 26.03, 22.22, 24.29, 21.01, 19.73,
23.03, 25.38, 24.98, 24.74, 19.75, 20.24, 24.99, 21.01, 24.53,
24.3, 23.95, 23.36, 22.92, 20.66, 15.42, 6.66, 15.28, 16.1, 16.73,
22.14, 22.02, 21.59, 21.4, 21.41, 21.45, 15.48, 17.78, 19.93,
15.58, 19.22, 17.29, 8.64, 8.94, 15.46, 12.52, 17.79, 18.36,
18.28, 15.27, 13.04, 13.78, 17.88, 17.88, 17.5, 17.31, 16.84,
14.55, 15.17, 7.43, 4.34, 5.23, 12.79, 15.84, 13.32, 15.43, 11.48,
6.13, 14.64, 9.04, 5.09, 11.84, 9.86, 11.4, 4.92, 2.81, 5.76,
7.92, 9.15, 13.14, 13.14, 9.94, 9.77, 11.15, 12.45, 12.33, 11.99,
11.8, 6.92, 11.23, 6.2, 9.6, 4.89, 11.43, 11.05, 10.83, 7.44,
5.4, 6.17, 3.52, 10.71, 10.64, 10.67, 10.6, 10.17, 6.02, 6.96,
6.5, 7.43, 3.49, 2.03, 5.22, 5.02, 4.24, 4.44, 5.52, 2.72, 3.75,
2.31, 8.38, 1.88, 3.07, 2.02, 2.66, 1.67, 5.77, 7.59, 1.9, 1.5,
9.72, 2.66, 2.39, 1.67, 2.38, 9.88), maxt = c(-4.4, -1.9, 0.8,
4.8, 6.8, 11, 13, 12.6, 11.4, 7, 5.8, 10, 7.2, 6.5, 5.9, 5.5,
10.4, 12, 15.6, 11.2, 7.1, 6.3, 6.5, 9.4, 12.8, 14.6, 14.3, 7.8,
11.9, 9.6, 4.5, 10.8, 13.2, 11.4, 14, 14.8, 14.9, 16.3, 17.2,
15.4, 13.3, 12.4, 15.1, 17.6, 19.6, 19.8, 15.1, 12.8, 15.9, 18.7,
18, 13.1, 10.6, 6, 7.6, 12.7, 14, 9.2, 8.3, 7.1, 9.5, 10, 6,
10.1, 15.5, 18.4, 19.9, 19.6, 19.9, 21.5, 13.9, 17, 20.5, 20.6,
22.7, 18.4, 18.5, 16, 19.9, 22.2, 19.1, 19.3, 12.6, 11.7, 17.1,
22.2, 26.5, 19.7, 22.9, 26.3, 20.7, 12.2, 12.4, 16.3, 17.4, 12.7,
12.7, 13, 11.4, 16.4, 20.6, 16.6, 18.4, 24.4, 11.7, 11.8, 18.6,
23, 21.9, 23.3, 24.6, 26, 22.5, 21.6, 13.2, 11.9, 14.8, 21.2,
25.8, 25.5, 22.6, 26.7, 27.6, 26.9, 27.2, 24.2, 18.6, 14.1, 20.5,
21.6, 24.2, 22.6, 20.9, 19.6, 16.9, 14.8, 17.1, 20.6, 18.3, 16.9,
20.2, 21.2, 19.6, 19.2, 22.6, 24, 23.9, 25.6, 27.1, 29.3, 30.2,
31.6, 26.4, 24.7, 25.2, 21, 25.9, 26.4, 30.7, 33.4, 34.7, 29,
30.5, 32.3, 31.9, 32.6, 32.6, 32.7, 33.6, 34, 31.6, 32.4, 31.4,
31.5, 33.7, 35.9, 37.1, 38.8, 39.2, 38.9, 37.8, 38.4, 38.3, 38.6,
37.2, 35.7, 27.9, 33.4, 32.7, 27.5, 29.2, 26.3, 26.9, 28, 29.1,
31.1, 32, 33.1, 29.4, 29.2, 32.3, 34, 33, 29, 29.3, 30.8, 31.5,
30.4, 24.9, 28.5, 33.6, 36.3, 37.7, 38.2, 34.5, 33.2, 33.9, 29.2,
32.3, 25.4, 28.8, 32.4, 32.9, 34.9, 34.6, 36.2, 34.5, 32, 34.1,
33.7, 33.3, 34.8, 34.5, 32.7, 32.3, 35.7, 35.3, 35, 34.2, 33.5,
33.9, 31.4, 27.6, 30.9, 32.2, 30.5, 25.9, 23.5, 19.6, 24.1, 28.1,
30.8, 33.2, 34.8, 35.8, 35.4, 33.5, 27.7, 21.7, 19.4, 20.1, 23.7,
28.5, 31.5, 31.6, 31, 29.3, 31.2, 32.6, 30.5, 28.6, 29.8, 30.9,
26.8, 21.1, 21.8, 20.4, 22.5, 24.9, 26.7, 27.1, 28, 30.7, 29.6,
25.5, 29.3, 30.4, 30.8, 30.5, 29, 22, 18, 13.1, 16, 19, 19.1,
19.3, 20.1, 20, 20.4, 18.6, 15.2, 13.7, 17.1, 22.3, 18.1, 6.3,
6, 5.7, 7.1, 10.3, 11.1, 14.2, 8, 7.1, 8.9, 10.7, 12.3, 14.8,
10.8, 3.2, 7.6, 12.6, 14.4, 9.6, 10.6, 11.7, 12.3, 13.4, 1.3,
-0.9, -0.2, 0.6, 2.5, 4, 5.4, 7.3, 13, 8, 6.7, 11.5, 13.2, 14.2,
14.9, 12.3, 5.5, 6.1, 11.1, 0.3, 0.5, 2, 2.8, 7, 4.9, 2.4, 7.3,
6.2, 2.9, 0.5, -1.2, -2.5, -4, -2.7, -1.1, -3), mint = c(-15.9,
-16.5, -14.4, -11.2, -5.7, -2.4, -2.5, -3.2, -4.3, -4.6, -1.5,
-1, -0.9, -6.3, -7, -5.7, -1.2, -0.9, 0.3, -2.7, -5.9, -10.1,
-8.7, -7.3, -5.7, -3.5, -1.2, -0.4, -0.9, -0.7, -4.3, -4.3, -2.8,
1, 2.7, 3.1, 5.8, 6.2, 3.8, 2.2, -0.7, -1.5, -0.9, -0.3, 1, 1,
-1.6, -3.8, -3.9, -1.9, -0.6, -0.8, -3.8, -7, -8.8, -7, -2.2,
-0.3, -1.1, -2.9, -5.1, -5.2, -9.2, -9.7, -6.9, -4.2, -3.1, -3.5,
-3.8, -2.3, 3.5, 0.3, 0.7, 5.8, 7, 7.4, 2.3, -0.6, -2.2, 0.7,
0.9, 1.6, 3.8, -0.9, -2.5, 1, 2.6, 1.8, -1.6, 2.3, -4.2, -6.6,
-4.7, -4.2, -0.5, -1.4, -3, 0.3, -2.9, -2.3, 1.1, -0.4, -1.5,
0.5, -6.1, -7.3, -5, -0.5, 0.6, 0.7, 1.2, 2.9, 4.3, 4.7, 2.1,
0.3, 0.5, 1.4, 3.4, 5, 4.9, 4.2, 6.3, 6.7, 6, 6.3, 3.6, 3.5,
3.7, 1.1, 1.9, 4.9, 0.7, 1.2, 5.8, 5.6, 4, 6.2, 8.3, 7, 6, 4.7,
7, 9.2, 8.1, 6.9, 7.9, 8.6, 9.6, 9.4, 10.3, 10.4, 9.6, 8.2, 9.4,
9.8, 7.2, 9.4, 10.8, 12.4, 14.5, 11.8, 11, 10.7, 11.3, 10.8,
9.7, 10.4, 10.6, 12.1, 10.3, 10.5, 11.3, 10, 12.6, 13.6, 17.4,
19.9, 19.9, 18.9, 18.4, 18.9, 20.1, 19, 17, 16.9, 14.8, 13.1,
14, 11.5, 10.6, 11.1, 12.7, 11.4, 11.9, 12.5, 13.3, 13.6, 13.2,
11.8, 11.8, 12.6, 15, 11.4, 10, 9.6, 9.3, 9.3, 8.2, 9.6, 9.7,
12, 14.3, 16.1, 16.5, 12.8, 13.7, 11.3, 10.3, 12.2, 11.4, 11.8,
11.1, 10.9, 11.2, 13, 11.8, 9, 9.7, 8.9, 10.1, 10, 11.5, 10.6,
12.2, 10.9, 12.6, 11.9, 11.9, 13.1, 13.4, 11.4, 6.9, 6, 7.7,
9.7, 7.8, 2.2, 1.5, 0.9, 2.3, 4.8, 6.3, 8.3, 10.4, 11.2, 12.8,
11, 7.5, 6.1, 5.5, 2.4, 3.5, 5.8, 5.9, 6.2, 5.6, 6.1, 7.4, 9.9,
7.8, 6.4, 7.8, 11, 10.1, 4.8, 3.5, 6.6, 4.6, 5.5, 5.9, 9.8, 8.3,
8.6, 6.4, 4.4, 6, 7.1, 6.9, 7.5, 7.8, 6.9, 3.9, 1.8, 0.3, 0.3,
-0.5, 3.2, 2.4, -0.3, 0.2, 5.1, -1.5, -1.4, 4.7, 5.6, 1.6, -1.3,
-3.8, -4.1, -4.6, -3.5, -0.8, -1.4, -6.5, -6, -5, -4.9, -3.9,
-4.2, -6.1, -1.7, -0.2, -0.3, -3.6, -7.1, -6.4, -3.4, -5.2, -8.6,
-9.6, -13.8, -16.3, -15.6, -14.5, -11.8, -4.6, 0, -7.6, -7.7,
-1.3, 4.8, 4.6, 2.3, 0.1, -2.2, -1.4, -2.6, -4.7, -9, -6.8, -4.4,
-3.7, -3.9, -5.1, 0, -1.8, -3.2, -9, -14.2, -17.4, -13, -8.2,
-12.7, -17.5), rain = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.8,
0.96, 0, 0, 0, 1.38, 0.25, 0.32, 0, 0, 0, 0, 0, 0, 0, 0, 5.68,
0, 0, 0, 0, 0, 1.12, 0, 0, 0, 4.24, 0.13, 6.84, 1.44, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.28, 2.13, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.65,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.65, 0, 3.6, 1.9, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.59, 1.19, 11.03, 5.43, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.77, 0, 0, 0, 0, 0, 5.06, 5.6,
0.01, 2.23, 5.45, 7.43, 4.47, 0.11, 4.02, 6.36, 0.38, 0.79, 1.46,
0, 0, 0, 0, 0, 0, 0, 0, 0.82, 3.06, 0.06, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.37, 0,
2.3, 1.74, 3.2, 1.72, 3.53, 2, 1.08, 0.46, 0.38, 0.3, 0, 0, 0,
0.47, 0, 0, 0.56, 4.86, 9.66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.86,
0, 0, 0, 0, 2.44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0.55, 0.83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16.08,
0.93, 0.01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.24, 4.25, 14.52,
13.45, 0, 0, 0, 0, 0, 0, 0, 0, 1.2, 1.23, 0, 0, 4.15, 11.05,
2.29, 0, 0, 0, 0, 0.77, 3.04, 0, 0, 0, 0, 0, 0.88, 0, 0, 0, 0,
0, 0, 0, 0, 0.94, 0, 0, 0, 0, 0, 0, 0.02, 0, 0, 0, 0, 0, 0, 0,
0.66, 1.85, 0.95, 0.61, 3.89, 0, 0, 1.23, 4.81, 0, 1.96, 1.67,
6.94, 9.65, 0, 1.99, 0, 0, 2.24, 2.67, 0.16, 0.52), evap = c(8.48,
8.48, 8.48, 8.48, 8.48, 8.48, 8.48, 8.31, 8.31, 8.31, 8.31, 8.31,
8.31, 8.31, 8.09, 8.09, 8.09, 8.09, 8.09, 8.09, 8.09, 7.86, 7.86,
7.86, 7.86, 7.86, 7.86, 7.86, 7.62, 7.62, 7.62, 7.62, 7.62, 7.62,
7.62, 7.39, 7.39, 7.39, 7.39, 7.39, 7.39, 7.39, 7.16, 7.16, 7.16,
7.16, 7.16, 7.16, 7.16, 6.93, 6.93, 6.93, 6.93, 6.93, 6.93, 6.93,
6.71, 6.71, 6.71, 6.71, 6.71, 6.71, 6.71, 6.48, 6.48, 6.48, 6.48,
6.48, 6.48, 6.48, 6.23, 6.23, 6.23, 6.23, 6.23, 6.23, 6.23, 5.96,
5.96, 5.96, 5.96, 5.96, 5.96, 5.96, 5.66, 5.66, 5.66, 5.66, 5.66,
5.66, 5.66, 5.32, 5.32, 5.32, 5.32, 5.32, 5.32, 5.32, 4.95, 4.95,
4.95, 4.95, 4.95, 4.95, 4.95, 4.56, 4.56, 4.56, 4.56, 4.56, 4.56,
4.56, 4.15, 4.15, 4.15, 4.15, 4.15, 4.15, 4.15, 3.75, 3.75, 3.75,
3.75, 3.75, 3.75, 3.75, 3.38, 3.38, 3.38, 3.38, 3.38, 3.38, 3.38,
3.05, 3.05, 3.05, 3.05, 3.05, 3.05, 3.05, 2.78, 2.78, 2.78, 2.78,
2.78, 2.78, 2.78, 2.58, 2.58, 2.58, 2.58, 2.58, 2.58, 2.58, 2.45,
2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.37, 2.37, 2.37, 2.37, 2.37,
2.37, 2.37, 2.35, 2.35, 2.35, 2.35, 2.35, 2.35, 2.35, 2.38, 2.38,
2.38, 2.38, 2.38, 2.38, 2.38, 2.46, 2.46, 2.46, 2.46, 2.46, 2.46,
2.46, 2.57, 2.57, 2.57, 2.57, 2.57, 2.57, 2.57, 2.72, 2.72, 2.72,
2.72, 2.72, 2.72, 2.72, 2.9, 2.9, 2.9, 2.9, 2.9, 2.9, 2.9, 3.1,
3.1, 3.1, 3.1, 3.1, 3.1, 3.1, 3.33, 3.33, 3.33, 3.33, 3.33, 3.33,
3.33, 3.57, 3.57, 3.57, 3.57, 3.57, 3.57, 3.57, 3.83, 3.83, 3.83,
3.83, 3.83, 3.83, 3.83, 4.13, 4.13, 4.13, 4.13, 4.13, 4.13, 4.13,
4.47, 4.47, 4.47, 4.47, 4.47, 4.47, 4.47, 4.85, 4.85, 4.85, 4.85,
4.85, 4.85, 4.85, 5.26, 5.26, 5.26, 5.26, 5.26, 5.26, 5.26, 5.67,
5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 6.08, 6.08, 6.08, 6.08, 6.08,
6.08, 6.08, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.79, 6.79,
6.79, 6.79, 6.79, 6.79, 6.79, 7.09, 7.09, 7.09, 7.09, 7.09, 7.09,
7.09, 7.35, 7.35, 7.35, 7.35, 7.35, 7.35, 7.35, 7.6, 7.6, 7.6,
7.6, 7.6, 7.6, 7.6, 7.84, 7.84, 7.84, 7.84, 7.84, 7.84, 7.84,
8.07, 8.07, 8.07, 8.07, 8.07, 8.07, 8.07, 8.28, 8.28, 8.28, 8.28,
8.28, 8.28, 8.28, 8.46, 8.46, 8.46, 8.46, 8.46, 8.46, 8.46, 8.58,
8.58, 8.58, 8.58, 8.58, 8.58, 8.58, 8.63, 8.63, 8.63, 8.63, 8.63,
8.63, 8.63, 8.6, 8.6, 8.6, 8.6, 8.6, 8.6, 8.6, 8.6), index = 8767:9131), .Names = c("date",
"radn", "maxt", "mint", "rain", "evap", "index"), na.action = structure(1L, .Names = "1", class = "omit"), row.names = 8768:9132, class = "data.frame")
I am trying to optimize a function to it to simulate some data. I have done this in the past with other datasets with success, but with this data optim is converging but visually the fit is terrible. I do a much better job using guess and check. Here I am looking at minimum temperature. I have many years of data, but in the interest of space I only included 1 year.
Here is my optimization code:
TMIN <- function(a,b,x){a*sin(b*x)}
plot(h$mint~h$index,type='l')
curve(TMIN(x, a=20, b=.017),add=TRUE, col="red")
normTMIN<-function(params,k){
a=params[1]
b=params[2]
c=params[3]
Mean<-mean(a*sin(b*k))
-sum(dnorm(k,mean=Mean,sd=c,log=TRUE)) #shape= Mean(a,b)/scale
}
optTMIN <- optim(par=c(a=60,b=.017,c=1),k=test$mint,fn=normTMIN) #par doesn't equal params
optTMIN
curve(TMIN(optTMIN$par[1],optTMIN$par[2],x), add=TRUE,col="blue")
I can't figure out why optim is going so terribly wrong. Thanks in advance.
Do you want to do something like the following (find list square estimate):
head(test)
TMIN <- function(a,b,x){a*sin(b*x)}
plot(test$mint~test$index,type='l')
curve(TMIN(x, a=20, b=.017),add=TRUE, col="red")
normTMIN<-function(params,k,x){
a=params[1]
b=params[2]
sum((k - TMIN(a,b,x))^2)
}
optTMIN <- optim(par=c(a=1,b=0.001),k=test$mint,x=test$index,fn=normTMIN, control=list(trace = TRUE)) #par doesn't equal params
optTMIN
curve(TMIN(optTMIN$par[1],optTMIN$par[2],x), add=TRUE,col="blue")
#$par
# a b
#10.97271664 0.01349994

Resources