geom.point in ggplot2, conditional shape - r

I'm putting together my first plot with ggplot2. I need to set a shape for values == 0. Here's my dataset and what I got so far :
structure(list(Var1 = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L), .Label = c("MD-1", "MD-2", "MD-3", "MD-4", "ME-1",
"ME-2", "ME-3", "ME-4", "ME-5", "ME-6", "MF-1", "MF-2", "MF-4",
"MF-6", "MF-7", "MF-8"), class = "factor"), Var2 = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1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L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 4L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
14L, 15L, 4L, 3L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 1L, 0L, 1L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 3L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 13L, 2L, 5L, 7L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 1L, 1L)), .Names = c("Var1",
"Var2", "Freq"), row.names = c(NA, -192L), class = "data.frame")
Here's the base of my plot
p <- ggplot(mat.bub, aes(Var1, Var2))
p + geom_point(aes(size = Freq))
Now, how to set geom.point to a specific shape if Freq==0 ? Here's what I tried so far:
p <- ggplot(mat.bub, aes(Var1, Var2,size=Freq))
p + geom_point(aes(Var1[Freq==0], Var2[Freq==0]), colour="black", shape=3, size=5, na.rm = T)
Inspired from this answer :
Modifying the shape for a subset of points with ggplot2
But I get an "arguments imply differing number of rows: 162, 192" error. Of course Var1 and Var2 are not numerical, that's what's different from the mtcars example.
How could I achieve this conditional shaping ? What am I missing ?
Thanx for any help !

As per my note on the answer you link to, try this:
p <- ggplot(mat.bub, aes(Var1, Var2,size=Freq)) + geom_point()
p + geom_point(data = subset(mat.bub,Freq == 0), colour="black", shape=3, size=5, na.rm = T)
As an explanation, while subsetting in the variables is possible, I much prefer handing each geom the specific subset of whatever data frame I'm dealing with. I find that easier to keep straight in my head, and is apparently less confusing for ggplot as well.

Related

Fitting zero inflated poisson to plot it in R

I have the following data
data<-c(1L, 4L, 5L, 10L, 13L, 8L, 3L, 5L, 13L, 9L, 5L, 10L, 9L, 4L,
4L, 13L, 10L, 10L, 7L, 7L, 3L, 1L, 11L, 4L, 5L, 9L, 10L, 3L,
2L, 7L, 8L, 4L, 5L, 6L, 3L, 4L, 13L, 7L, 8L, 6L, 5L, 3L, 10L,
4L, 8L, 8L, 2L, 9L, 5L, 2L, 8L, 7L, 6L, 6L, 6L, 4L, 3L, 9L, 11L,
6L, 7L, 7L, 3L, 4L, 18L, 14L, 8L, 9L, 5L, 3L, 7L, 3L, 8L, 3L,
9L, 3L, 4L, 7L, 7L, 5L, 8L, 7L, 10L, 9L, 9L, 11L, 8L, 3L, 9L,
10L, 11L, 9L, 12L, 13L, 9L, 15L, 11L, 13L, 3L, 24L, 11L, 13L,
14L, 14L, 5L, 10L, 6L, 10L, 8L, 9L, 13L, 5L, 8L, 8L, 6L, 17L,
11L, 11L, 8L, 2L, 14L, 6L, 1L, 7L, 5L, 3L, 12L, 6L, 10L, 7L,
15L, 9L, 7L, 3L, 9L, 11L, 3L, 5L, 14L, 7L, 3L, 20L, 17L, 14L,
7L, 11L, 11L, 2L, 4L, 9L, 5L, 10L, 7L, 10L, 13L, 7L, 18L, 13L,
18L, 20L, 16L, 9L, 5L, 13L, 16L, 11L, 9L, 7L, 12L, 13L, 21L,
9L, 7L, 13L, 4L, 7L, 5L, 13L, 19L, 17L, 8L, 7L, 4L, 18L, 14L,
8L, 8L, 16L, 13L, 9L, 14L, 8L, 20L, 7L, 12L, 14L, 8L, 16L, 10L,
9L, 20L, 5L, 7L, 8L, 16L, 11L, 10L, 12L, 20L, 5L, 2L, 21L, 16L,
18L, 0L, 16L, 4L, 6L, 16L, 6L, 15L, 15L, 10L, 8L, 13L, 22L, 14L,
5L, 8L, 11L, 14L, 7L, 9L, 7L, 7L, 8L, 5L, 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8L, 6L, 5L, 4L, 5L, 1L, 6L, 6L, 8L, 9L, 5L, 10L,
1L, 8L, 7L, 7L, 6L, 5L, 1L, 5L, 8L, 11L, 2L, 6L, 7L, 6L, 5L,
20L, 8L, 10L, 7L, 5L, 2L, 5L, 3L, 17L, 6L, 5L, 0L, 1L, 1L, 9L,
1L)
I have run a ZINB model and I know that it is the best fit for my data. I want to demonstrate on a graph that this distribution is my best option. I am using fitdist
library(fitdistrplus)
library(gamlss)
nb<-fitdist(data, "nbinom")
pois<-fitdist(data, "pois")
zinb<-fitdist(data, 'ZANBI',start = list(mu = 4, sigma = 0.2))
par(mfrow = c(2, 2))
plot.legend <- c("Negative binomial", "Poisson", "ZINB")
My problem is that, just as I wanted to demonstrate that nbinom and pois are not the best fit, I can't do it with zero inflated poissonZIP.
I am using gamlss
zip<-fitdist(data, 'ZIP',start = list(mu = 7.09, sigma = 4.5))
Here I'm using the values suggested in here considering mean(data[data != 0]) and var(data[data != 0]). I always get:
Error in fitdist(data, "ZIP", start = list(mu = 7.09, sigma = 4.5)) :
the function mle failed to estimate the parameters,
with the error code 100
In addition: Warning messages:
1: In fitdist(data, "ZIP", start = list(mu = 7.09, sigma = 4.5)) :
The dZIP function should return a zero-length vector when input has length zero and not raise an error
2: In fitdist(data, "ZIP", start = list(mu = 7.09, sigma = 4.5)) :
The pZIP function should return a zero-length vector when input has length zero and not raise an error
How can I plot a ZIP of my values to demonstrate is not the best fit?
The following arguments on the ZIP fit worked for me:
A start sigma < 1.
The Nelder-Mead optimizer
A (lower, upper) bounds for the optimization parameters mu and sigma set respectively to (0, Inf) and (0, 1),
The result of running the following code on your data array is below, which confirms that the Zero-Inflated Negative Binomial is the best fit (based on AIC and BIC).
library(fitdistrplus)
library(gamlss)
nb<-fitdist(data, "nbinom")
pois<-fitdist(data, "pois")
zinb<-fitdist(data, 'ZANBI',start = list(mu = 4, sigma = 0.2))
zip<-fitdist(data, 'ZIP', start = list(mu = 7.09, sigma = 0.5), discrete=TRUE,
optim.method="Nelder-Mead", lower = c(0, 0), upper = c(Inf, 1))
print(nb)
print(pois)
print(zinb)
print(zip)
cdfcomp(list(nb, zinb, pois, zip))
gofstat(list(nb, zinb, pois, zip))
The only thing that worries me is that the standard error of the estimated parameters for the ZIP fit are NA...
Partial OUTPUT
Fitting of the distribution ' nbinom ' by maximum likelihood
Parameters:
estimate Std. Error
size 1.007110 0.05297338
mu 5.548579 0.16643396
Fitting of the distribution ' pois ' by maximum likelihood
Parameters:
estimate Std. Error
lambda 5.548313 0.06522914
Fitting of the distribution ' ZANBI ' by maximum likelihood
Parameters:
estimate Std. Error
mu 6.8886199 0.1549058
sigma 0.3401722 0.0266448
Fitting of the distribution ' ZIP ' by maximum likelihood
Parameters:
estimate Std. Error
mu 7.0869552 NA
sigma 0.2171502 NA
Goodness-of-fit criteria
1-mle-nbinom 2-mle-ZANBI 3-mle-pois 4-mle-ZIP
Akaike's Information Criterion 7302.831 7141.004 10169.16 7981.985
Bayesian Information Criterion 7313.177 7151.350 10174.33 7992.331

How to do a partial autocorrelation plot with many zeros in r

I have a dataset of ER admissions with many zeros. These are daily admissions from 2016-06-05 to 2019-12-31. This is my data:
df<-structure(list(date = structure(c(1465084800, 1465171200, 1465257600,
1465344000, 1465430400, 1465516800, 1465603200, 1465689600, 1465776000,
1465862400, 1465948800, 1466035200, 1466121600, 1466208000, 1466294400,
1466380800, 1466467200, 1466553600, 1466640000, 1466726400, 1466812800,
1466899200, 1466985600, 1467072000, 1467158400, 1467244800, 1467331200,
1467417600, 1467504000, 1467590400, 1467676800, 1467763200, 1467849600,
1467936000, 1468022400, 1468108800, 1468195200, 1468281600, 1468368000,
1468454400, 1468540800, 1468627200, 1468713600, 1468800000, 1468886400,
1468972800, 1469059200, 1469145600, 1469232000, 1469318400, 1469404800,
1469491200, 1469577600, 1469664000, 1469750400, 1469836800, 1469923200,
1470009600, 1470096000, 1470182400, 1470268800, 1470355200, 1470441600,
1470528000, 1470614400, 1470700800, 1470787200, 1470873600, 1470960000,
1471046400, 1471132800, 1471219200, 1471305600, 1471392000, 1471478400,
1471564800, 1471651200, 1471737600, 1471824000, 1471910400, 1471996800,
1472083200, 1472169600, 1472256000, 1472342400, 1472428800, 1472515200,
1472601600, 1472688000, 1472774400, 1472860800, 1472947200, 1473033600,
1473120000, 1473206400, 1473292800, 1473379200, 1473465600, 1473552000,
1473638400, 1473724800, 1473811200, 1473897600, 1473984000, 1474070400,
1474156800, 1474243200, 1474329600, 1474416000, 1474502400, 1474588800,
1474675200, 1474761600, 1474848000, 1474934400, 1475020800, 1475107200,
1475193600, 1475280000, 1475366400, 1475452800, 1475539200, 1475625600,
1475712000, 1475798400, 1475884800, 1475971200, 1476057600, 1476144000,
1476230400, 1476316800, 1476403200, 1476489600, 1476576000, 1476662400,
1476748800, 1476835200, 1476921600, 1477008000, 1477094400, 1477180800,
1477267200, 1477353600, 1477440000, 1477526400, 1477612800, 1477699200,
1477785600, 1477872000, 1477958400, 1478044800, 1478131200, 1478217600,
1478304000, 1478390400, 1478476800, 1478563200, 1478649600, 1478736000,
1478822400, 1478908800, 1478995200, 1479081600, 1479168000, 1479254400,
1479340800, 1479427200, 1479513600, 1479600000, 1479686400, 1479772800,
1479859200, 1479945600, 1480032000, 1480118400, 1480204800, 1480291200,
1480377600, 1480464000, 1480550400, 1480636800, 1480723200, 1480809600,
1480896000, 1480982400, 1481068800, 1481155200, 1481241600, 1481328000,
1481414400, 1481500800, 1481587200, 1481673600, 1481760000, 1481846400,
1481932800, 1482019200, 1482105600, 1482192000, 1482278400, 1482364800,
1482451200, 1482537600, 1482624000, 1482710400, 1482796800, 1482883200,
1482969600, 1483056000, 1483142400, 1483228800, 1483315200, 1483401600,
1483488000, 1483574400, 1483660800, 1483747200, 1483833600, 1483920000,
1484006400, 1484092800, 1484179200, 1484352000, 1484438400, 1484524800,
1484611200, 1484697600, 1484784000, 1484870400, 1484956800, 1485043200,
1485129600, 1485216000, 1485302400, 1485388800, 1485475200, 1485561600,
1485648000, 1485734400, 1485820800, 1485907200, 1485993600, 1486080000,
1486166400, 1486252800, 1486339200, 1486425600, 1486512000, 1486598400,
1486684800, 1486771200, 1486857600, 1486944000, 1487030400, 1487116800,
1487203200, 1487289600, 1487376000, 1487462400, 1487548800, 1487635200,
1487721600, 1487808000, 1487894400, 1487980800, 1488067200, 1488153600,
1488240000, 1488326400, 1488412800, 1488499200, 1488585600, 1488672000,
1488758400, 1488844800, 1488931200, 1489017600, 1489104000, 1489190400,
1489276800, 1489363200, 1489449600, 1489536000, 1489622400, 1489708800,
1489795200, 1489881600, 1489968000, 1490054400, 1490140800, 1490227200,
1490313600, 1490400000, 1490486400, 1490572800, 1490659200, 1490745600,
1490832000, 1490918400, 1491004800, 1491091200, 1491177600, 1491264000,
1491350400, 1491436800, 1491523200, 1491609600, 1491696000, 1491782400,
1491868800, 1491955200, 1492041600, 1492128000, 1492214400, 1492300800,
1492387200, 1492473600, 1492560000, 1492646400, 1492732800, 1492819200,
1492905600, 1492992000, 1493078400, 1493164800, 1493251200, 1493337600,
1493424000, 1493510400, 1493596800, 1493683200, 1493769600, 1493856000,
1493942400, 1494028800, 1494115200, 1494201600, 1494288000, 1494374400,
1494460800, 1494547200, 1494633600, 1494720000, 1494806400, 1494892800,
1494979200, 1495065600, 1495152000, 1495238400, 1495324800, 1495411200,
1495497600, 1495584000, 1495670400, 1495756800, 1495843200, 1495929600,
1496016000, 1496102400, 1496188800, 1496275200, 1496361600, 1496448000,
1496534400, 1496620800, 1496707200, 1496793600, 1496880000, 1496966400,
1497052800, 1497139200, 1497225600, 1497312000, 1497398400, 1497484800,
1497571200, 1497657600, 1497744000, 1497830400, 1497916800, 1498003200,
1498089600, 1498176000, 1498262400, 1498348800, 1498435200, 1498521600,
1498608000, 1498694400, 1498780800, 1498867200, 1498953600, 1499040000,
1499126400, 1499212800, 1499299200, 1499385600, 1499472000, 1499558400,
1499644800, 1499731200, 1499817600, 1499904000, 1499990400, 1500076800,
1500163200, 1500249600, 1500336000, 1500422400, 1500508800, 1500595200,
1500681600, 1500768000, 1500854400, 1500940800, 1501027200, 1501113600,
1501200000, 1501286400, 1501372800, 1501459200, 1501545600, 1501632000,
1501718400, 1501804800, 1501891200, 1501977600, 1502064000, 1502150400,
1502236800, 1502323200, 1502409600, 1502496000, 1502582400, 1502668800,
1502755200, 1502841600, 1502928000, 1503014400, 1503100800, 1503187200,
1503273600, 1503360000, 1503446400, 1503532800, 1503619200, 1503705600,
1503792000, 1503878400, 1503964800, 1504051200, 1504137600, 1504224000,
1504310400, 1504396800, 1504483200, 1504569600, 1504656000, 1504742400,
1504828800, 1504915200, 1505001600, 1505088000, 1505174400, 1505260800,
1505347200, 1505433600, 1505520000, 1505606400, 1505692800, 1505779200,
1505865600, 1505952000, 1506038400, 1506124800, 1506211200, 1506297600,
1506384000, 1506470400, 1506556800, 1506643200, 1506729600, 1506816000,
1506902400, 1506988800, 1507075200, 1507161600, 1507248000, 1507334400,
1507420800, 1507507200, 1507593600, 1507680000, 1507766400, 1507852800,
1507939200, 1508025600, 1508112000, 1508198400, 1508284800, 1508371200,
1508457600, 1508544000, 1508630400, 1508716800, 1508803200, 1508889600,
1508976000, 1509062400, 1509148800, 1509235200, 1509321600, 1509408000,
1509494400, 1509580800, 1509667200, 1509753600, 1509840000, 1509926400,
1510012800, 1510099200, 1510185600, 1510272000, 1510358400, 1510444800,
1510531200, 1510617600, 1510704000, 1510790400, 1510876800, 1510963200,
1511049600, 1511136000, 1511222400, 1511308800, 1511395200, 1511481600,
1511568000, 1511654400, 1511740800, 1511827200, 1511913600, 1.512e+09,
1512086400, 1512172800, 1512259200, 1512345600, 1512432000, 1512518400,
1512604800, 1512691200, 1512777600, 1512864000, 1512950400, 1513036800,
1513123200, 1513209600, 1513296000, 1513382400, 1513468800, 1513555200,
1513641600, 1513728000, 1513814400, 1513900800, 1513987200, 1514073600,
1514160000, 1514246400, 1514332800, 1514419200, 1514505600, 1514592000,
1514678400, 1514764800, 1514851200, 1514937600, 1515024000, 1515110400,
1515196800, 1515283200, 1515369600, 1515456000, 1515542400, 1515628800,
1515715200, 1515801600, 1515888000, 1515974400, 1516060800, 1516147200,
1516233600, 1516320000, 1516406400, 1516492800, 1516579200, 1516665600,
1516752000, 1516838400, 1516924800, 1517011200, 1517097600, 1517184000,
1517270400, 1517356800, 1517443200, 1517529600, 1517616000, 1517702400,
1517788800, 1517875200, 1517961600, 1518048000, 1518134400, 1518220800,
1518307200, 1518393600, 1518480000, 1518566400, 1518652800, 1518739200,
1518825600, 1518912000, 1518998400, 1519084800, 1519171200, 1519257600,
1519344000, 1519430400, 1519516800, 1519603200, 1519689600, 1519776000,
1519862400, 1519948800, 1520035200, 1520121600, 1520208000, 1520294400,
1520380800, 1520467200, 1520553600, 1520640000, 1520726400, 1520812800,
1520899200, 1520985600, 1521072000, 1521158400, 1521244800, 1521331200,
1521417600, 1521504000, 1521590400, 1521676800, 1521763200, 1521849600,
1521936000, 1522022400, 1522108800, 1522195200, 1522281600, 1522368000,
1522454400, 1522540800, 1522627200, 1522713600, 1522800000, 1522886400,
1522972800, 1523059200, 1523145600, 1523232000, 1523318400, 1523404800,
1523491200, 1523577600, 1523664000, 1523750400, 1523836800, 1523923200,
1524009600, 1524096000, 1524182400, 1524268800, 1524355200, 1524441600,
1524528000, 1524614400, 1524700800, 1524787200, 1524873600, 1524960000,
1525046400, 1525132800, 1525219200, 1525305600, 1525392000, 1525478400,
1525564800, 1525651200, 1525737600, 1525824000, 1525910400, 1525996800,
1526083200, 1526169600, 1526256000, 1526342400, 1526428800, 1526515200,
1526601600, 1526688000, 1526774400, 1526860800, 1526947200, 1527033600,
1527120000, 1527206400, 1527292800, 1527379200, 1527465600, 1527552000,
1527638400, 1527724800, 1527811200, 1527897600, 1527984000, 1528070400,
1528156800, 1528243200, 1528329600, 1528416000, 1528502400, 1528588800,
1528675200, 1528761600, 1528848000, 1528934400, 1529020800, 1529107200,
1529193600, 1529280000, 1529366400, 1529452800, 1529539200, 1529625600,
1529712000, 1529798400, 1529884800, 1529971200, 1530057600, 1530144000,
1530230400, 1530316800, 1530403200, 1530489600, 1530576000, 1530662400,
1530748800, 1530835200, 1530921600, 1531008000, 1531094400, 1531180800,
1531267200, 1531353600, 1531440000, 1531526400, 1531612800, 1531699200,
1531785600, 1531872000, 1531958400, 1532044800, 1532131200, 1532217600,
1532304000, 1532390400, 1532476800, 1532563200, 1532649600, 1532736000,
1532822400, 1532908800, 1532995200, 1533081600, 1533168000, 1533254400,
1533340800, 1533427200, 1533513600, 1533600000, 1533686400, 1533772800,
1533859200, 1533945600, 1534032000, 1534118400, 1534204800, 1534291200,
1534377600, 1534464000, 1534550400, 1534636800, 1534723200, 1534809600,
1534896000, 1534982400, 1535068800, 1535155200, 1535241600, 1535328000,
1535414400, 1535500800, 1535587200, 1535673600, 1535760000, 1535846400,
1535932800, 1536019200, 1536105600, 1536192000, 1536278400, 1536364800,
1536451200, 1536537600, 1536624000, 1536710400, 1536796800, 1536883200,
1536969600, 1537056000, 1537142400, 1537228800, 1537315200, 1537401600,
1537488000, 1537574400, 1537660800, 1537747200, 1537833600, 1537920000,
1538006400, 1538092800, 1538179200, 1538265600, 1538352000, 1538438400,
1538524800, 1538611200, 1538697600, 1538784000, 1538870400, 1538956800,
1539043200, 1539129600, 1539216000, 1539302400, 1539388800, 1539475200,
1539561600, 1539648000, 1539734400, 1539820800, 1539907200, 1539993600,
1540080000, 1540166400, 1540252800, 1540339200, 1540425600, 1540512000,
1540598400, 1540684800, 1540771200, 1540857600, 1540944000, 1541030400,
1541116800, 1541203200, 1541289600, 1541376000, 1541462400, 1541548800,
1541635200, 1541721600, 1541808000, 1541894400, 1541980800, 1542067200,
1542153600, 1542240000, 1542326400, 1542412800, 1542499200, 1542585600,
1542672000, 1542758400, 1542844800, 1542931200, 1543017600, 1543104000,
1543190400, 1543276800, 1543363200, 1543449600, 1543536000, 1543622400,
1543708800, 1543795200, 1543881600, 1543968000, 1544054400, 1544140800,
1544227200, 1544313600, 1544400000, 1544486400, 1544572800, 1544659200,
1544745600, 1544832000, 1544918400, 1545004800, 1545091200, 1545177600,
1545264000, 1545350400, 1545436800, 1545523200, 1545609600, 1545696000,
1545782400, 1545868800, 1545955200, 1546041600, 1546128000, 1546214400,
1546300800, 1546387200, 1546473600, 1546560000, 1546646400, 1546732800,
1546819200, 1546905600, 1546992000, 1547078400, 1547164800, 1547251200,
1547337600, 1547424000, 1547510400, 1547596800, 1547683200, 1547769600,
1547856000, 1547942400, 1548028800, 1548115200, 1548201600, 1548288000,
1548374400, 1548460800, 1548547200, 1548633600, 1548720000, 1548806400,
1548892800, 1548979200, 1549065600, 1549152000, 1549238400, 1549324800,
1549411200, 1549497600, 1549584000, 1549670400, 1549756800, 1549843200,
1549929600, 1550016000, 1550102400, 1550188800, 1550275200, 1550361600,
1550448000, 1550534400, 1550620800, 1550707200, 1550793600, 1550880000,
1550966400, 1551052800, 1551139200, 1551225600, 1551312000, 1551398400,
1551484800, 1551571200, 1551657600, 1551744000, 1551830400, 1551916800,
1552003200, 1552089600, 1552176000, 1552262400, 1552348800, 1552435200,
1552521600, 1552608000, 1552694400, 1552780800, 1552867200, 1552953600,
1553040000, 1553126400, 1553212800, 1553299200, 1553385600, 1553472000,
1553558400, 1553644800, 1553731200, 1553817600, 1553904000, 1553990400,
1554076800, 1554163200, 1554249600, 1554336000, 1554422400, 1554508800,
1554595200, 1554681600, 1554768000, 1554854400, 1554940800, 1555027200,
1555113600, 1555200000, 1555286400, 1555372800, 1555459200, 1555545600,
1555632000, 1555718400, 1555804800, 1555891200, 1555977600, 1556064000,
1556150400, 1556236800, 1556323200, 1556409600, 1556496000, 1556582400,
1556668800, 1556755200, 1556841600, 1556928000, 1557014400, 1557100800,
1557187200, 1557273600, 1557360000, 1557446400, 1557532800, 1557619200,
1557705600, 1557792000, 1557878400, 1557964800, 1558051200, 1558137600,
1558224000, 1558310400, 1558396800, 1558483200, 1558569600, 1558656000,
1558742400, 1558828800, 1558915200, 1559001600, 1559088000, 1559174400,
1559260800, 1559347200, 1559433600, 1559520000, 1559606400, 1559692800,
1559779200, 1559865600, 1559952000, 1560038400, 1560124800, 1560211200,
1560297600, 1560384000, 1560470400, 1560556800, 1560643200, 1560729600,
1560816000, 1560902400, 1560988800, 1561075200, 1561161600, 1561248000,
1561334400, 1561420800, 1561507200, 1561593600, 1561680000, 1561766400,
1561852800, 1561939200, 1562025600, 1562112000, 1562198400, 1562284800,
1562371200, 1562457600, 1562544000, 1562630400, 1562716800, 1562803200,
1562889600, 1562976000, 1563062400, 1563148800, 1563235200, 1563321600,
1563408000, 1563494400, 1563580800, 1563667200, 1563753600, 1563840000,
1563926400, 1564012800, 1564099200, 1564185600, 1564272000, 1564358400,
1564444800, 1564531200, 1564617600, 1564704000, 1564790400, 1564876800,
1564963200, 1565049600, 1565136000, 1565222400, 1565308800, 1565395200,
1565481600, 1565568000, 1565654400, 1565740800, 1565827200, 1565913600,
1.566e+09, 1566086400, 1566172800, 1566259200, 1566345600, 1566432000,
1566518400, 1566604800, 1566691200, 1566777600, 1566864000, 1566950400,
1567036800, 1567123200, 1567209600, 1567296000, 1567382400, 1567468800,
1567555200, 1567641600, 1567728000, 1567814400, 1567900800, 1567987200,
1568073600, 1568160000, 1568246400, 1568332800, 1568419200, 1568505600,
1568592000, 1568678400, 1568764800, 1568851200, 1568937600, 1569024000,
1569110400, 1569196800, 1569283200, 1569369600, 1569456000, 1569542400,
1569628800, 1569715200, 1569801600, 1569888000, 1569974400, 1570060800,
1570147200, 1570233600, 1570320000, 1570406400, 1570492800, 1570579200,
1570665600, 1570752000, 1570838400, 1570924800, 1571011200, 1571097600,
1571184000, 1571270400, 1571356800, 1571443200, 1571529600, 1571616000,
1571702400, 1571788800, 1571875200, 1571961600, 1572048000, 1572134400,
1572220800, 1572307200, 1572393600, 1572480000, 1572566400, 1572652800,
1572739200, 1572825600, 1572912000, 1572998400, 1573084800, 1573171200,
1573257600, 1573344000, 1573430400, 1573516800, 1573603200, 1573689600,
1573776000, 1573862400, 1573948800, 1574035200, 1574121600, 1574208000,
1574294400, 1574380800, 1574467200, 1574553600, 1574640000, 1574726400,
1574812800, 1574899200, 1574985600, 1575072000, 1575158400, 1575244800,
1575331200, 1575417600, 1575504000, 1575590400, 1575676800, 1575763200,
1575849600, 1575936000, 1576022400, 1576108800, 1576195200, 1576281600,
1576368000, 1576454400, 1576540800, 1576627200, 1576713600, 1576800000,
1576886400, 1576972800, 1577059200, 1577145600, 1577232000, 1577318400,
1577404800, 1577491200, 1577577600, 1577664000, 1577750400), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), adm = c(1L, 4L, 5L, 10L, 13L,
8L, 3L, 5L, 13L, 9L, 5L, 10L, 9L, 4L, 4L, 13L, 10L, 10L, 7L,
7L, 3L, 1L, 11L, 4L, 5L, 9L, 10L, 3L, 2L, 7L, 8L, 4L, 5L, 6L,
3L, 4L, 13L, 7L, 8L, 6L, 5L, 3L, 10L, 4L, 8L, 8L, 2L, 9L, 5L,
2L, 8L, 7L, 6L, 6L, 6L, 4L, 3L, 9L, 11L, 6L, 7L, 7L, 3L, 4L,
18L, 14L, 8L, 9L, 5L, 3L, 7L, 3L, 8L, 3L, 9L, 3L, 4L, 7L, 7L,
5L, 8L, 7L, 10L, 9L, 9L, 11L, 8L, 3L, 9L, 10L, 11L, 9L, 12L,
13L, 9L, 15L, 11L, 13L, 3L, 24L, 11L, 13L, 14L, 14L, 5L, 10L,
6L, 10L, 8L, 9L, 13L, 5L, 8L, 8L, 6L, 17L, 11L, 11L, 8L, 2L,
14L, 6L, 1L, 7L, 5L, 3L, 12L, 6L, 10L, 7L, 15L, 9L, 7L, 3L, 9L,
11L, 3L, 5L, 14L, 7L, 3L, 20L, 17L, 14L, 7L, 11L, 11L, 2L, 4L,
9L, 5L, 10L, 7L, 10L, 13L, 7L, 18L, 13L, 18L, 20L, 16L, 9L, 5L,
13L, 16L, 11L, 9L, 7L, 12L, 13L, 21L, 9L, 7L, 13L, 4L, 7L, 5L,
13L, 19L, 17L, 8L, 7L, 4L, 18L, 14L, 8L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, 7L, 1L, 14L, 7L, 7L,
7L, 2L, 5L, 5L, 9L, 2L, 9L, 2L, 6L, 2L, 9L, 4L, 3L, 4L, 9L, 7L,
6L, 5L, 4L, 5L, 6L, 4L, 5L, 2L, 5L, 4L, 7L, 3L, 9L, 6L, 9L, 7L,
2L, 7L, 6L, 7L, 3L, 4L, 8L, 3L, 8L, 10L, 3L, 3L, 5L, 4L, 8L,
6L, 5L, 4L, 5L, 1L, 6L, 6L, 8L, 9L, 5L, 10L, 1L, 8L, 7L, 7L,
6L, 5L, 1L, 5L, 8L, 11L, 2L, 6L, 7L, 6L, 5L, 20L, 8L, 10L, 7L,
5L, 2L, 5L, 3L, 17L, 6L, 5L, 0L, 1L, 1L, 9L, 1L)), row.names = c(NA,
-1304L), class = "data.frame")
I want to do a time series analysis with it.
I transformed it into a ts to get a pacf
ts1 <- zoo(df$adm, df$date)
ts <- as.xts(ts1)
pacf(ts)
The problem is that the x-axis, usually showing lags like, 1,2,3...is showing lags in magnitudes of hundred of thousands.
How can I correct this?
TL;DR: The pacf() function converts its main argument to ts by calling as.ts() and then computes the PACF from that. In your application you probably just want to treat the observations as an equidistant series so it's easiest to strip the time index and just compute the PACF of the data vector. You can do that via:
pacf(coredata(ts1))
pacf(coredata(ts))
Both lead to identical results.
Details: The as.ts() methods for both zoo and xts try to preserve the time index when creating the ts object. While the zoo method does not assume any knowledge about the time class and just converts it to numeric, the xts method behaves somewhat differently because it "understands" what a POSIXct object is.
In either case the time index gets coerced to numeric which is the time in seconds since 1970-01-01 for POSIXct. Therefore the distance between the observations is 1 day = 86400 seconds and hence the frequency is 1/86400 = 1.157407e-05. Using the simple Date class instead of POSIXct would avoid this problem.
Finally, pacf(ts1) fails because as.ts(ts1) creates a ts series with one missing value because there is one gap in the data:
ts1[221:224]
## 2017-01-11 2017-01-12 2017-01-14 2017-01-15
## 15 15 10 8
Possibly it may be sensible to fill the observation for 2017-01-13 with 0?
This is closely related to this question: Set frequency in xts object. The frequency is used in pacf here.
In particular, in your case the frequency (time in days between observations) is really small:
> frequency(ts)
[1] 1.157407e-05
You have daily data, so if you set attr(ts, 'frequency') <- 1 before pacf call, it will work.
ts1 <- zoo(df$adm, df$date)
ts <- xts::as.xts(ts1)
attr(ts, 'frequency') <- 1
pacf(ts)
Using the fpp3 forecasting packages I get the daily PACF lags per below if that helps.
(I don't use zoo/xts myself so can't say why that's showing the larger magnitudes.)
library(fpp3)
df <- structure(list(date = structure(c(
1465084800, 1465171200, 1465257600,
1465344000, 1465430400, 1465516800, 1465603200, 1465689600, 1465776000,
1465862400, 1465948800, 1466035200, 1466121600, 1466208000, 1466294400,
1466380800, 1466467200, 1466553600, 1466640000, 1466726400, 1466812800,
1466899200, 1466985600, 1467072000, 1467158400, 1467244800, 1467331200,
1467417600, 1467504000, 1467590400, 1467676800, 1467763200, 1467849600,
1467936000, 1468022400, 1468108800, 1468195200, 1468281600, 1468368000,
1468454400, 1468540800, 1468627200, 1468713600, 1468800000, 1468886400,
1468972800, 1469059200, 1469145600, 1469232000, 1469318400, 1469404800,
1469491200, 1469577600, 1469664000, 1469750400, 1469836800, 1469923200,
1470009600, 1470096000, 1470182400, 1470268800, 1470355200, 1470441600,
1470528000, 1470614400, 1470700800, 1470787200, 1470873600, 1470960000,
1471046400, 1471132800, 1471219200, 1471305600, 1471392000, 1471478400,
1471564800, 1471651200, 1471737600, 1471824000, 1471910400, 1471996800,
1472083200, 1472169600, 1472256000, 1472342400, 1472428800, 1472515200,
1472601600, 1472688000, 1472774400, 1472860800, 1472947200, 1473033600,
1473120000, 1473206400, 1473292800, 1473379200, 1473465600, 1473552000,
1473638400, 1473724800, 1473811200, 1473897600, 1473984000, 1474070400,
1474156800, 1474243200, 1474329600, 1474416000, 1474502400, 1474588800,
1474675200, 1474761600, 1474848000, 1474934400, 1475020800, 1475107200,
1475193600, 1475280000, 1475366400, 1475452800, 1475539200, 1475625600,
1475712000, 1475798400, 1475884800, 1475971200, 1476057600, 1476144000,
1476230400, 1476316800, 1476403200, 1476489600, 1476576000, 1476662400,
1476748800, 1476835200, 1476921600, 1477008000, 1477094400, 1477180800,
1477267200, 1477353600, 1477440000, 1477526400, 1477612800, 1477699200,
1477785600, 1477872000, 1477958400, 1478044800, 1478131200, 1478217600,
1478304000, 1478390400, 1478476800, 1478563200, 1478649600, 1478736000,
1478822400, 1478908800, 1478995200, 1479081600, 1479168000, 1479254400,
1479340800, 1479427200, 1479513600, 1479600000, 1479686400, 1479772800,
1479859200, 1479945600, 1480032000, 1480118400, 1480204800, 1480291200,
1480377600, 1480464000, 1480550400, 1480636800, 1480723200, 1480809600,
1480896000, 1480982400, 1481068800, 1481155200, 1481241600, 1481328000,
1481414400, 1481500800, 1481587200, 1481673600, 1481760000, 1481846400,
1481932800, 1482019200, 1482105600, 1482192000, 1482278400, 1482364800,
1482451200, 1482537600, 1482624000, 1482710400, 1482796800, 1482883200,
1482969600, 1483056000, 1483142400, 1483228800, 1483315200, 1483401600,
1483488000, 1483574400, 1483660800, 1483747200, 1483833600, 1483920000,
1484006400, 1484092800, 1484179200, 1484352000, 1484438400, 1484524800,
1484611200, 1484697600, 1484784000, 1484870400, 1484956800, 1485043200,
1485129600, 1485216000, 1485302400, 1485388800, 1485475200, 1485561600,
1485648000, 1485734400, 1485820800, 1485907200, 1485993600, 1486080000,
1486166400, 1486252800, 1486339200, 1486425600, 1486512000, 1486598400,
1486684800, 1486771200, 1486857600, 1486944000, 1487030400, 1487116800,
1487203200, 1487289600, 1487376000, 1487462400, 1487548800, 1487635200,
1487721600, 1487808000, 1487894400, 1487980800, 1488067200, 1488153600,
1488240000, 1488326400, 1488412800, 1488499200, 1488585600, 1488672000,
1488758400, 1488844800, 1488931200, 1489017600, 1489104000, 1489190400,
1489276800, 1489363200, 1489449600, 1489536000, 1489622400, 1489708800,
1489795200, 1489881600, 1489968000, 1490054400, 1490140800, 1490227200,
1490313600, 1490400000, 1490486400, 1490572800, 1490659200, 1490745600,
1490832000, 1490918400, 1491004800, 1491091200, 1491177600, 1491264000,
1491350400, 1491436800, 1491523200, 1491609600, 1491696000, 1491782400,
1491868800, 1491955200, 1492041600, 1492128000, 1492214400, 1492300800,
1492387200, 1492473600, 1492560000, 1492646400, 1492732800, 1492819200,
1492905600, 1492992000, 1493078400, 1493164800, 1493251200, 1493337600,
1493424000, 1493510400, 1493596800, 1493683200, 1493769600, 1493856000,
1493942400, 1494028800, 1494115200, 1494201600, 1494288000, 1494374400,
1494460800, 1494547200, 1494633600, 1494720000, 1494806400, 1494892800,
1494979200, 1495065600, 1495152000, 1495238400, 1495324800, 1495411200,
1495497600, 1495584000, 1495670400, 1495756800, 1495843200, 1495929600,
1496016000, 1496102400, 1496188800, 1496275200, 1496361600, 1496448000,
1496534400, 1496620800, 1496707200, 1496793600, 1496880000, 1496966400,
1497052800, 1497139200, 1497225600, 1497312000, 1497398400, 1497484800,
1497571200, 1497657600, 1497744000, 1497830400, 1497916800, 1498003200,
1498089600, 1498176000, 1498262400, 1498348800, 1498435200, 1498521600,
1498608000, 1498694400, 1498780800, 1498867200, 1498953600, 1499040000,
1499126400, 1499212800, 1499299200, 1499385600, 1499472000, 1499558400,
1499644800, 1499731200, 1499817600, 1499904000, 1499990400, 1500076800,
1500163200, 1500249600, 1500336000, 1500422400, 1500508800, 1500595200,
1500681600, 1500768000, 1500854400, 1500940800, 1501027200, 1501113600,
1501200000, 1501286400, 1501372800, 1501459200, 1501545600, 1501632000,
1501718400, 1501804800, 1501891200, 1501977600, 1502064000, 1502150400,
1502236800, 1502323200, 1502409600, 1502496000, 1502582400, 1502668800,
1502755200, 1502841600, 1502928000, 1503014400, 1503100800, 1503187200,
1503273600, 1503360000, 1503446400, 1503532800, 1503619200, 1503705600,
1503792000, 1503878400, 1503964800, 1504051200, 1504137600, 1504224000,
1504310400, 1504396800, 1504483200, 1504569600, 1504656000, 1504742400,
1504828800, 1504915200, 1505001600, 1505088000, 1505174400, 1505260800,
1505347200, 1505433600, 1505520000, 1505606400, 1505692800, 1505779200,
1505865600, 1505952000, 1506038400, 1506124800, 1506211200, 1506297600,
1506384000, 1506470400, 1506556800, 1506643200, 1506729600, 1506816000,
1506902400, 1506988800, 1507075200, 1507161600, 1507248000, 1507334400,
1507420800, 1507507200, 1507593600, 1507680000, 1507766400, 1507852800,
1507939200, 1508025600, 1508112000, 1508198400, 1508284800, 1508371200,
1508457600, 1508544000, 1508630400, 1508716800, 1508803200, 1508889600,
1508976000, 1509062400, 1509148800, 1509235200, 1509321600, 1509408000,
1509494400, 1509580800, 1509667200, 1509753600, 1509840000, 1509926400,
1510012800, 1510099200, 1510185600, 1510272000, 1510358400, 1510444800,
1510531200, 1510617600, 1510704000, 1510790400, 1510876800, 1510963200,
1511049600, 1511136000, 1511222400, 1511308800, 1511395200, 1511481600,
1511568000, 1511654400, 1511740800, 1511827200, 1511913600, 1.512e+09,
1512086400, 1512172800, 1512259200, 1512345600, 1512432000, 1512518400,
1512604800, 1512691200, 1512777600, 1512864000, 1512950400, 1513036800,
1513123200, 1513209600, 1513296000, 1513382400, 1513468800, 1513555200,
1513641600, 1513728000, 1513814400, 1513900800, 1513987200, 1514073600,
1514160000, 1514246400, 1514332800, 1514419200, 1514505600, 1514592000,
1514678400, 1514764800, 1514851200, 1514937600, 1515024000, 1515110400,
1515196800, 1515283200, 1515369600, 1515456000, 1515542400, 1515628800,
1515715200, 1515801600, 1515888000, 1515974400, 1516060800, 1516147200,
1516233600, 1516320000, 1516406400, 1516492800, 1516579200, 1516665600,
1516752000, 1516838400, 1516924800, 1517011200, 1517097600, 1517184000,
1517270400, 1517356800, 1517443200, 1517529600, 1517616000, 1517702400,
1517788800, 1517875200, 1517961600, 1518048000, 1518134400, 1518220800,
1518307200, 1518393600, 1518480000, 1518566400, 1518652800, 1518739200,
1518825600, 1518912000, 1518998400, 1519084800, 1519171200, 1519257600,
1519344000, 1519430400, 1519516800, 1519603200, 1519689600, 1519776000,
1519862400, 1519948800, 1520035200, 1520121600, 1520208000, 1520294400,
1520380800, 1520467200, 1520553600, 1520640000, 1520726400, 1520812800,
1520899200, 1520985600, 1521072000, 1521158400, 1521244800, 1521331200,
1521417600, 1521504000, 1521590400, 1521676800, 1521763200, 1521849600,
1521936000, 1522022400, 1522108800, 1522195200, 1522281600, 1522368000,
1522454400, 1522540800, 1522627200, 1522713600, 1522800000, 1522886400,
1522972800, 1523059200, 1523145600, 1523232000, 1523318400, 1523404800,
1523491200, 1523577600, 1523664000, 1523750400, 1523836800, 1523923200,
1524009600, 1524096000, 1524182400, 1524268800, 1524355200, 1524441600,
1524528000, 1524614400, 1524700800, 1524787200, 1524873600, 1524960000,
1525046400, 1525132800, 1525219200, 1525305600, 1525392000, 1525478400,
1525564800, 1525651200, 1525737600, 1525824000, 1525910400, 1525996800,
1526083200, 1526169600, 1526256000, 1526342400, 1526428800, 1526515200,
1526601600, 1526688000, 1526774400, 1526860800, 1526947200, 1527033600,
1527120000, 1527206400, 1527292800, 1527379200, 1527465600, 1527552000,
1527638400, 1527724800, 1527811200, 1527897600, 1527984000, 1528070400,
1528156800, 1528243200, 1528329600, 1528416000, 1528502400, 1528588800,
1528675200, 1528761600, 1528848000, 1528934400, 1529020800, 1529107200,
1529193600, 1529280000, 1529366400, 1529452800, 1529539200, 1529625600,
1529712000, 1529798400, 1529884800, 1529971200, 1530057600, 1530144000,
1530230400, 1530316800, 1530403200, 1530489600, 1530576000, 1530662400,
1530748800, 1530835200, 1530921600, 1531008000, 1531094400, 1531180800,
1531267200, 1531353600, 1531440000, 1531526400, 1531612800, 1531699200,
1531785600, 1531872000, 1531958400, 1532044800, 1532131200, 1532217600,
1532304000, 1532390400, 1532476800, 1532563200, 1532649600, 1532736000,
1532822400, 1532908800, 1532995200, 1533081600, 1533168000, 1533254400,
1533340800, 1533427200, 1533513600, 1533600000, 1533686400, 1533772800,
1533859200, 1533945600, 1534032000, 1534118400, 1534204800, 1534291200,
1534377600, 1534464000, 1534550400, 1534636800, 1534723200, 1534809600,
1534896000, 1534982400, 1535068800, 1535155200, 1535241600, 1535328000,
1535414400, 1535500800, 1535587200, 1535673600, 1535760000, 1535846400,
1535932800, 1536019200, 1536105600, 1536192000, 1536278400, 1536364800,
1536451200, 1536537600, 1536624000, 1536710400, 1536796800, 1536883200,
1536969600, 1537056000, 1537142400, 1537228800, 1537315200, 1537401600,
1537488000, 1537574400, 1537660800, 1537747200, 1537833600, 1537920000,
1538006400, 1538092800, 1538179200, 1538265600, 1538352000, 1538438400,
1538524800, 1538611200, 1538697600, 1538784000, 1538870400, 1538956800,
1539043200, 1539129600, 1539216000, 1539302400, 1539388800, 1539475200,
1539561600, 1539648000, 1539734400, 1539820800, 1539907200, 1539993600,
1540080000, 1540166400, 1540252800, 1540339200, 1540425600, 1540512000,
1540598400, 1540684800, 1540771200, 1540857600, 1540944000, 1541030400,
1541116800, 1541203200, 1541289600, 1541376000, 1541462400, 1541548800,
1541635200, 1541721600, 1541808000, 1541894400, 1541980800, 1542067200,
1542153600, 1542240000, 1542326400, 1542412800, 1542499200, 1542585600,
1542672000, 1542758400, 1542844800, 1542931200, 1543017600, 1543104000,
1543190400, 1543276800, 1543363200, 1543449600, 1543536000, 1543622400,
1543708800, 1543795200, 1543881600, 1543968000, 1544054400, 1544140800,
1544227200, 1544313600, 1544400000, 1544486400, 1544572800, 1544659200,
1544745600, 1544832000, 1544918400, 1545004800, 1545091200, 1545177600,
1545264000, 1545350400, 1545436800, 1545523200, 1545609600, 1545696000,
1545782400, 1545868800, 1545955200, 1546041600, 1546128000, 1546214400,
1546300800, 1546387200, 1546473600, 1546560000, 1546646400, 1546732800,
1546819200, 1546905600, 1546992000, 1547078400, 1547164800, 1547251200,
1547337600, 1547424000, 1547510400, 1547596800, 1547683200, 1547769600,
1547856000, 1547942400, 1548028800, 1548115200, 1548201600, 1548288000,
1548374400, 1548460800, 1548547200, 1548633600, 1548720000, 1548806400,
1548892800, 1548979200, 1549065600, 1549152000, 1549238400, 1549324800,
1549411200, 1549497600, 1549584000, 1549670400, 1549756800, 1549843200,
1549929600, 1550016000, 1550102400, 1550188800, 1550275200, 1550361600,
1550448000, 1550534400, 1550620800, 1550707200, 1550793600, 1550880000,
1550966400, 1551052800, 1551139200, 1551225600, 1551312000, 1551398400,
1551484800, 1551571200, 1551657600, 1551744000, 1551830400, 1551916800,
1552003200, 1552089600, 1552176000, 1552262400, 1552348800, 1552435200,
1552521600, 1552608000, 1552694400, 1552780800, 1552867200, 1552953600,
1553040000, 1553126400, 1553212800, 1553299200, 1553385600, 1553472000,
1553558400, 1553644800, 1553731200, 1553817600, 1553904000, 1553990400,
1554076800, 1554163200, 1554249600, 1554336000, 1554422400, 1554508800,
1554595200, 1554681600, 1554768000, 1554854400, 1554940800, 1555027200,
1555113600, 1555200000, 1555286400, 1555372800, 1555459200, 1555545600,
1555632000, 1555718400, 1555804800, 1555891200, 1555977600, 1556064000,
1556150400, 1556236800, 1556323200, 1556409600, 1556496000, 1556582400,
1556668800, 1556755200, 1556841600, 1556928000, 1557014400, 1557100800,
1557187200, 1557273600, 1557360000, 1557446400, 1557532800, 1557619200,
1557705600, 1557792000, 1557878400, 1557964800, 1558051200, 1558137600,
1558224000, 1558310400, 1558396800, 1558483200, 1558569600, 1558656000,
1558742400, 1558828800, 1558915200, 1559001600, 1559088000, 1559174400,
1559260800, 1559347200, 1559433600, 1559520000, 1559606400, 1559692800,
1559779200, 1559865600, 1559952000, 1560038400, 1560124800, 1560211200,
1560297600, 1560384000, 1560470400, 1560556800, 1560643200, 1560729600,
1560816000, 1560902400, 1560988800, 1561075200, 1561161600, 1561248000,
1561334400, 1561420800, 1561507200, 1561593600, 1561680000, 1561766400,
1561852800, 1561939200, 1562025600, 1562112000, 1562198400, 1562284800,
1562371200, 1562457600, 1562544000, 1562630400, 1562716800, 1562803200,
1562889600, 1562976000, 1563062400, 1563148800, 1563235200, 1563321600,
1563408000, 1563494400, 1563580800, 1563667200, 1563753600, 1563840000,
1563926400, 1564012800, 1564099200, 1564185600, 1564272000, 1564358400,
1564444800, 1564531200, 1564617600, 1564704000, 1564790400, 1564876800,
1564963200, 1565049600, 1565136000, 1565222400, 1565308800, 1565395200,
1565481600, 1565568000, 1565654400, 1565740800, 1565827200, 1565913600,
1.566e+09, 1566086400, 1566172800, 1566259200, 1566345600, 1566432000,
1566518400, 1566604800, 1566691200, 1566777600, 1566864000, 1566950400,
1567036800, 1567123200, 1567209600, 1567296000, 1567382400, 1567468800,
1567555200, 1567641600, 1567728000, 1567814400, 1567900800, 1567987200,
1568073600, 1568160000, 1568246400, 1568332800, 1568419200, 1568505600,
1568592000, 1568678400, 1568764800, 1568851200, 1568937600, 1569024000,
1569110400, 1569196800, 1569283200, 1569369600, 1569456000, 1569542400,
1569628800, 1569715200, 1569801600, 1569888000, 1569974400, 1570060800,
1570147200, 1570233600, 1570320000, 1570406400, 1570492800, 1570579200,
1570665600, 1570752000, 1570838400, 1570924800, 1571011200, 1571097600,
1571184000, 1571270400, 1571356800, 1571443200, 1571529600, 1571616000,
1571702400, 1571788800, 1571875200, 1571961600, 1572048000, 1572134400,
1572220800, 1572307200, 1572393600, 1572480000, 1572566400, 1572652800,
1572739200, 1572825600, 1572912000, 1572998400, 1573084800, 1573171200,
1573257600, 1573344000, 1573430400, 1573516800, 1573603200, 1573689600,
1573776000, 1573862400, 1573948800, 1574035200, 1574121600, 1574208000,
1574294400, 1574380800, 1574467200, 1574553600, 1574640000, 1574726400,
1574812800, 1574899200, 1574985600, 1575072000, 1575158400, 1575244800,
1575331200, 1575417600, 1575504000, 1575590400, 1575676800, 1575763200,
1575849600, 1575936000, 1576022400, 1576108800, 1576195200, 1576281600,
1576368000, 1576454400, 1576540800, 1576627200, 1576713600, 1576800000,
1576886400, 1576972800, 1577059200, 1577145600, 1577232000, 1577318400,
1577404800, 1577491200, 1577577600, 1577664000, 1577750400
), class = c(
"POSIXct",
"POSIXt"
), tzone = "UTC"), adm = c(
1L, 4L, 5L, 10L, 13L,
8L, 3L, 5L, 13L, 9L, 5L, 10L, 9L, 4L, 4L, 13L, 10L, 10L, 7L,
7L, 3L, 1L, 11L, 4L, 5L, 9L, 10L, 3L, 2L, 7L, 8L, 4L, 5L, 6L,
3L, 4L, 13L, 7L, 8L, 6L, 5L, 3L, 10L, 4L, 8L, 8L, 2L, 9L, 5L,
2L, 8L, 7L, 6L, 6L, 6L, 4L, 3L, 9L, 11L, 6L, 7L, 7L, 3L, 4L,
18L, 14L, 8L, 9L, 5L, 3L, 7L, 3L, 8L, 3L, 9L, 3L, 4L, 7L, 7L,
5L, 8L, 7L, 10L, 9L, 9L, 11L, 8L, 3L, 9L, 10L, 11L, 9L, 12L,
13L, 9L, 15L, 11L, 13L, 3L, 24L, 11L, 13L, 14L, 14L, 5L, 10L,
6L, 10L, 8L, 9L, 13L, 5L, 8L, 8L, 6L, 17L, 11L, 11L, 8L, 2L,
14L, 6L, 1L, 7L, 5L, 3L, 12L, 6L, 10L, 7L, 15L, 9L, 7L, 3L, 9L,
11L, 3L, 5L, 14L, 7L, 3L, 20L, 17L, 14L, 7L, 11L, 11L, 2L, 4L,
9L, 5L, 10L, 7L, 10L, 13L, 7L, 18L, 13L, 18L, 20L, 16L, 9L, 5L,
13L, 16L, 11L, 9L, 7L, 12L, 13L, 21L, 9L, 7L, 13L, 4L, 7L, 5L,
13L, 19L, 17L, 8L, 7L, 4L, 18L, 14L, 8L, 8L, 16L, 13L, 9L, 14L,
8L, 20L, 7L, 12L, 14L, 8L, 16L, 10L, 9L, 20L, 5L, 7L, 8L, 16L,
11L, 10L, 12L, 20L, 5L, 2L, 21L, 16L, 18L, 0L, 16L, 4L, 6L, 16L,
6L, 15L, 15L, 10L, 8L, 13L, 22L, 14L, 5L, 8L, 11L, 14L, 7L, 9L,
7L, 7L, 8L, 5L, 12L, 6L, 20L, 10L, 17L, 9L, 7L, 13L, 9L, 13L,
15L, 18L, 10L, 8L, 10L, 12L, 16L, 16L, 11L, 13L, 8L, 8L, 20L,
16L, 11L, 14L, 18L, 10L, 8L, 17L, 24L, 8L, 15L, 16L, 9L, 10L,
22L, 15L, 16L, 16L, 20L, 16L, 7L,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)), row.names = c(
NA,
-1304L
), class = "data.frame")
df |>
mutate(date = as.Date(date)) |>
tsibble(index = date) |>
fill_gaps() |>
PACF(adm) |>
autoplot()
Created on 2022-06-30 by the reprex package (v2.0.1)
You could solve your problem as below.
ts1 <- zoo(df$adm, df$date)
ts <- as.xts(ts1)
pl = pacf(ts, xaxt="n")
axis(1, pl$lag, seq_along(pl$lag))

set diagonal elements to a certain color on geom_tile ggplot2

I want to produce a confusion matrix plot where the diagonal entries are green, the zero entries white, and the off-diagonal non-zero entries should be red.
This is the data:
gg <- structure(list(Prediction = structure(c(1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L), .Label = c("0", "1", "2", "3", "4", "5", "6",
"7", "8", "9"), class = "factor"), Reference = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L), .Label = c("0", "1", "2", "3", "4",
"5", "6", "7", "8", "9"), class = "factor"), Freq = c(93L, 7L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 100L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 2L, 89L, 6L, 0L, 0L, 0L, 0L, 3L, 0L, 0L, 1L, 98L,
0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 26L, 0L, 0L, 71L, 0L, 0L,
3L, 0L, 0L, 2L, 69L, 0L, 0L, 1L, 25L, 0L, 3L, 0L, 0L, 6L, 64L,
0L, 0L, 0L, 0L, 30L, 0L, 0L, 0L, 1L, 13L, 0L, 0L, 0L, 0L, 0L,
86L, 0L, 0L, 3L, 96L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 4L, 37L,
0L, 0L, 5L, 0L, 0L, 54L, 0L, 0L)), class = "data.frame", row.names = c(NA,
-100L))
In this example, the off-diagonal zeros are white. But how can I intentionally set the diagonal to green and non-zero off-diagonal red?
gg %>% dplyr::mutate(Freq2 = ifelse(Freq == 0,NA,Freq)) %>%
ggplot(aes(Prediction, Reference, fill = Freq2)) +
geom_tile() +
geom_text(aes(label=Freq)) +
scale_fill_gradientn(colours = c("#f8766d", "#00ba38"),na.value="white") +
labs(x = "Prediction",y = "Reference", fill = "Freq")
One option using scale_fill_identity -
library(dplyr)
library(ggplot2)
gg %>%
mutate(color = case_when(Prediction == Reference ~ 'green',
Freq == 0 ~ 'white',
TRUE ~ ' red')) %>%
ggplot(aes(Prediction, Reference, fill = color)) +
geom_tile() +
geom_text(aes(label=Freq)) +
scale_fill_identity() +
labs(x = "Prediction",y = "Reference")
Figured it out. Had to use scale_fill_manual
gg2 <- gg %>% dplyr::mutate(Freq2 = ifelse(Freq == 0,NA,Freq))
gg2[gg2$Prediction == gg2$Reference,]$Freq2 = "diag"
gg2[gg2$Prediction != gg2$Reference & !is.na(gg2$Freq2),]$Freq2 = "notDiag"
gg2 %>%
ggplot(aes(Prediction, Reference, fill = Freq2)) +
geom_tile() +
geom_text(aes(label=Freq)) +
scale_fill_manual(values=c("#00ba38", "#f8766d"),na.value="white")+
labs(x = "Prediction",y = "Reference", fill = "Freq")

R - Easy significant test on 2 dataframes

I am stucking a simple statistical comparism of 2 dataframes. Both dataframes consist of different kind of observations (columns) and the observation days (rows). I counted the number of occurrences for each day and each case. I dont have the same number of observation days, the observations took place under different conditions and I want to find out if there is a significant difference between those two dataframes. So basically I want to compare Case1 of df1 with Case1 of df2. For that I calculated the number of occurrences per day of each dataframe and compared them (in%).
In reality I have thousands of these dataframes and all have different number of rows.
My problem is now, how can I get an idea of which of the results are significant? How can I see if only 9 day of observation is too less to be significant?
I tried to perform a Chi-Square test, is that the right thing to do?
Here is Dataframe 1:
structure(list(Case1 = c(17L, 9L, 4L, 3L, 5L, 4L, 5L, 4L, 6L, 13L,
7L, 17L, 9L, 11L, 10L, 8L, 7L, 22L, 7L, 14L, 15L, 13L, 17L, 7L,
13L, 12L, 10L, 16L, 7L, 6L, 13L, 10L, 12L, 12L, 11L, 13L, 12L,
9L, 11L, 12L, 14L, 10L, 11L, 14L, 15L, 9L, 12L, 13L, 19L, 14L,
10L, 10L, 4L, 10L, 9L, 11L, 10L, 4L, 6L, 3L, 11L, 10L, 7L, 8L,
12L, 8L, 7L, 3L, 5L, 5L, 6L, 5L, 8L, 10L, 9L, 3L, 5L, 9L, 9L,
4L, 9L, 7L, 8L, 6L, 4L, 7L, 6L, 9L, 4L, 17L, 16L, 9L, 16L, 12L,
9L, 10L, 14L, 6L, 17L, 14L, 14L, 11L, 10L, 11L, 15L, 12L, 11L,
15L, 10L, 12L, 12L, 5L, 7L, 7L, 15L, 9L, 8L, 14L, 15L, 20L, 8L,
12L, 12L, 19L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, 2L, 1L,
0L, 1L, 1L, 2L, 2L, 2L, 3L, 1L, 2L, 1L, 0L, 0L, 2L, 2L, 4L, 0L,
0L, 1L, 3L, 5L, 1L, 0L, 2L, 0L, 1L, 1L, 0L, 4L, 0L, 0L, 1L, 3L,
4L, 0L, 0L, 0L, 2L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 2L, 1L, 0L, 1L,
1L, 1L, 0L, 0L, 2L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 2L, 4L, 1L, 1L,
1L, 2L, 1L, 1L, 0L, 5L, 2L, 0L, 1L, 0L, 2L, 1L, 1L, 1L, 4L, 1L,
1L, 3L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 2L, 4L, 1L, 2L, 2L, 6L, 0L,
2L, 0L, 0L, 1L, 1L, 0L, 3L, 2L, 3L, 0L, 1L, 0L, 0L, 0L, 3L, 1L,
0L, 0L, 2L, 0L, 0L, 5L, 0L, 1L, 0L, 0L, 4L, 2L, 0L, 0L, 1L, 0L,
0L, 1L, 2L, 0L, 0L, 2L, 1L, 1L, 1L, 4L, 1L, 0L, 1L, 1L, 2L, 0L,
1L, 1L)), .Names = c("Case1", "Case2", "Case3"), class = "data.frame", row.names = c(NA,
-175L))
Here is Dataframe 2:
structure(list(Case1 = c(9L, 11L, 10L, 4L, 9L, 6L, 4L, 7L, 13L),
Case2 = c(7L, 10L, 8L, 4L, 8L, 4L, 3L, 6L, 8L), Case3 = c(2L, 1L,
2L, 0L, 1L, 2L, 1L, 1L, 5L)), .Names = c("Case1", "Case2", "Case3"), class = "data.frame", row.names = c(NA,
-9L))

Decision Tree Keeps Using Y-variable in Tree Decision Making

I'm using C5.0 to make a decision tree, and it's using my class label in the tree. A snippet of my data is below.
trainX
V1 V2 V3 V4 V5 V6
1 39 State-gov 77516 Bachelors 13 Never-married
2 50 Self-emp-not-inc 83311 Bachelors 13 Married-civ-spouse
3 38 Private 215646 HS-grad 9 Divorced
4 53 Private 234721 11th 7 Married-civ-spouse
5 28 Private 338409 Bachelors 13 Married-civ-spouse
V7 V8 V9 V10 V11 V12 V13 V14
1 Adm-clerical Not-in-family White Male 2174 0 40 United-States
2 Exec-managerial Husband White Male 0 0 13 United-States
3 Handlers-cleaners Not-in-family White Male 0 0 40 United-States
4 Handlers-cleaners Husband Black Male 0 0 40 United-States
5 Prof-specialty Wife Black Female 0 0 40 Cuba
trainY
[1] <=50K <=50K <=50K <=50K <=50K
There are cases in my data of >50K as well, this snippet of 5 just did not contain any.
When I make my tree, this is the code I use
library(C50)
trainX = X[1:100,]
trainY = Y[1:100]
testX = X[101:150,]
testY = Y[101:150]
model = C5.0(trainX, trainY)
summary(model)
And the output I get is...
Decision tree:
<=50K (100/25)
Evaluation on training data (100 cases):
Decision Tree
----------------
Size Errors
1 25(25.0%) <<
(a) (b) <-classified as
---- ----
75 (a): class <=50K
25 (b): class >50K
What am I doing wrong that it's using the classification as part of the tree?
EDIT - DPUTS below of Head. Still gives me the same issue, where its making a Decision Tree using the split as <=50K or >50K, which is my "Y" output and thus shouldn't be part of the decision making process.
trainX
structure(list(V1 = c(39L, 50L, 38L, 53L, 28L, 37L), V2 = structure(c(8L,
7L, 5L, 5L, 5L, 5L), .Label = c(" ?", " Federal-gov", " Local-gov",
" Never-worked", " Private", " Self-emp-inc", " Self-emp-not-inc",
" State-gov", " Without-pay"), class = "factor"), V3 = c(77516L,
83311L, 215646L, 234721L, 338409L, 284582L), V4 = structure(c(10L,
10L, 12L, 2L, 10L, 13L), .Label = c(" 10th", " 11th", " 12th",
" 1st-4th", " 5th-6th", " 7th-8th", " 9th", " Assoc-acdm", " Assoc-voc",
" Bachelors", " Doctorate", " HS-grad", " Masters", " Preschool",
" Prof-school", " Some-college"), class = "factor"), V5 = c(13L,
13L, 9L, 7L, 13L, 14L), V6 = structure(c(5L, 3L, 1L, 3L, 3L,
3L), .Label = c(" Divorced", " Married-AF-spouse", " Married-civ-spouse",
" Married-spouse-absent", " Never-married", " Separated", " Widowed"
), class = "factor"), V7 = structure(c(2L, 5L, 7L, 7L, 11L, 5L
), .Label = c(" ?", " Adm-clerical", " Armed-Forces", " Craft-repair",
" Exec-managerial", " Farming-fishing", " Handlers-cleaners",
" Machine-op-inspct", " Other-service", " Priv-house-serv", " Prof-specialty",
" Protective-serv", " Sales", " Tech-support", " Transport-moving"
), class = "factor"), V8 = structure(c(2L, 1L, 2L, 1L, 6L, 6L
), .Label = c(" Husband", " Not-in-family", " Other-relative",
" Own-child", " Unmarried", " Wife"), class = "factor"), V9 = structure(c(5L,
5L, 5L, 3L, 3L, 5L), .Label = c(" Amer-Indian-Eskimo", " Asian-Pac-Islander",
" Black", " Other", " White"), class = "factor"), V10 = structure(c(2L,
2L, 2L, 2L, 1L, 1L), .Label = c(" Female", " Male"), class = "factor"),
V11 = c(2174L, 0L, 0L, 0L, 0L, 0L), V12 = c(0L, 0L, 0L, 0L,
0L, 0L), V13 = c(40L, 13L, 40L, 40L, 40L, 40L), V14 = structure(c(40L,
40L, 40L, 40L, 6L, 40L), .Label = c(" ?", " Cambodia", " Canada",
" China", " Columbia", " Cuba", " Dominican-Republic", " Ecuador",
" El-Salvador", " England", " France", " Germany", " Greece",
" Guatemala", " Haiti", " Holand-Netherlands", " Honduras",
" Hong", " Hungary", " India", " Iran", " Ireland", " Italy",
" Jamaica", " Japan", " Laos", " Mexico", " Nicaragua", " Outlying-US(Guam-USVI-etc)",
" Peru", " Philippines", " Poland", " Portugal", " Puerto-Rico",
" Scotland", " South", " Taiwan", " Thailand", " Trinadad&Tobago",
" United-States", " Vietnam", " Yugoslavia"), class = "factor")), .Names = c("V1",
"V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10", "V11",
"V12", "V13", "V14"), row.names = c(NA, 6L), class = "data.frame")
trainY
structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c(" <=50K", " >50K"
), class = "factor")
After reading in trainX, trainY, the easiest way to reproduce this problem would be
library(C50)
test = C5.0(x=trainX, y=trainY)
My actual train Y :
structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L,
1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 2L, 1L, 2L, 2L, 1L, 1L), .Label = c(" <=50K", " >50K"), class = "factor")
My actual trainX
structure(list(age = c(39L, 50L, 38L, 53L, 28L, 37L, 49L, 52L,
31L, 42L, 37L, 30L, 23L, 32L, 40L, 34L, 25L, 32L, 38L, 43L, 40L,
54L, 35L, 43L, 59L, 56L, 19L, 54L, 39L, 49L, 23L, 20L, 45L, 30L,
22L, 48L, 21L, 19L, 31L, 48L, 31L, 53L, 24L, 49L, 25L, 57L, 53L,
44L, 41L, 29L, 25L, 18L, 47L, 50L, 47L, 43L, 46L, 35L, 41L, 30L,
30L, 32L, 48L, 42L, 29L, 36L, 28L, 53L, 49L, 25L, 19L, 31L, 29L,
23L, 79L, 27L, 40L, 67L, 18L, 31L, 18L, 52L, 46L, 59L, 44L, 53L,
49L, 33L, 30L, 43L, 57L, 37L, 28L, 30L, 34L, 29L, 48L, 37L, 48L,
32L), workClass = structure(c(8L, 7L, 5L, 5L, 5L, 5L, 5L, 7L,
5L, 5L, 5L, 8L, 5L, 5L, 5L, 5L, 7L, 5L, 5L, 7L, 5L, 5L, 2L, 5L,
5L, 3L, 5L, 1L, 5L, 5L, 3L, 5L, 5L, 2L, 8L, 5L, 5L, 5L, 5L, 7L,
5L, 7L, 5L, 5L, 5L, 2L, 5L, 5L, 8L, 5L, 5L, 5L, 5L, 2L, 6L, 5L,
5L, 5L, 5L, 5L, 5L, 1L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 1L, 5L, 5L,
7L, 5L, 5L, 5L, 5L, 1L, 5L, 3L, 5L, 5L, 5L, 5L, 5L, 5L, 3L, 5L,
5L, 2L, 5L, 5L, 5L, 5L, 3L, 3L, 7L, 5L, 5L, 2L), .Label = c(" ?",
" Federal-gov", " Local-gov", " Never-worked", " Private", " Self-emp-inc",
" Self-emp-not-inc", " State-gov", " Without-pay"), class = "factor"),
fnlwgt = c(77516L, 83311L, 215646L, 234721L, 338409L, 284582L,
160187L, 209642L, 45781L, 159449L, 280464L, 141297L, 122272L,
205019L, 121772L, 245487L, 176756L, 186824L, 28887L, 292175L,
193524L, 302146L, 76845L, 117037L, 109015L, 216851L, 168294L,
180211L, 367260L, 193366L, 190709L, 266015L, 386940L, 59951L,
311512L, 242406L, 197200L, 544091L, 84154L, 265477L, 507875L,
88506L, 172987L, 94638L, 289980L, 337895L, 144361L, 128354L,
101603L, 271466L, 32275L, 226956L, 51835L, 251585L, 109832L,
237993L, 216666L, 56352L, 147372L, 188146L, 59496L, 293936L,
149640L, 116632L, 105598L, 155537L, 183175L, 169846L, 191681L,
200681L, 101509L, 309974L, 162298L, 211678L, 124744L, 213921L,
32214L, 212759L, 309634L, 125927L, 446839L, 276515L, 51618L,
159937L, 343591L, 346253L, 268234L, 202051L, 54334L, 410867L,
249977L, 286730L, 212563L, 117747L, 226296L, 115585L, 191277L,
202683L, 171095L, 249409L), education = structure(c(10L,
10L, 12L, 2L, 10L, 13L, 7L, 12L, 13L, 10L, 16L, 10L, 10L,
8L, 9L, 6L, 12L, 12L, 2L, 13L, 11L, 12L, 7L, 2L, 12L, 10L,
12L, 16L, 12L, 12L, 8L, 16L, 10L, 16L, 16L, 2L, 16L, 12L,
16L, 8L, 7L, 10L, 10L, 12L, 12L, 10L, 12L, 13L, 9L, 9L, 16L,
12L, 15L, 10L, 12L, 16L, 5L, 9L, 12L, 12L, 10L, 6L, 12L,
11L, 16L, 12L, 16L, 12L, 16L, 16L, 16L, 10L, 10L, 16L, 16L,
12L, 8L, 1L, 2L, 6L, 12L, 10L, 12L, 12L, 12L, 12L, 12L, 13L,
7L, 11L, 9L, 16L, 16L, 12L, 10L, 16L, 11L, 16L, 8L, 12L), .Label = c(" 10th",
" 11th", " 12th", " 1st-4th", " 5th-6th", " 7th-8th", " 9th",
" Assoc-acdm", " Assoc-voc", " Bachelors", " Doctorate",
" HS-grad", " Masters", " Preschool", " Prof-school", " Some-college"
), class = "factor"), educationNum = c(13L, 13L, 9L, 7L,
13L, 14L, 5L, 9L, 14L, 13L, 10L, 13L, 13L, 12L, 11L, 4L,
9L, 9L, 7L, 14L, 16L, 9L, 5L, 7L, 9L, 13L, 9L, 10L, 9L, 9L,
12L, 10L, 13L, 10L, 10L, 7L, 10L, 9L, 10L, 12L, 5L, 13L,
13L, 9L, 9L, 13L, 9L, 14L, 11L, 11L, 10L, 9L, 15L, 13L, 9L,
10L, 3L, 11L, 9L, 9L, 13L, 4L, 9L, 16L, 10L, 9L, 10L, 9L,
10L, 10L, 10L, 13L, 13L, 10L, 10L, 9L, 12L, 6L, 7L, 4L, 9L,
13L, 9L, 9L, 9L, 9L, 9L, 14L, 5L, 16L, 11L, 10L, 10L, 9L,
13L, 10L, 16L, 10L, 12L, 9L), marital = structure(c(5L, 3L,
1L, 3L, 3L, 3L, 4L, 3L, 5L, 3L, 3L, 3L, 5L, 5L, 3L, 3L, 5L,
5L, 3L, 1L, 3L, 6L, 3L, 3L, 1L, 3L, 5L, 3L, 1L, 3L, 5L, 5L,
1L, 3L, 3L, 5L, 5L, 2L, 3L, 3L, 3L, 3L, 3L, 6L, 5L, 3L, 3L,
1L, 3L, 5L, 3L, 5L, 3L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 4L,
3L, 3L, 1L, 3L, 1L, 3L, 3L, 5L, 5L, 6L, 3L, 5L, 3L, 5L, 3L,
3L, 5L, 3L, 5L, 3L, 3L, 3L, 1L, 1L, 3L, 3L, 5L, 5L, 3L, 1L,
1L, 3L, 3L, 5L, 3L, 3L, 1L, 5L), .Label = c(" Divorced",
" Married-AF-spouse", " Married-civ-spouse", " Married-spouse-absent",
" Never-married", " Separated", " Widowed"), class = "factor"),
occ = structure(c(2L, 5L, 7L, 7L, 11L, 5L, 9L, 5L, 11L, 5L,
5L, 11L, 2L, 13L, 4L, 15L, 6L, 8L, 13L, 5L, 11L, 9L, 6L,
15L, 14L, 14L, 4L, 1L, 5L, 4L, 12L, 13L, 5L, 2L, 9L, 8L,
8L, 2L, 13L, 11L, 8L, 11L, 14L, 2L, 7L, 11L, 8L, 5L, 4L,
11L, 5L, 9L, 11L, 5L, 5L, 14L, 8L, 9L, 2L, 8L, 13L, 1L, 15L,
11L, 14L, 4L, 2L, 2L, 5L, 1L, 11L, 13L, 13L, 8L, 11L, 9L,
2L, 1L, 9L, 6L, 13L, 9L, 9L, 13L, 4L, 13L, 12L, 11L, 13L,
11L, 11L, 4L, 8L, 13L, 12L, 7L, 11L, 13L, 5L, 9L), .Label = c(" ?",
" Adm-clerical", " Armed-Forces", " Craft-repair", " Exec-managerial",
" Farming-fishing", " Handlers-cleaners", " Machine-op-inspct",
" Other-service", " Priv-house-serv", " Prof-specialty",
" Protective-serv", " Sales", " Tech-support", " Transport-moving"
), class = "factor"), relationship = structure(c(2L, 1L,
2L, 1L, 6L, 6L, 2L, 1L, 2L, 1L, 1L, 1L, 4L, 2L, 1L, 1L, 4L,
5L, 1L, 5L, 1L, 5L, 1L, 1L, 5L, 1L, 4L, 1L, 2L, 1L, 2L, 4L,
4L, 4L, 1L, 5L, 4L, 6L, 1L, 1L, 1L, 1L, 1L, 5L, 2L, 1L, 1L,
5L, 1L, 2L, 6L, 4L, 6L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
1L, 1L, 2L, 1L, 2L, 6L, 1L, 4L, 4L, 4L, 1L, 2L, 3L, 4L, 1L,
1L, 4L, 1L, 2L, 1L, 6L, 1L, 2L, 4L, 1L, 1L, 2L, 2L, 1L, 5L,
5L, 6L, 1L, 2L, 1L, 1L, 5L, 4L), .Label = c(" Husband", " Not-in-family",
" Other-relative", " Own-child", " Unmarried", " Wife"), class = "factor"),
race = structure(c(5L, 5L, 5L, 3L, 3L, 5L, 3L, 5L, 5L, 5L,
3L, 2L, 5L, 3L, 2L, 1L, 5L, 5L, 5L, 5L, 5L, 3L, 3L, 5L, 5L,
5L, 5L, 2L, 5L, 5L, 5L, 3L, 5L, 5L, 3L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 3L, 5L, 5L, 5L, 5L, 4L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 3L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 3L, 2L, 5L, 5L, 5L, 5L, 5L, 3L
), .Label = c(" Amer-Indian-Eskimo", " Asian-Pac-Islander",
" Black", " Other", " White"), class = "factor"), sex = structure(c(2L,
2L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L,
2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L), .Label = c(" Female",
" Male"), class = "factor"), capGain = c(2174L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 14084L, 5178L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 5013L, 2407L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 14344L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), capLoss = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 2042L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 1408L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1902L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 1573L, 0L, 0L, 1902L, 0L, 0L, 0L), hours = c(40L,
13L, 40L, 40L, 40L, 40L, 16L, 45L, 50L, 40L, 80L, 40L, 30L,
50L, 40L, 45L, 35L, 40L, 50L, 45L, 60L, 20L, 40L, 40L, 40L,
40L, 40L, 60L, 80L, 40L, 52L, 44L, 40L, 40L, 15L, 40L, 40L,
25L, 38L, 40L, 43L, 40L, 50L, 40L, 35L, 40L, 38L, 40L, 40L,
43L, 40L, 30L, 60L, 55L, 60L, 40L, 40L, 40L, 48L, 40L, 40L,
40L, 40L, 45L, 58L, 40L, 40L, 40L, 50L, 40L, 32L, 40L, 70L,
40L, 20L, 40L, 40L, 2L, 22L, 40L, 30L, 40L, 40L, 48L, 40L,
35L, 40L, 50L, 40L, 50L, 40L, 40L, 25L, 35L, 40L, 50L, 60L,
48L, 40L, 40L), country = structure(c(40L, 40L, 40L, 40L,
6L, 40L, 24L, 40L, 40L, 40L, 40L, 20L, 40L, 40L, 1L, 27L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 36L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 34L, 40L, 40L, 1L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 1L,
17L, 40L, 40L, 40L, 27L, 34L, 40L, 40L, 40L, 1L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 27L,
40L, 40L, 40L, 40L, 40L, 6L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 1L, 40L, 40L, 40L, 40L, 10L, 40L
), .Label = c(" ?", " Cambodia", " Canada", " China", " Columbia",
" Cuba", " Dominican-Republic", " Ecuador", " El-Salvador",
" England", " France", " Germany", " Greece", " Guatemala",
" Haiti", " Holand-Netherlands", " Honduras", " Hong", " Hungary",
" India", " Iran", " Ireland", " Italy", " Jamaica", " Japan",
" Laos", " Mexico", " Nicaragua", " Outlying-US(Guam-USVI-etc)",
" Peru", " Philippines", " Poland", " Portugal", " Puerto-Rico",
" Scotland", " South", " Taiwan", " Thailand", " Trinadad&Tobago",
" United-States", " Vietnam", " Yugoslavia"), class = "factor")), .Names = c("age",
"workClass", "fnlwgt", "education", "educationNum", "marital",
"occ", "relationship", "race", "sex", "capGain", "capLoss", "hours",
"country"), row.names = c(NA, 100L), class = "data.frame")
The code you provided constructs a factor with 1 level (<=50k) because the first vector input contains only 1Ls. You should assign these labels accordingly or use an easier way to construct your response variable - something like trainY <- as.factor(...).
I changed the way trainY is constructed to:
y <- structure(c(1L, 2L, 1L, 1L, 2L, 1L), .Label = c(" <=50K", " >50K"), class = "factor")
and after re-training the tree with same commands i got:
Decision tree:
V14 = Cuba: >50K (1)
V14 in {?,Cambodia,Canada,China,Columbia,Dominican-Republic,Ecuador,
El-Salvador,England,France,Germany,Greece,Guatemala,Haiti,
Holand-Netherlands,Honduras,Hong,Hungary,India,Iran,Ireland,Italy,
Jamaica,Japan,Laos,Mexico,Nicaragua,Outlying-US(Guam-USVI-etc),Peru,
Philippines,Poland,Portugal,Puerto-Rico,Scotland,South,Taiwan,Thailand,
Trinadad&Tobago,United-States,Vietnam,Yugoslavia}: <=50K (5/1)
Make sure you don't have only one class in the response when passing args to C5.0. hth
UPDATE
After plotting some of the predictors vs response I noticed that education and educationNum show the clearest division in the data (Doctorate implies >50K immediately). Next step was to tweak some of the very useful C5.0 Control options - they are well documented in the C5.0 package documentation and the official informal tutorial page - check them out they give you broad control over the classification controls.
For example:
C5.0(x = trainX,y = trainY,control = C5.0Control(subset = T, winnow = T,minCases = 4,fuzzyThreshold = T))
Decision tree:
educationNum <= 13 (14.5): <=50K (95/20)
educationNum >= 16 (14.5): >50K (5)
similiarly, doing some "feature engineering" which in this case meant just leaving out some of the columns from the original dataframe produced :
C5.0(x = trainX[ ,c(1:5, 9:13)], y = trainY)
Decision tree:
educationNum <= 14: <=50K (95/20)
educationNum > 14: >50K (5)
I believe that there is no one general "out of the box" C5.0 defaults setting that would produce satisfying results for all kinds of problems, so it really comes down to trying out different parameter settings, features etc...but as with all things R there is plenty of material around to give you some direction.

Resources