mixed model for paired data - 4 level outcome / 3 times - r

What is the correct test to evaluate the difference between 3 RX readers of the same 50 patients? The rx outcome is a categorical value with 4 ordered levels. The 3 reader have read the RX at the same time.
May I use a mixed model for paired data with patients as random effect?
I'm really in difficulty...
I've tried the repolr package for repeated ordinal scores:
repolr(formula = rsna ~ factor(reader) ,
subjects = "Patient" , data = mydata ,
categories = 4, times=c(1,2,3), po.test=TRUE,fixed=FALSE)
but I obtain this error:
Error in ord.expand(space = space, formula = formula, times = times, poly = poly, :
data: model frame and formula mismatch in model.matrix()
Here are the data:
mydata<- data.frame(Patient = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50),
reader = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3),
rsna = c(1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 1, 1, 2, 2, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 2, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 4, 4, 4, 2, 1, 3, 2, 1, 1, 1, 2, 1, 3, 1, 1, 1, 3, 1, 1, 1, 1, 1, 4, 2, 2, 1, 1))
rsna is my outcome with 4 levels, Patients are the 50 patients, reader are the 3 readers.
How can I fix it?

If you turn the reader variable into a factor in the dataset first, it works:
mydata<- data.frame(Patient = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 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 1, 1, 3, 1, 1, 1, 1, 1, 4, 2, 2, 1, 1))
mydata$reader <- as.factor(mydata$reader)
library(repolr)
repolr(formula = rsna ~ reader,
subjects = "Patient" , data = mydata ,
categories = 4, times=c(1,2,3), po.test=TRUE,fixed=FALSE)
#>
#> repolr: 2016-02-26 version 3.4
#>
#> Call:
#> repolr(formula = rsna ~ reader, subjects = "Patient", data = mydata,
#> times = c(1, 2, 3), categories = 4, po.test = TRUE, fixed = FALSE)
#>
#> Coefficients:
#> cuts1|2 cuts2|3 cuts3|4 reader2 reader3
#> 1.1761 2.1395 2.9071 0.6600 -0.4768
Created on 2022-06-07 by the reprex package (v2.0.1)

Related

Error using aggregate to find length with missing values

I am trying to use the aggregate function in R to summarise a data using the length function. My data has some NA's and I have tried using 'na.rm = T' or 'na.omit' however none sees to work. I keep getting this error
'Error in FUN(X[[i]], ...) :
2 arguments passed to 'length' which requires 1'
data10 <- structure(list(Group = c(1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 2, 2,
1, 2, 2, 1, 2, 2, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2,
1), SUBJECT = c(1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10, 10,
11, 12, 14, 14, 15, 16, 16, 17, 18, 19, 19, 20, 21, 21, 22, 23,
23, 24, 25), test = c(1, 2, 1, 1, 2, 2, 1, 2, 2, 1, 1, 2, 2,
1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 2, 1
), trial = c(1, 3, 5, 7, 1, 3, 5, 7, 1, 3, 5, 7, 1, 3, 5, 7,
1, 3, 5, 7, 1, 3, 5, 7, 1, 3, 5, 7, 1, 3, 5, 7, 1, 3), Condition = c(1,
2, 3, 1, 3, 1, 2, 3, 2, 3, 1, 2, 1, 2, 3, 1, 3, 1, 2, 3, 2, 3,
1, 2, 1, 2, 3, 1, 3, 1, 2, 3, 2, 3), Sac2 = c(1, 1, 1, NA, 2,
1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 1,
1, 1, 1, 1, 2, 2, 1, 1), Sac = c(1, 1, 1, NA, 3, 1, 1, 1, 1, 3,
1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 1, 1, 1, 7, 1, 1, 1, 1, 1, 1, 3,
3, 1, 1), Saccade...8 = c(1, 1, 1, NA, 2, 1, 1, 1, 1, 2, 1, 1,
1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 2, 1,
1), T_APPEAR = c(9.236, 17.85, 28.942, 63.724, 9.463, 22.963,
52.068, 57.021, 15.344, 19.783, 37.825, 46.17, 4.339, 21.241,
29.179, 31.823, 12.164, 22.84, 23.954, 73.663, 27.269, 22.131,
30.361, 62.674, 6.928, 16.413, 47.555, 48.893, 7.291, 15.796,
31.788, 54.946, 10.117, 28.83)), row.names = c(NA, -34L), class = c("tbl_df",
"tbl", "data.frame"))
data14 = aggregate(data10,
by = list(data10$SUBJECT,data10$Condition, data10$Group, data10$test),
FUN = length(), na.rm=TRUE)

Density plot of a vector shows tails before and after its minimum and maximum

I have the following vector:
v<-c(1, 1, 8, 3, 1, 9, 4, 21, 13, 13, 1, 1, 3, 10, 1, 13, 22, 1,
1, 4, 2, 1, 13, 1, 5, 1, 2, 1, 1, 2, 12, 10, 26, 15, 2, 9, 6,
5, 1, 3, 18, 2, 10, 2, 8, 9, 4, 1, 11, 4, 2, 12, 3, 14, 2, 1,
27, 3, 6, 2, 1, 1, 3, 16, 3, 36, 13, 9, 11, 10, 24, 2, 27, 4,
4, 2, 9, 1, 3, 13, 3, 1, 8, 5, 5, 15, 1, 1, 3, 1, 4, 14, 8, 1,
1, 2, 20, 1, 9, 3, 1, 2, 5, 14, 5, 11, 1, 3, 2, 9, 10, 21, 9,
1, 20, 5, 11, 23, 2, 1, 1, 2, 1, 7, 2, 9, 1, 19, 9, 9, 2, 15,
17, 8, 11, 17, 2, 14, 2, 8, 13, 1, 2, 9, 15, 25, 3, 8, 32, 4,
11, 1, 1, 2)
I would like to estimate its density in R through the command density. With few lines of code:
d<-density(v)
df<-data.frame(x=d$x,y=d$y,stringsAsFactors = FALSE)
plot(df)
I obtained the following picture:
But the resulting plot doesn't add up, because max(v) is 36 and min(v) is 1 while the graph shows tails before and after 0 and 40.

Bootstrapping multiple regression error: number of items to replace is not a multiple of replacement length

I want to bootstrap my dataset for multiple regression. Unfortunately I get this error message:
"number of items to replace is not a multiple of replacement length"
I suspect that the factors in my regression formula may be problematic.
What could I do to solve my problem?
My code is as following (I read Andy FieldĀ“s Discovering Statistics using R):
BootReg <- function(data, indices, formula) {
d <- data[indices,]
fit <- lm(formula, data=d)
return(coef(fit))
}
bootResults <-boot(statistic = BootReg, formula = TICS_Skala1 ~HSPhoch + HSPhoch*extra.c
+ psy + sex + age.c, data = mod.reg.data, R = 2000)
psy (psychiatric disease), sex and HSPhoch (high sensory-processing sensitivity) are factors. TICS_Skala1, extra.c, age.c are continuos variables.
my sample data:
> dput(head(mod.reg.data, 20))
structure(list(neo_01 = c(3, 4, 3, 0, 4, 4, 3, 2, 3, 1, 4, 2,
3, 3, 1, 2, 3, 4, 0, 2), neo_03 = c(1, 1, 1, 3, 1, 2, 0, 0, 0,
0, 0, 0, 1, 3, 1, 1, 1, 1, 3, 1), neo_04 = c(2, 4, 3, 0, 4, 3,
4, 3, 2, 3, 3, 3, 3, 4, 2, 4, 3, 4, 3, 3), neo_08 = c(3, 0, 1,
2, 3, 3, 4, 3, 2, 1, 2, 4, 0, 3, 1, 1, 3, 1, 3, 1), neo_12 = c(3,
1, 1, 2, 2, 2, 4, 1, 1, 2, 1, 4, 1, 3, 1, 1, 3, 2, 3, 2), neo_13 = c(3,
2, 2, 4, 3, 3, 3, 2, 2, 1, 2, 3, 0, 3, 1, 0, 2, 3, 0, 2), neo_16 = c(3,
1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 3,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L, 5L, 6L, 6L, 6L, 5L, 6L, 5L, 6L, 6L, 4L, 6L, 5L, 5L, 6L, 6L,
5L, 5L, 6L), .Label = c("kein", "Haupt", "mittlereR", "Fachabi",
"Abi", "Studium"), class = "factor"), job = structure(c(6L, 2L,
2L, 2L, 2L, 6L, 2L, 6L, 5L, 2L, 2L, 1L, 6L, 2L, 2L, 2L, 6L, 2L,
2L, 6L), .Label = c("hausl", "Student", "Azubi", "Suchend", "Rente",
"berufstaetig"), class = "factor"), age = c(23, 24, 21, 70, 25,
29, 22, 25, 57, 24, 25, 30, 31, 20, 28, 27, 26, 21, 24, 53),
VPN = 1:20, consent = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label =
c("ja",
"nein"), class = "factor"), psy = c(0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0), HSPS = c(86, 75,
69, 102, 85, 82, 97, 59, 100, 68, 80, 106, 68, 73, 105, 79,
91, 63, 119, 59), neuro = c(16, 3, 4, 10, 10, 11, 12, 5,
5, 5, 5, 16, 5, 18, 4, 3, 8, 5, 19, 7), extra = c(15, 17,
19, 7, 19, 17, 18, 17, 16, 10, 17, 14, 15, 19, 11, 13, 16,
18, 9, 13), TICS_Skala1 = c(23, 1, 22, 11, 14, 16, 22, 25,
2, 11, 1, 29, 9, 20, 10, 19, 16, 9, 18, 16), TICS_Skala2 = c(14,
12, 11, 9, 11, 10, 4, 10, 5, 8, 5, 24, 13, 5, 6, 6, 14, 2,
1, 13), TICS_Skala3 = c(21, 6, 10, 5, 12, 14, 11, 20, 3,
11, 4, 27, 20, 13, 7, 13, 20, 11, 11, 18), TICS_Skala4 = c(13,
14, 13, 2, 16, 23, 10, 9, 3, 13, 15, 18, 14, 11, 13, 10,
7, 9, 17, 6), TICS_Skala5 = c(12, 2, 6, 5, 3, 5, 8, 3, 4,
6, 0, 18, 3, 7, 1, 6, 6, 1, 13, 3), TICS_Skala6 = c(10, 2,
3, 4, 4, 6, 3, 0, 0, 5, 2, 15, 10, 5, 2, 1, 5, 2, 8, 3),
TICS_Skala7 = c(15, 5, 9, 13, 4, 8, 4, 9, 1, 6, 2, 11, 2,
12, 3, 2, 1, 3, 2, 7), TICS_Skala8 = c(8, 10, 3, 0, 11, 7,
2, 1, 2, 2, 7, 20, 7, 2, 2, 2, 1, 1, 2, 3), TICS_Skala9 = c(12,
3, 4, 8, 8, 6, 9, 5, 2, 6, 5, 11, 3, 11, 1, 5, 9, 3, 7, 5
), TICS_Skala10 = c(32, 5, 18, 16, 19, 18, 21, 16, 5, 17,
7, 39, 12, 24, 3, 15, 20, 6, 25, 14), neuro.c = c(6.08921933085502,
-6.91078066914498, -5.91078066914498, 0.089219330855018,
0.089219330855018, 1.08921933085502, 2.08921933085502,
-4.91078066914498,
-4.91078066914498, -4.91078066914498, -4.91078066914498,
6.08921933085502, -4.91078066914498, 8.08921933085502,
-5.91078066914498,
-6.91078066914498, -1.91078066914498, -4.91078066914498,
9.08921933085502, -2.91078066914498), extra.c = c(5.21003717472119,
7.21003717472119, 9.21003717472119, -2.78996282527881,
9.21003717472119,
7.21003717472119, 8.21003717472119, 7.21003717472119,
6.21003717472119,
0.21003717472119, 7.21003717472119, 4.21003717472119,
5.21003717472119,
9.21003717472119, 1.21003717472119, 3.21003717472119,
6.21003717472119,
8.21003717472119, -0.78996282527881, 3.21003717472119), age.c =
c(-15.4460966542751,
-14.4460966542751, -17.4460966542751, 31.5539033457249,
-13.4460966542751,
-9.4460966542751, -16.4460966542751, -13.4460966542751,
18.5539033457249,
-14.4460966542751, -13.4460966542751, -8.4460966542751,
-7.4460966542751,
-18.4460966542751, -10.4460966542751, -11.4460966542751,
-12.4460966542751, -17.4460966542751, -14.4460966542751,
14.5539033457249), HSP.c = c(-1.92936802973978, -12.9293680297398,
-18.9293680297398, 14.0706319702602, -2.92936802973978,
-5.92936802973978,
9.07063197026022, -28.9293680297398, 12.0706319702602,
-19.9293680297398,
-7.92936802973978, 18.0706319702602, -19.9293680297398,
-14.9293680297398,
17.0706319702602, -8.92936802973978, 3.07063197026022,
-24.9293680297398,
31.0706319702602, -28.9293680297398), HSPhoch = c(1, 0, 0,
1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0)), row.names =
c(NA, 20L), class = "data.frame")

Select Input in ggplot Shiny dashboard - Error: object not found

I am trying to create ggplot output using R Markdown Shiny Document. I need it to plot data based on the selection in a dropdown menu. My code:
df<- data.frame(df,out)
renderRpivotTable({
rpivotTable(data = df, rows = c("organisationunitname","X2"), cols = "X1", vals = "value",
aggregatorName = "List Unique Values",inclusions = list(organisationunitname=list("All OUs")),
rendererName = "Lab Table", width = "100%", height = "500px") })
orgunit <- c("Cy3L", "Yieu", "j9ao", "H3LY", "U3nd",
"qU1l", "jXVh", "dXHb", "tCq8", "Blee", "5jra", "qO2V", "Qa9J",
"2XIy", "MJpY", "tNKa", "UorU", "7pZt", "Mxsz", "WCkd", "BiDp",
"Zw8w", "0J7c", "9YtI", "TAkB", "py3Q", "RdQt", "Yhv1", "PB0X",
"H3L4", "INY7", "DpTW", "3zXP", "OqpO", "tiZU", "5wnz")
inputPanel(selectInput("OU", label = "Select OU:", choices = orgunit, selected = "All OUs"))
renderPlot({
df1=reactive({return(df[organisationunitname %in% as.character(input$OU)])})
ggplot(data = df1(),aes(x=X1,y=value))+geom_bar(stat = "identity")+facet_grid(X2~.)
})
It gives me this error: object 'organisationunitname' not found
Error Message
My data:
structure(list(country = c("Cy3L", "Yieu", "j9ao", "H3LY", "U3nd",
"qU1l", "jXVh", "dXHb", "tCq8", "Blee", "5jra", "qO2V", "Qa9J",
"2XIy", "MJpY", "tNKa", "UorU", "7pZt", "Mxsz", "WCkd", "BiDp",
"Zw8w", "0J7c", "9YtI", "TAkB", "py3Q", "RdQt", "Yhv1", "PB0X",
"H3L4", "INY7", "DpTW", "3zXP", "OqpO", "tiZU", "5wnz"), cd4_perform_result = structure(c(24L,
6L, 7L, 1L, 1L, 1L, 5L, 3L, 2L, 1L, 10L, 1L, 2L, 8L, 1L, 2L,
17L, 1L, 1L, 23L, 12L, 1L, 14L, 11L, 18L, 1L, 21L, 16L, 1L, 22L,
19L, 4L, 1L, 15L, 20L, 9L), .Label = c("0", "1", "11", "125",
"130", "14", "15", "194", "24", "261", "27", "31", "3442", "370",
"4", "5", "51", "567", "577", "73", "76", "79", "796", "9", "end"
), class = "factor"), cd4_participate_result = c(1, 8, 8, 1,
1, 1, 5, 3, 2, 1, 7, 1, 2, 9, 1, 2, 17, 1, 1, 18, 12, 1, 4, 15,
14, 1, 20, 16, 1, 21, 10, 6, 1, 19, 13, 3), cd4_pass_result = c(1,
4, 19, 1, 1, 1, 5, 3, 2, 1, 21, 1, 2, 20, 1, 2, 13, 1, 1, 14,
6, 1, 11, 12, 10, 1, 18, 2, 1, 16, 7, 17, 1, 15, 9, 3), eid_perform_result = c(2,
1, 7, 1, 1, 1, 1, 9, 1, 1, 8, 1, 2, 3, 5, 2, 5, 1, 1, 10, 5,
1, 4, 2, 11, 1, 5, 1, 1, 5, 9, 2, 1, 1, 9, 5), eid_participate_result = c(2,
1, 5, 1, 1, 1, 1, 8, 1, 1, 7, 1, 2, 10, 5, 2, 5, 1, 1, 4, 2,
1, 10, 2, 9, 1, 5, 1, 1, 5, 7, 2, 1, 1, 6, 5), eid_pass_result = c(2,
1, 5, 1, 1, 1, 1, 7, 1, 1, 6, 1, 2, 10, 1, 2, 5, 1, 1, 4, 2,
1, 9, 2, 8, 1, 5, 1, 1, 5, 6, 2, 1, 1, 5, 5), vl_perform_result = c(2,
1, 3, 1, 1, 1, 1, 9, 1, 1, 10, 1, 2, 11, 5, 2, 5, 1, 1, 6, 5,
1, 8, 7, 6, 1, 12, 1, 1, 5, 9, 2, 1, 1, 8, 5), vl_participate_result = c(2,
1, 7, 1, 1, 1, 1, 7, 1, 1, 8, 1, 2, 8, 4, 2, 4, 1, 1, 5, 2, 1,
4, 6, 3, 1, 9, 1, 1, 4, 7, 2, 1, 1, 6, 1), vl_pass_result = c(2,
1, 7, 1, 1, 1, 1, 7, 1, 1, 9, 1, 2, 8, 1, 2, 5, 1, 1, 4, 2, 1,
2, 6, 3, 1, 11, 1, 1, 5, 7, 2, 1, 1, 5, 1), hiv_perform_result = c(19,
29, 14, 1, 1, 1, 26, 21, 10, 1, 6, 11, 9, 7, 20, 27, 8, 15, 1,
28, 12, 1, 25, 18, 24, 1, 22, 5, 1, 23, 17, 16, 1, 2, 3, 4),
hiv_participate_result = c(19, 28, 14, 1, 1, 1, 22, 20, 4,
1, 16, 9, 10, 3, 12, 27, 5, 1, 1, 21, 6, 1, 24, 18, 13, 1,
25, 8, 1, 23, 15, 17, 1, 2, 26, 7), hiv_pass_result = c(20,
28, 14, 1, 1, 1, 18, 22, 7, 1, 17, 27, 11, 2, 24, 26, 10,
1, 1, 15, 4, 1, 21, 19, 12, 1, 23, 8, 1, 16, 13, 9, 1, 3,
25, 6), tbafb_perform_result = c(9, 1, 8, 1, 1, 1, 1, 7,
1, 1, 6, 1, 21, 5, 1, 2, 12, 1, 1, 15, 13, 1, 17, 11, 20,
1, 10, 1, 1, 14, 16, 4, 1, 18, 3, 1), tbafb_participate_result = c(1,
1, 18, 1, 1, 1, 1, 5, 1, 1, 12, 1, 19, 11, 1, 2, 6, 1, 1,
13, 7, 1, 10, 9, 14, 1, 8, 1, 1, 16, 15, 4, 1, 18, 3, 1),
tbafb_pass_result = c(1, 1, 19, 1, 1, 1, 1, 6, 1, 1, 13,
1, 20, 11, 1, 2, 4, 1, 1, 15, 5, 1, 7, 10, 12, 1, 8, 1, 1,
16, 9, 3, 1, 14, 18, 1), tbculture_perform_result = c(3,
1, 2, 1, 1, 1, 1, 1, 1, 1, 6, 1, 3, 8, 1, 2, 2, 1, 1, 7,
3, 1, 5, 4, 7, 1, 5, 1, 1, 3, 6, 6, 1, 3, 3, 1), tbculture_participate_result = c(1,
1, 2, 1, 1, 1, 1, 1, 1, 1, 6, 1, 4, 9, 1, 2, 2, 1, 1, 8,
2, 1, 7, 5, 7, 1, 1, 1, 1, 4, 4, 6, 1, 4, 4, 1), tbculture_pass_result = c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 4, 8, 1, 2, 2, 1, 1, 9,
2, 1, 7, 5, 6, 1, 1, 1, 1, 4, 4, 7, 1, 4, 4, 1), tbxpert_perform_result = c(1,
1, 4, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 17, 1, 8, 3, 1, 1, 5,
9, 1, 16, 7, 13, 1, 4, 1, 1, 12, 11, 1, 1, 6, 14, 10), tbxpert_participate_result = c(1,
1, 5, 1, 1, 1, 1, 1, 1, 1, 16, 1, 1, 4, 1, 12, 3, 1, 1, 2,
7, 1, 17, 9, 11, 1, 1, 1, 1, 14, 10, 1, 1, 6, 8, 13), tbxpert_pass_result = c(1,
1, 2, 1, 1, 1, 1, 1, 1, 1, 13, 1, 1, 4, 1, 9, 3, 1, 1, 15,
6, 1, 14, 8, 8, 1, 1, 1, 1, 12, 6, 1, 1, 5, 7, 10)), .Names = c("organisationunitname",
"cd4_perform_result", "cd4_participate_result", "cd4_pass_result",
"eid_perform_result", "eid_participate_result", "eid_pass_result",
"vl_perform_result", "vl_participate_result", "vl_pass_result",
"hiv_perform_result", "hiv_participate_result", "hiv_pass_result",
"tbafb_perform_result", "tbafb_participate_result", "tbafb_pass_result",
"tbculture_perform_result", "tbculture_participate_result", "tbculture_pass_result",
"tbxpert_perform_result", "tbxpert_participate_result", "tbxpert_pass_result"
), row.names = c(NA, 36L), class = "data.frame")
I am not sure why it's not reading the "organisationunitname" column. Please help.
I think your error is this line:
df1=reactive({return(df[organisationunitname %in% as.character(input$OU)])})
Change it to:
df1=df[df$organisationunitname %in% as.character(input$OU),])
You also have the incorrect number of dimensions and reactive is not required here because the expression is already in a reactive function: renderPlot.

Joining two weighted Graphs in R and keeping weight as sum

I have the same question as this how to merge two weighted graph and sum weigths.
But here ist my R code for better understanding:
g1 <- graph.full(10)
V(g1)$name <- letters[1:vcount(g1)]
E(g1)$weight <- 1
g3 <- graph.full(5)
V(g3)$name <- c("a", "b", "x", "y", "z")
E(g3)$weight <- 1
graph.union.by.name(g1, g3)
The weights in merged graph should be a 2 on same edges in g1 and g3 (a - b)
And the dput of graphs is:
> dput(g1)
structure(list(10, FALSE, c(1, 2, 3, 4, 5, 6, 7, 8, 9, 2, 3,
4, 5, 6, 7, 8, 9, 3, 4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9, 5, 6,
7, 8, 9, 6, 7, 8, 9, 7, 8, 9, 8, 9, 9), c(0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 8), c(0, 1, 9,
2, 10, 17, 3, 11, 18, 24, 4, 12, 19, 25, 30, 5, 13, 20, 26, 31,
35, 6, 14, 21, 27, 32, 36, 39, 7, 15, 22, 28, 33, 37, 40, 42,
8, 16, 23, 29, 34, 38, 41, 43, 44), c(0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44), c(0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45),
c(0, 9, 17, 24, 30, 35, 39, 42, 44, 45, 45), list(c(1, 0,
1), structure(list(name = "Full graph", loops = FALSE), .Names = c("name",
"loops")), structure(list(name = c("a", "b", "c", "d", "e",
"f", "g", "h", "i", "j")), .Names = "name"), structure(list(
weight = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), .Names = "weight"))), class = "igraph")
> dput(g2)
structure(list(10, FALSE, c(1, 2, 3, 4, 5, 6, 7, 8, 9, 2, 3,
4, 5, 6, 7, 8, 9, 3, 4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9, 5, 6,
7, 8, 9, 6, 7, 8, 9, 7, 8, 9, 8, 9, 9), c(0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 8), c(0, 1, 9,
2, 10, 17, 3, 11, 18, 24, 4, 12, 19, 25, 30, 5, 13, 20, 26, 31,
35, 6, 14, 21, 27, 32, 36, 39, 7, 15, 22, 28, 33, 37, 40, 42,
8, 16, 23, 29, 34, 38, 41, 43, 44), c(0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44), c(0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45),
c(0, 9, 17, 24, 30, 35, 39, 42, 44, 45, 45), list(c(1, 0,
1), structure(list(name = "Full graph", loops = FALSE), .Names = c("name",
"loops")), structure(list(name = c("a", "b", "c", "d", "e",
"f", "g", "h", "i", "j")), .Names = "name"), structure(list(
weight = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), .Names = "weight"))), class = "igraph")
Is it possible with igraph or do i need some workaround?
This will be supported in the next version, until then here is a workaround:
mymerge <- function(g1, g2) {
e1 <- get.data.frame(g1, what="edges")
e2 <- get.data.frame(g2, what="edges")
e <- merge(e1, e2, by=c("from", "to"), all=TRUE)
newe <- data.frame(e[,c("from", "to"), drop=FALSE],
weight=rowSums(e[, c("weight.x", "weight.y")], na.rm=TRUE))
graph.data.frame(newe, directed=is.directed(g1))
}
mymerge(g1, g3)
# IGRAPH UNW- 13 54 --
# + attr: name (v/c), weight (e/n)
mymerge(g1, g3)["a", "b"]
# [1] 2

Resources