Unexpected clustering errors (partitioning around mediods) - r

I am using the fpc package for determining the optimal number of clusters. The pamk() function takes a dissimilarity matrix as an argument and does not require the user to specify k. According to the documentation:
pamk() This calls pam and clara for the partitioning around medoids
clustering method (Kaufman and Rouseeuw, 1990) and includes two
different ways of estimating the number of clusters.
but when I input two very similar matricies - foo and bar (data below), the function errors out on the second matrix (bar)
Error in pam(sdata, k, diss = diss, ...) :
Number of clusters 'k' must be in {1,2, .., n-1}; hence n >= 2
What could be causing this error, given that the input matricies are basically the same? For example:
foo works!
hc <- hclust(as.dist(foo))
plot(hc)
pamk.best <- fpc::pamk(foo)
pamk.best$nc
[1] 2
bar does not
hc <- hclust(as.dist(bar))
plot(hc, main = 'bar dendogram')
pamk.best <- fpc::pamk(bar)
Error in pam(sdata, k, diss = diss, ...) :
Number of clusters 'k' must be in {1,2, .., n-1}; hence n >= 2
Any suggestions would be helpful!
dput(foo)
structure(c(0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 9, 0, 0, 0,
0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0,
0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 9, 0, 0, 0,
0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0,
0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 9, 9, 9, 9,
9, 9, 9, 9, 0, 9, 9, 9, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0,
0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 9, 0, 0, 0,
0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0,
0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 9, 9, 9, 9,
9, 9, 9, 9, 0, 9, 9, 9, 9, 9, 0), .Dim = c(14L, 14L), .Dimnames = list(
c("etc", "etc", "etc", "etc", "etc", "etc", "etc", "similares",
"etc", "etc", "etc", "etc", "etc", "similares"), NULL))
dput(bar)
structure(c(0, 6, 6, 6, 6, 6, 0, 0, 0, 0, 6, 0, 0, 0, 0, 6, 0,
0, 0, 0, 6, 0, 0, 0, 0), .Dim = c(5L, 5L), .Dimnames = list(c("ramírez",
"similares", "similares", "similares", "similares"), NULL))

bar has n=5 columns, so the max(krange) has to be <= n-1, thus 4. The default krange is 2:10, hence the error. You may have to pass an appropriate krange; try:
pamk.best <- fpc::pamk(bar, krange=c(2:(dim(bar)[2]-1)))

Related

Representing a correlation matrix without a "classical" heatmap

I'm doing some analysis on a complex network. I have computed the degree correlation matrix, which looks like this:
data[1:5, 1:5]
1 2 3 4 5
1 6 19 11 16 5
2 19 10 16 12 6
3 11 16 7 11 10
4 16 12 11 5 9
5 5 6 10 9 8
And I'd like to plot it to obtain something akin to this:
I've tried to use ggplot but the results are not at all satisfying, this is my code:
library(reshape2)
library(ggplot2)
data = melt(data)
#The "melt" function was used to turn the matrix in a three column dataframe with columns named "Var1",
"Var2", and "value"
ggplot(data = data) +
theme_bw() +
geom_tile(aes(x = Var1, y = Var2, fill = value)) +
scale_fill_viridis(name = "") +
labs(x = "k2", y = "k1")
And this is what I get:
Is there any way to fix it?
P.S. Sorry if I couldn't post the images directly, but my reputation is not high enough
EDIT: I'm putting here the dput() output of my matrix, as asked in the comments:
structure(c(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, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 7, 5, 3, 10, 4, 3, 4,
6, 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, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), dim = c(75L, 75L), dimnames = list(
c("2", "3", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "18", "19", "20", "21", "22", "23", "24",
"25", "26", "27", "28", "29", "30", "31", "32", "33", "34",
"35", "36", "37", "38", "39", "40", "41", "42", "43", "44",
"45", "46", "47", "48", "49", "50", "51", "52", "53", "54",
"55", "56", "57", "58", "59", "60", "61", "62", "63", "64",
"65", "66", "67", "68", "69", "70", "71", "72", "73", "74",
"75", "77", "79", "81"), c("2", "3", "5", "6", "7", "8",
"9", "10", "11", "12", "13", "14", "15", "16", "18", "19",
"20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
"30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
"40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
"50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
"60", "61", "62", "63", "64", "65", "66", "67", "68", "69",
"70", "71", "72", "73", "74", "75", "77", "79", "81")))
You get the lines because you have missing values. The full range is not represented in your data. Here's one way to fill in the missing values using tidyr
library(dplyr)
library(tidyr)
full_range <- function(x) seq(min(x), max(x))
data %>%
as.data.frame() %>%
tibble::rownames_to_column("Var1") %>%
pivot_longer(-Var1, names_to="Var2") %>%
mutate(across(Var1:Var2, as.numeric)) %>% {
d <- .
expand_grid(Var1=full_range(d$Var1), Var2=full_range(d$Var2)) %>%
left_join(d) %>%
replace_na(list(value=0))
} %>%
ggplot() +
theme_bw() +
geom_tile(aes(x = Var1, y = Var2, fill = value)) +
scale_fill_viridis_c(name = "") +
labs(x = "k2", y = "k1")
that looks like this

Errors with distance-decay using betapart and ddecay packages

My goal is to create a distance-decay curve for species data vs geographic distance. However, I am running into errors. For the betapart package, this may be due to the lack of columns relative to the number of rows. Is there a way to get past this? If not, is there another method for creating a distance-decay curve (and plotting it)? I also tried the ddecay package but ran into errors there too. Any help is much appreciated. Data is in structure form below.
# BETAPART -------------------------------------------------
library(betapart)
spat.dist<-dist(coords)
dissim.BCI<-beta.pair.abund(spec)$beta.bray.bal
plot(spat.dist, dissim.BCI, ylim=c(0,1), xlim=c(0, max(spat.dist)))
BCI.decay.exp<-decay.model(dissim.BCI, spat.dist, y.type="dissim", model.type="exp", perm=100)
#========================================================================================================
I also tried a few other packages --------------------------
# ddecay package -------------------------------------------
devtools::install_github("chihlinwei/ddecay")
the issue with this method is that it requires the use of a gradient however, I would like to avoid that if possible but I do not see a way around this. Also they do not include their example data in the package.
dd <- beta.decay(gradient=spat.dist, counts=decostand(spec, method="pa"),
coords=coords, nboots=1000,
dis.fun = "beta.pair", index.family = "sorensen", dis = 1, like.pairs=T)
x <- vegdist(coords, method = "euclidean")
y <- 1 - dist(decostand(spec, method="pa"), index.family = "sorensen")[[1]]
plot(x, y)
lines(dd$Predictions[, "x"], dd$Predictions[,"mean"], col="red", lwd=2)
#========================================================================================================
# DATA -----------------------------------------------------
spec <- structure(list(Ccol = c(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Acol = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0), NYcol = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0), Mcol = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 0,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, 0, 0, 0, 24, 0, 6, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0,
9, 17, 17), VCcol = c(0, 38, 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), Vcol = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0), Ocol = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0), AVcol = c(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, 1), JXcol = c(0,
3, 3, 0, 0, 0, 0, 0, 8, 0, 0, 10, 3, 0, 0, 5, 0, 0, 0, 1,
0, 0, 0, 2, 4, 1, 0, 0, 0)), class = "data.frame", row.names = c(NA,
-29L))
coords <- structure(list(Lat.x = c(34.43363, 34.36784, 34.32587, 34.19891,
34.24217, 34.24863, 34.18137, 34.16838, 34.10961, 34.08329, 34.40571,
34.39591, 34.39292, 34.37466, 34.28948, 34.26146, 34.04687, 34.0409,
34.068339, 34.34679, 34.17161, 34.23308, 34.21544, 34.14922,
34.27539, 34.2323, 34.19057, 34.07042, 34.06289), Lon.x = c(-94.94494,
-94.92512, -94.94429, -94.84497, -94.8573, -94.85641, -94.887,
-94.91322, -94.92913, -94.93276, -95.02622, -95.04382, -94.96295,
-94.83733, -94.81071, -94.79161, -95.03968, -95.0608, -95.086986,
-95.03345, -95.23862, -95.25619, -95.1041, -95.02286, -95.02672,
-95.02626, -95.02941, -95.01746, -94.98786)), class = "data.frame", row.names = c(NA,
-29L))
You can get more answers, if you tell what was the problem. For instance, which functions failed and what was the error message. I had a look at betapart::decay.model(), where I could get this error message:
Error in eval(family$initialize) :
cannot find valid starting values: please specify some
I cut the long story short: you cannot use this function with your data because you have dissimilarities of 1 in your data, dissimilarities are turned into similarities with 1-dissimilarity and this makes these values zero similarities (that is, these pairs of sampling unit have nothing in common, they share no species). Function decay.model uses glm with gaussian family with log-link, and log-link requires that you give the starting values, if you have zeros in the y-variate.
I think that you have four alternatives:
You do not use the method as it does not suit your data.
You modify the decay.model function so that you can specify the starting values, like the error message suggested. This means that you add mustart to the function call so that it reads, e.g., glm(y ~ x, family=gaussian(link="log"), mustart=pmax(y, 0.01)). This replaces zeros with 0.01 as starting values.
You change maximum distances from 1 to something smaller, for instance, 0.99: dissim.BCI[dissim.BCI==1] <- 0.99. However, this changes the data, and also changes the results from those you get with alternative 2 (which only changes starting values, but data are unmodified). However, the effect is not very large and any Bayesian would claim that dissimilarity 1 is just a frequentist folly (you just haven't seen the case that is in common with these sampling units).
You change the maximum distance to missing values. This will change data more than alternative 3. It removes maximum dissimilarities and these no longer influence the decay curve. The effect is the same as censoring greatest dissimilarities. The results change more than in alternative 3.

Why is auto.arima() giving me the Error: "'by' argument is much too small"

I am working on predicting intra-day sales for a retailer. We want to know if we can predict sales through the rest of the day, based off sales within that day. I'm working with roughly 3 years of data in a time series, which has given me roughly 26,000 rows of data.
I've never worked with a time series this large so my approach might be off. Or auto.arima() may not have been made to handle data this large.
I've tried limiting my data down to even 300 rows and had marginal success, but have not found anything that works with my larger data set. auto.arima() doesn't even have a by = argument from what I can find.
my_ts <- structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 3,
3, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 4, 1,
1, 0, 3, 1, 0, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4,
1, 9, 1, 6, 5, 1, 0, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 3, 1, 0, 3, 5, 2, 3, 4, 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 0, 0, 0, 1, 0, 0, 1, 4, 1, 2, 0, 0, 5, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 8, 0, 1, 1, 4, 0, 4, 3,
2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 6, 1, 0, 0, 0,
3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8,
1, 2, 0, 4, 2, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
1, 6, 7, 0, 1, 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 5, 0, 2, 1, 4, 1, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 2, 1, 4, 7, 5, 0, 7, 4, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 1, 6, 0, 4, 6, 2, 1, 3, 5, 3, 3, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 4, 3, 0, 1, 1, 3,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 6, 0, 0), index = structure(c(1435190400,
1435194000, 1435197600, 1435201200, 1435204800, 1435208400, 1435212000,
1435215600, 1435219200, 1435222800, 1435226400, 1435230000, 1435233600,
1435237200, 1435240800, 1435244400, 1435248000, 1435251600, 1435255200,
1435258800, 1435262400, 1435266000, 1435269600, 1435273200, 1435276800,
1435280400, 1435284000, 1435287600, 1435291200, 1435294800, 1435298400,
1435302000, 1435305600, 1435309200, 1435312800, 1435316400, 1435320000,
1435323600, 1435327200, 1435330800, 1435334400, 1435338000, 1435341600,
1435345200, 1435348800, 1435352400, 1435356000, 1435359600, 1435363200,
1435366800, 1435370400, 1435374000, 1435377600, 1435381200, 1435384800,
1435388400, 1435392000, 1435395600, 1435399200, 1435402800, 1435406400,
1435410000, 1435413600, 1435417200, 1435420800, 1435424400, 1435428000,
1435431600, 1435435200, 1435438800, 1435442400, 1435446000, 1435449600,
1435453200, 1435456800, 1435460400, 1435464000, 1435467600, 1435471200,
1435474800, 1435478400, 1435482000, 1435485600, 1435489200, 1435492800,
1435496400, 1435500000, 1435503600, 1435507200, 1435510800, 1435514400,
1435518000, 1435521600, 1435525200, 1435528800, 1435532400, 1435536000,
1435539600, 1435543200, 1435546800, 1435550400, 1435554000, 1435557600,
1435561200, 1435564800, 1435568400, 1435572000, 1435575600, 1435579200,
1435582800, 1435586400, 1435590000, 1435593600, 1435597200, 1435600800,
1435604400, 1435608000, 1435611600, 1435615200, 1435618800, 1435622400,
1435626000, 1435629600, 1435633200, 1435636800, 1435640400, 1435644000,
1435647600, 1435651200, 1435654800, 1435658400, 1435662000, 1435665600,
1435669200, 1435672800, 1435676400, 1435680000, 1435683600, 1435687200,
1435690800, 1435694400, 1435698000, 1435701600, 1435705200, 1435708800,
1435712400, 1435716000, 1435719600, 1435723200, 1435726800, 1435730400,
1435734000, 1435737600, 1435741200, 1435744800, 1435748400, 1435752000,
1435755600, 1435759200, 1435762800, 1435766400, 1435770000, 1435773600,
1435777200, 1435780800, 1435784400, 1435788000, 1435791600, 1435795200,
1435798800, 1435802400, 1435806000, 1435809600, 1435813200, 1435816800,
1435820400, 1435824000, 1435827600, 1435831200, 1435834800, 1435838400,
1435842000, 1435845600, 1435849200, 1435852800, 1435856400, 1435860000,
1435863600, 1435867200, 1435870800, 1435874400, 1435878000, 1435881600,
1435885200, 1435888800, 1435892400, 1435896000, 1435899600, 1435903200,
1435906800, 1435910400, 1435914000, 1435917600, 1435921200, 1435924800,
1435928400, 1435932000, 1435935600, 1435939200, 1435942800, 1435946400,
1435950000, 1435953600, 1435957200, 1435960800, 1435964400, 1435968000,
1435971600, 1435975200, 1435978800, 1435982400, 1435986000, 1435989600,
1435993200, 1435996800, 1436000400, 1436004000, 1436007600, 1436011200,
1436014800, 1436018400, 1436022000, 1436025600, 1436029200, 1436032800,
1436036400, 1436040000, 1436043600, 1436047200, 1436050800, 1436054400,
1436058000, 1436061600, 1436065200, 1436068800, 1436072400, 1436076000,
1436079600, 1436083200, 1436086800, 1436090400, 1436094000, 1436097600,
1436101200, 1436104800, 1436108400, 1436112000, 1436115600, 1436119200,
1436122800, 1436126400, 1436130000, 1436133600, 1436137200, 1436140800,
1436144400, 1436148000, 1436151600, 1436155200, 1436158800, 1436162400,
1436166000, 1436169600, 1436173200, 1436176800, 1436180400, 1436184000,
1436187600, 1436191200, 1436194800, 1436198400, 1436202000, 1436205600,
1436209200, 1436212800, 1436216400, 1436220000, 1436223600, 1436227200,
1436230800, 1436234400, 1436238000, 1436241600, 1436245200, 1436248800,
1436252400, 1436256000, 1436259600, 1436263200, 1436266800, 1436270400,
1436274000, 1436277600, 1436281200, 1436284800, 1436288400, 1436292000,
1436295600, 1436299200, 1436302800, 1436306400, 1436310000, 1436313600,
1436317200, 1436320800, 1436324400, 1436328000, 1436331600, 1436335200,
1436338800, 1436342400, 1436346000, 1436349600, 1436353200, 1436356800,
1436360400, 1436364000, 1436367600, 1436371200, 1436374800, 1436378400,
1436382000, 1436385600, 1436389200, 1436392800, 1436396400, 1436400000,
1436403600, 1436407200, 1436410800, 1436414400, 1436418000, 1436421600,
1436425200, 1436428800, 1436432400, 1436436000, 1436439600, 1436443200,
1436446800, 1436450400, 1436454000, 1436457600, 1436461200, 1436464800,
1436468400, 1436472000, 1436475600, 1436479200, 1436482800, 1436486400,
1436490000, 1436493600, 1436497200, 1436500800, 1436504400, 1436508000,
1436511600, 1436515200, 1436518800, 1436522400, 1436526000, 1436529600,
1436533200, 1436536800, 1436540400, 1436544000, 1436547600, 1436551200,
1436554800, 1436558400, 1436562000, 1436565600, 1436569200, 1436572800,
1436576400, 1436580000, 1436583600, 1436587200, 1436590800, 1436594400,
1436598000, 1436601600, 1436605200, 1436608800, 1436612400, 1436616000,
1436619600, 1436623200, 1436626800, 1436630400, 1436634000, 1436637600,
1436641200, 1436644800, 1436648400, 1436652000, 1436655600, 1436659200,
1436662800, 1436666400, 1436670000, 1436673600, 1436677200, 1436680800,
1436684400, 1436688000, 1436691600, 1436695200, 1436698800, 1436702400,
1436706000, 1436709600, 1436713200, 1436716800, 1436720400, 1436724000,
1436727600, 1436731200, 1436734800, 1436738400, 1436742000, 1436745600,
1436749200, 1436752800, 1436756400, 1436760000, 1436763600, 1436767200,
1436770800, 1436774400, 1436778000, 1436781600, 1436785200, 1436788800,
1436792400, 1436796000, 1436799600, 1436803200, 1436806800, 1436810400,
1436814000, 1436817600, 1436821200, 1436824800, 1436828400, 1436832000,
1436835600, 1436839200, 1436842800, 1436846400, 1436850000, 1436853600,
1436857200, 1436860800, 1436864400, 1436868000, 1436871600, 1436875200,
1436878800, 1436882400, 1436886000, 1436889600, 1436893200, 1436896800,
1436900400, 1436904000, 1436907600, 1436911200, 1436914800, 1436918400,
1436922000, 1436925600, 1436929200, 1436932800, 1436936400, 1436940000,
1436943600, 1436947200, 1436950800, 1436954400, 1436958000, 1436961600,
1436965200, 1436968800, 1436972400, 1436976000, 1436979600, 1436983200,
1436986800, 1436990400, 1436994000, 1436997600, 1437001200, 1437004800,
1437008400, 1437012000, 1437015600, 1437019200, 1437022800, 1437026400,
1437030000, 1437033600, 1437037200, 1437040800, 1437044400, 1437048000,
1437051600, 1437055200, 1437058800, 1437062400, 1437066000, 1437069600,
1437073200, 1437076800, 1437080400, 1437084000, 1437087600, 1437091200,
1437094800, 1437098400, 1437102000, 1437105600, 1437109200, 1437112800,
1437116400, 1437120000, 1437123600, 1437127200, 1437130800, 1437134400,
1437138000, 1437141600, 1437145200, 1437148800, 1437152400, 1437156000,
1437159600, 1437163200, 1437166800, 1437170400, 1437174000, 1437177600,
1437181200, 1437184800, 1437188400, 1437192000, 1437195600, 1437199200,
1437202800, 1437206400, 1437210000, 1437213600, 1437217200, 1437220800,
1437224400, 1437228000, 1437231600, 1437235200, 1437238800, 1437242400,
1437246000, 1437249600, 1437253200, 1437256800, 1437260400, 1437264000,
1437267600, 1437271200, 1437274800, 1437278400, 1437282000, 1437285600,
1437289200, 1437292800, 1437296400, 1437300000, 1437303600, 1437307200,
1437310800, 1437314400, 1437318000, 1437321600, 1437325200, 1437328800,
1437332400, 1437336000, 1437339600, 1437343200, 1437346800, 1437350400,
1437354000, 1437357600, 1437361200, 1437364800, 1437368400, 1437372000,
1437375600, 1437379200, 1437382800, 1437386400, 1437390000, 1437393600,
1437397200, 1437400800, 1437404400, 1437408000, 1437411600, 1437415200,
1437418800, 1437422400, 1437426000, 1437429600, 1437433200, 1437436800,
1437440400, 1437444000, 1437447600, 1437451200, 1437454800, 1437458400,
1437462000, 1437465600, 1437469200, 1437472800, 1437476400, 1437480000,
1437483600, 1437487200, 1437490800, 1437494400, 1437498000, 1437501600,
1437505200, 1437508800, 1437512400, 1437516000, 1437519600, 1437523200,
1437526800, 1437530400, 1437534000, 1437537600, 1437541200, 1437544800,
1437548400, 1437552000, 1437555600, 1437559200, 1437562800, 1437566400,
1437570000, 1437573600, 1437577200, 1437580800, 1437584400, 1437588000,
1437591600, 1437595200, 1437598800, 1437602400, 1437606000, 1437609600,
1437613200, 1437616800, 1437620400, 1437624000, 1437627600, 1437631200,
1437634800, 1437638400, 1437642000, 1437645600, 1437649200, 1437652800,
1437656400, 1437660000, 1437663600, 1437667200, 1437670800, 1437674400,
1437678000, 1437681600, 1437685200, 1437688800, 1437692400, 1437696000,
1437699600, 1437703200, 1437706800, 1437710400, 1437714000, 1437717600,
1437721200, 1437724800, 1437728400, 1437732000, 1437735600, 1437739200,
1437742800, 1437746400, 1437750000, 1437753600, 1437757200, 1437760800,
1437764400, 1437768000, 1437771600, 1437775200, 1437778800, 1437782400,
1437786000, 1437789600, 1437793200, 1437796800, 1437800400, 1437804000,
1437807600, 1437811200, 1437814800, 1437818400, 1437822000, 1437825600,
1437829200, 1437832800, 1437836400, 1437840000, 1437843600, 1437847200,
1437850800, 1437854400, 1437858000, 1437861600, 1437865200, 1437868800,
1437872400, 1437876000, 1437879600, 1437883200, 1437886800, 1437890400,
1437894000, 1437897600, 1437901200, 1437904800, 1437908400, 1437912000,
1437915600, 1437919200, 1437922800, 1437926400, 1437930000, 1437933600,
1437937200, 1437940800, 1437944400, 1437948000, 1437951600, 1437955200,
1437958800, 1437962400, 1437966000, 1437969600, 1437973200, 1437976800,
1437980400, 1437984000, 1437987600, 1437991200, 1437994800, 1437998400,
1438002000, 1438005600, 1438009200, 1438012800, 1438016400, 1438020000,
1438023600, 1438027200, 1438030800, 1438034400, 1438038000, 1438041600,
1438045200, 1438048800, 1438052400, 1438056000, 1438059600, 1438063200,
1438066800, 1438070400, 1438074000, 1438077600, 1438081200, 1438084800,
1438088400, 1438092000, 1438095600, 1438099200, 1438102800, 1438106400,
1438110000, 1438113600, 1438117200, 1438120800, 1438124400, 1438128000,
1438131600, 1438135200, 1438138800, 1438142400, 1438146000, 1438149600,
1438153200, 1438156800, 1438160400, 1438164000, 1438167600, 1438171200,
1438174800, 1438178400, 1438182000, 1438185600, 1438189200, 1438192800,
1438196400, 1438200000, 1438203600, 1438207200, 1438210800, 1438214400,
1438218000, 1438221600, 1438225200, 1438228800, 1438232400, 1438236000,
1438239600, 1438243200, 1438246800, 1438250400, 1438254000, 1438257600,
1438261200, 1438264800, 1438268400, 1438272000, 1438275600, 1438279200,
1438282800, 1438286400, 1438290000, 1438293600, 1438297200, 1438300800,
1438304400, 1438308000, 1438311600, 1438315200, 1438318800, 1438322400,
1438326000, 1438329600, 1438333200, 1438336800, 1438340400, 1438344000,
1438347600, 1438351200, 1438354800, 1438358400, 1438362000, 1438365600,
1438369200, 1438372800, 1438376400, 1438380000, 1438383600, 1438387200,
1438390800, 1438394400, 1438398000, 1438401600, 1438405200, 1438408800,
1438412400, 1438416000, 1438419600, 1438423200, 1438426800, 1438430400,
1438434000, 1438437600, 1438441200, 1438444800, 1438448400, 1438452000,
1438455600, 1438459200, 1438462800, 1438466400, 1438470000, 1438473600,
1438477200, 1438480800, 1438484400, 1438488000, 1438491600, 1438495200,
1438498800, 1438502400, 1438506000, 1438509600, 1438513200, 1438516800,
1438520400, 1438524000, 1438527600, 1438531200, 1438534800, 1438538400,
1438542000, 1438545600, 1438549200, 1438552800, 1438556400, 1438560000,
1438563600, 1438567200, 1438570800, 1438574400, 1438578000, 1438581600,
1438585200, 1438588800, 1438592400, 1438596000, 1438599600, 1438603200,
1438606800, 1438610400, 1438614000, 1438617600, 1438621200, 1438624800,
1438628400, 1438632000, 1438635600, 1438639200, 1438642800, 1438646400,
1438650000, 1438653600, 1438657200, 1438660800, 1438664400, 1438668000,
1438671600, 1438675200, 1438678800, 1438682400, 1438686000, 1438689600,
1438693200, 1438696800, 1438700400, 1438704000, 1438707600, 1438711200,
1438714800, 1438718400, 1438722000, 1438725600, 1438729200, 1438732800,
1438736400, 1438740000, 1438743600, 1438747200, 1438750800, 1438754400,
1438758000, 1438761600, 1438765200, 1438768800, 1438772400, 1438776000,
1438779600, 1438783200, 1438786800), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), class = c("zooreg", "zoo"), frequency = 24)
fit1 <-auto.arima(my_ts,seasonal = TRUE)
I was hoping to get a model through arima, but I'm only getting the error:
"Error in seq.default(head(tt, 1), tail(tt, 1), deltat) :
'by' argument is much too small"

Stacked barplot with partitioned main and sub x label

I'm new to R. I want to create a stacked barplot based on the following data. I want to plot these data into a stacked barplot that describes percentage of disease score for each combination of genotype and race in x axis, e.g. 76R-race 1, rmc-race 1. As well how to simplify the x axis, by splitting each race to have 76R and rmc combination instead of labelling each combination, i.e. instead of labelling each bar with 76R-race 1, rmc-race 1, etc, how to label race 1 as main axis and have 76R and rmc as sub-axis, and so on.
disease.nov <- data.frame(disease.score = c(0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 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, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
genotype=gl(2,52,624, labels=c("76R","rmc")),
race=gl(6,104,624, labels=c("race 1","race 2","race 3","WAC 7673","WAC 7591","control")))
I'm not sure if this is what you're looking for:
library(ggplot2)
library(scales)
ggplot(disease.nov, aes(x=genotype, fill=factor(disease.score))) +
geom_bar(position="fill") +
facet_wrap(~ race) +
scale_y_continuous(labels = percent_format())
Which produces:

Weighted vertex cover (as linear programming) in R with the ROI package

I'm trying to solve an instance of the weighted vertex cover problem using R for homework and I can't seem to get it right. I'm using the ROI package (could just as well use linprog).
The instance looks like this:
Edges:
A-B, A-C, A-G,
B-C, B-D, B-E, B-G,
C-E, C-F,
D-F,
E-G,
F-H, F-I,
G-H
Weights:
A - 10,
B - 7,
C - 4,
D - 7,
E - 12,
F - 25,
G - 27,
H - 3,
I - 9
My code is:
# a b c d e f g h i
constraints <- L_constraint(matrix(c(1, 1, 0, 0, 0, 0, 0, 0, 0, # a b
1, 0, 1, 0, 0, 0, 0, 0, 0, # a c
1, 0, 0, 0, 0, 0, 1, 0, 0, # a g
0, 1, 1, 0, 0, 0, 0, 0, 0, # b c
0, 1, 0, 1, 0, 0, 0, 0, 0, # b d
0, 1, 0, 0, 1, 0, 0, 0, 0, # b e
0, 1, 0, 0, 0, 0, 1, 0, 0, # b g
0, 0, 1, 0, 1, 0, 0, 0, 0, # c e
0, 0, 1, 0, 0, 1, 0, 0, 0, # c f
0, 0, 0, 1, 0, 1, 0, 0, 0, # d f
0, 0, 0, 0, 1, 0, 1, 0, 0, # e g
0, 0, 0, 0, 0, 1, 0, 1, 0, # f h
0, 0, 0, 0, 0, 1, 0, 0, 1, # f i
0, 0, 0, 0, 0, 0, 1, 1, 0, # g h
# end of u + v >= 1
1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1,
# end of u >= 0
1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1),
# end of u <= 1
ncol = 9), # matrix
dir = c(rep(">=", 14+9), rep("<=", 9)),
rhs = c(rep(1, 14), rep(0, 9), rep(1, 9))) # L_constraint
objective <- L_objective(c(10, 7, 4, 7, 12, 25, 27, 3, 9))
problem <- OP(objective, constraints, rep("C", 9),
maximum = FALSE)
solution <- ROI_solve(problem, solver = "glpk")
The result is No solution found. I don't know what I'm doing wrong, but it may just as well be something obvious. Can't get my head around it -- a solution should always exist, even if it takes all the vertices (i. e. all variables are >= 0.5).
If it matters, I'm on Arch Linux running R from the repositories (ver. 2.14) and installed the packages via install.packages("...").
Thanks!
Okay, solved it. The problem was that I didn't add byrows = TRUE to the matrix definition. In addition I changed ncol = 9 into nrow = .... Apparently the matrix() function did not work as I expected.

Resources