Why the energy distance function give me null result? - r

As mention here https://cran.r-project.org/web/packages/energy/energy.pdf
the e.dist returns Returns the E-distances (energy statistics) between clusters.
And as inputs it accepts data matrix of pooled sample or Euclidean distances.
I want to compute the e-distance between 100 observations of my data set.
Look what I did:
> disteuc<-dist(DATABASE,method = "euclidean")
> edist(disteuc,sizes=100)
dist(0)
Why I get null value ??
This is the first 100 rows of my data set:
> dput(DATABASE[1:100,])
structure(list(TYPE_PEAU = c(2L, 2L, 3L, 2L, 2L, 2L, 2L, 4L,
3L, 2L, 2L, 2L, 2L, 1L, 4L, 2L, 2L, 2L, 4L, 2L, 3L, 3L, 2L, 2L,
2L, 2L, 2L, 4L, 3L, 4L, 2L, 2L, 2L, 2L, 4L, 2L, 1L, 2L, 2L, 2L,
2L, 4L, 3L, 2L, 4L, 2L, 1L, 2L, 2L, 2L, 3L, 1L, 2L, 4L, 2L, 2L,
3L, 4L, 2L, 2L, 2L, 2L, 2L, 4L, 2L, 2L, 2L, 4L, 2L, 4L, 2L, 4L,
3L, 3L, 2L, 2L, 2L, 2L, 4L, 4L, 2L, 2L, 4L, 2L, 2L, 2L, 4L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 4L, 2L, 2L, 2L, 2L, 2L), SENSIBILITE = c(3L,
2L, 3L, 3L, 3L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 3L, 3L, 3L,
1L, 3L, 3L, 1L, 3L, 2L, 2L, 3L, 3L, 3L, 1L, 3L, 3L, 2L, 1L, 3L,
1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 3L, 2L, 3L, 3L, 2L, 2L, 1L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 2L, 3L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 3L, 3L, 2L, 3L, 2L, 3L, 2L,
3L, 3L, 3L, 3L, 3L, 2L, 1L, 1L, 2L, 3L, 3L, 2L, 3L, 1L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 12L, 5L, 6L, 16L, 3L, 14L, 4L, 4L, 6L, 9L, 13L, 3L,
5L, 12L, 4L, 3L, 6L, 3L, 6L, 6L, 3L, 6L, 4L, 3L, 3L, 7L, 3L,
12L, 12L, 10L, 3L, 6L, 7L, 14L, 3L, 18L, 7L, 5L, 4L, 7L, 17L,
6L, 6L, 3L, 6L, 17L, 10L, 12L, 5L, 13L, 15L, 6L, 3L, 11L, 6L,
7L, 7L, 16L, 3L, 3L, 3L, 3L, 6L, 3L, 4L, 3L, 10L, 3L, 4L, 6L,
5L, 14L, 3L), NOMBRE_CADEAU = c(2L, 1L, 1L, 1L, 2L, 2L, 1L, 2L,
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 3L, 1L, 1L,
2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L,
3L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 2L,
1L, 1L, 1L, 1L, 2L, 1L, 3L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L,
2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L)), .Names = c("TYPE_PEAU",
"SENSIBILITE", "IMPERFECTIONS", "BRILLANCE", "GRAIN_PEAU", "RIDES_VISAGE",
"ALLERGIES", "MAINS", "PEAU_CORPS", "INTERET_ALIM_NATURELLE",
"INTERET_ORIGINE_GEO", "INTERET_VACANCES", "INTERET_ENVIRONNEMENT",
"INTERET_COMPOSITION", "AGE_INTERVAL", "ATTENTE_BEAUTE_1", "ATTENTE_BEAUTE_2",
"MILIEU_VIE", "PROFIL_SELECTIONNE", "NOMBRE_ACHAT", "NOMBRE_CADEAU"
), row.names = c(NA, 100L), class = "data.frame")
>

You are only specifying a cluster size, if you have 100 data and they are all in the same cluster there are no distances to other clusters.
> edist(disteuc,sizes=100)
dist(0)
> edist(disteuc,sizes=c(10, 90))
1
2 42.51959
> edist(disteuc,sizes=c(10, 40, 50))
1 2
2 44.32714
3 39.80484 35.26888

Related

getting Error in svd(X) : infinite or missing values in 'x' when using summary of regression model

I am getting an error
Error in svd(X) : infinite or missing values in 'x'
while doing summary of ordinal regression model. This is my code ..
library(MASS)
a <- dget('dput.txt')
lep <- polr(bmicat2 ~ Leptin, data = a,Hess = TRUE)
summary(lep)
Error in svd(X) : infinite or missing values in 'x'
sample data is given to replicate the error. Can someone please help.
structure(list(bmicat2 = structure(c(1L, 3L, 2L, 1L, 1L, 1L,
1L, 1L, 3L, 3L, 3L, 3L, 3L, 1L, 2L, 3L, 2L, 3L, 3L, 3L, 3L, 1L,
3L, 3L, 1L, 1L, 2L, 1L, 2L, 2L, 3L, 1L, 1L, 1L, 1L, 1L, 2L, 3L,
2L, 1L, 1L, 3L, 3L, 2L, 1L, 1L, 1L, 2L, 1L, 3L, 1L, 3L, 1L, 1L,
1L, 2L, 1L, 3L, 2L, 1L, 1L, 2L, 1L, 3L, 1L, 1L, 1L, 3L, 1L, 3L,
3L, 3L, 2L, 3L, 1L, 3L, 3L, 3L, 2L, 2L, 1L, 2L, 2L, 1L, 3L, 1L,
1L, 1L, 2L, 2L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 2L, 3L, 1L, 2L, 1L,
2L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 3L, 1L, 1L, 2L, 2L, 2L, 1L, 3L,
3L, 3L, 3L, 3L, 2L, 3L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L,
1L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 3L, 1L, 1L, 1L, 1L, 2L, 3L, 2L,
2L, 1L, 1L, 1L, 3L, 2L, 1L, 3L, 2L, 2L, 2L, 2L, 1L, 3L, 1L, 3L,
1L, 1L, 1L, 3L, 1L, 1L,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overweight", "Obesity"), class = "factor"),
Leptin = c(47710.88, 200022.04, 161067.35, 55561.76, 100728.06,
69783.61, 54981.01, 58801.34, 128313.05, 157378.46, 292366.57,
121608.04, 206046.88, 54981.01, 154969.33, 516791.75, 104766.73,
440134.48, 286576.47, 343513.87, 40020.2, 30077.63, 359266.48,
290381.41, 23005.7, 48080.73, 134741.37, 114631.03, 49644.25,
139956.69, 138242.54, 19862, 64541.08, 57119.32, 115382.48,
7238.99, 154969.33, 82321.93, 85406.54, 19170.47, 57208.08,
277488.74, 290791.3, 206703.97, 25333.82, 20134.62, 32823.3,
231036.03, 111986.18, 352190.59, 128041.35, 185025.96, 63451.72,
143404.56, 71163.46, 252067.35, 46223.39, 185077.75, 172339.07,
41381.36, 91498.49, 233969.82, 24245.94, 248133.29, 145890.48,
196431.01, 146690.84, 218617.65, 151333.68, 245695.08, 336242.88,
266936.45, 64105.63, 301181.31, 150192.02, 253863.48, 314169.03,
406059.04, 68228.37, 335171.04, 37547.56, 123713.8, 75034,
45708.91, 67449.43, 15920.57, 38444.37, 19170.47, 174853.97,
236689.18, 22879.68, 34599.46, 57562.83, 177486.58, 244481.84,
122637.48, 58094.2, 82921.65, 382788.21, 119733.17, 64192.75,
8787.33, 17146.98, 21986.45, 13077.71, 18320.19, 119777.74,
61615.67, 5708.97, 24307.05, 244118.62, 10780.13, 12158.23,
80265.64, 70215.06, 122189.66, 48219.23, 156702.5, 128313.05,
115072.95, 152956.29, 107776.73, 108914.21, 85835.09, 13608.28,
24853.42, 58359.56, 29967.69, 168944.14, 22435.55, 67709.18,
17444.89, 51058.87, 21072.27, 34702.75, 9711.01, 43870.71,
113571.74, 26863.91, 294914.16, 15920.57, 23381.51, 309409.6,
19587.14, 99905.3, 79494.37, 90768.21, 131129.25, 411527.63,
132269.4, 83735.58, 92014.19, 57030.54, 62578.38, 131676.19,
238711.8, 48080.73, 429691.15, 88750.76, 32770.45, 163022.26,
98045.93, 8421.27, 113659.95, 27210.74, 421265.4, 225005.8,
39431.91, 18748.27, 224660.83, 13695.33, 11186.36, 42727.62,
863581.67, 18031.36, 250895.16, 326547.74, 69351.93, 34288.82,
64932.66, 23381.51, 392858.01, 32399.47, 176370.64, 31651.9,
17592.65, 93304.24, 71938.68, 297130.98, 58624.7, 311565.88,
143685.29, 204518.07, 28689.43, 612308, 119688.61, 116888.21,
60738.48, 274462.8, 307122.48, 202886.86, 119777.74, 194409.2,
259555.37, 479766.12, 97527.66, 177029.67, 17146.98, 70560.06,
50922.4, 213003.8, 142470.09, 26747.8, 235563.59, 49460.99,
185181.36, 27210.74, 156220.34, 284284.42, 254982.61, 67059.61,
46736.22, 97657.21, 399497.2, 13433.03, 385197.12, 143685.29,
46503.31, 333111.93, 228589.14, 40117.95, 86563.73, 459114.82,
334559.84, 39824.45, 90295.84, 19309.96, 25333.82, 15604.37,
548683.37, 13954.22, 63974.92, 283344.56, 47061.73, 14794.69,
56852.91, 63320.83, 21335.74, 18176.13, 44060.31, 31436.88,
779337.47, 177842.32, 15683.81, 1804.18, 18031.36, 150572.24,
69956.22, 353788.11, 42823.25, 25927.76, 23131.34, 351871.83,
130355.47, 48034.54, 9711.01, 296020.99, 77994.24, 106641.08,
NA, 68876.79, 64323.41, 37947.12, 166071.05, 239189.29, 376318.03,
132041.15, 48818.15, 209454.17, 25572.25, 232324.09, 142750.23,
34185.02, 21204.24, 6040.1, 5708.97, 252190.95, 129219.75,
50922.4, 97786.76, 117464.95, 84978.04, 15122, 6356.95, NA,
299220.74, 28801.64, 535105.27, 421922.32, 9486.52, 159801.65,
139492.77, 40410.71, 28011.68, 67189.58, 10780.13, 173997.11,
15283.91, 192081.41, 169590.94, 29747.24, 57961.45, 55606.38,
351712.55, 157233.52, 117553.73, 201046.58, NA, 204409.11,
468179.87, 201640.99, 374968.45, 330911.94, 153817.84, 45098.7,
83050.16, NA, 20134.62, 20606.55, 328498.24, 22115.29, 40313.21,
196751.22, 6356.95, 8042.41, 252005.56, 124522.47, 9711.01,
168745.34, 110580.08, 78722.96, 104897.35, 43728.34, 20270.11,
339321.01, 170488.25, 55829.38, 173292.85, 29967.69, 5708.97,
30132.53, 12715.53, 180648.71, 146219.86, 33716.28, 85835.09,
110404.53, 327146.88, 259303.38, 164396.3, 206156.31, 21204.24,
105158.65, 152478.41, 327897.07, 29025.44, 36237.65, 426358.52,
265525.58, 52464.02, 287117.75, 658217.42, 67709.18, 107645.6,
46829.29, 186790.78, 68920, 363915.23, 269385.74, 126324.01,
146361.1, 153243.28, 101161.4, 318839.47, 132223.74, 96190,
143966.19, 162141.4, 63495.34, 35371.14, 261070.81, 197071.7,
240146.08, 73100.38, 63713.39, 248622.82, 92616.07, 163120.25,
95026.25, 266807.98, 153434.72, 145937.52, 127950.82, 376487.04,
81208.15, 311998.55, 41767.47, 59595.08, 13256.19, 35011.88,
99083.27, 47571.98, 174450.51, 8296.48, 35524.66, 68747.15,
214064.04, 127272.35, 70603.17, 99256.27, 19862, 145373.38,
184560.15, 57828.63, 115426.71)), row.names = c(NA, -425L
), class = c("tbl_df", "tbl", "data.frame"))
It is an issue of lep$Hessian having NA values. If you do this:
lep <- polr(bmicat2 ~ Leptin, data = a,Hess = TRUE)
lep$Hessian[1,1]<-0
lep$Hessian[1,2]<-0
lep$Hessian[1,3]<-0
lep$Hessian[2,1]<-0
lep$Hessian[3,1]<-0
summary(lep)
You do not have any problems but the output from lep and summary(lep) are pretty much the same, I think. Is it the imputation of 0 to missing values in the Hessian that disturbing?

How to randomly change 50% of a column observations based on another column condition?

I'm analyzing a survey and I need to do an interaction.plot() between variable disclosure_1 and TYPE_1 to see how they affect a third variable ADTRUST.
The survey randomly showed a different scenario to each participant. DISCLOSURE_1 is the code to indicate the type of disclosure that was shown to a respondent (B = Before, D = During, A = After, N = None).
TYPE_1 indicates the terminology used (DF = Deepfake, SM = Sythetic Media).
When creating the survey I dumbly only used DF for N because I thought there was no need to create an SM scenario if there was no disclosure shown (so no difference in terminology used). It still makes no sense logically, but when plotting the interaction plot the variable N does not appear. And since the study wants to analyze:
how disclosure impacts ADTRUST
how disclosure positioning impacts ADTRUST
how different terminology used in disclosure impact ADTRUST
I need to randomly substitute 50% of the observations with SM instead of DF under TYPE_1 but ONLY if the column DISCLOSURE_1 is == N.
I have no clue how to do that. Could somebody please help?
NOTE!!!! The structure is part of a bigger dataset. the dput was only done only for [25:26], so keep in mind I need to be able to precisely select the columns in the code.
Thank youu
structure(list(DISCLOSURE_1 = structure(c(4L, 3L, 1L, 3L, 1L,
1L, 4L, 3L, 4L, 3L, 4L, 1L, 3L, 3L, 4L, 1L, 3L, 3L, 1L, 3L, 3L,
4L, 2L, 1L, 1L, 4L, 2L, 3L, 3L, 1L, 4L, 1L, 1L, 4L, 4L, 1L, 3L,
2L, 2L, 1L, 4L, 1L, 1L, 1L, 4L, 3L, 4L, 3L, 2L, 3L, 1L, 1L, 3L,
1L, 1L, 2L, 1L, 2L, 2L, 2L, 3L, 2L, 1L, 3L, 3L, 3L, 3L, 2L, 2L,
3L, 3L, 2L, 1L, 2L, 3L, 1L, 2L, 2L, 1L, 1L, 1L, 3L, 2L, 2L, 3L,
3L, 2L, 3L, 3L, 2L, 1L, 3L, 1L, 1L, 4L, 4L, 1L, 2L, 4L, 3L, 1L,
1L, 1L, 3L, 2L, 3L, 1L, 2L, 2L, 3L, 4L, 2L, 4L, 2L, 3L, 3L, 2L,
4L, 4L, 3L, 4L, 1L, 1L, 3L, 3L, 1L, 3L, 2L, 3L, 3L, 1L, 2L, 1L,
4L, 1L, 2L, 3L, 3L, 1L, 4L, 2L, 3L, 2L, 1L, 1L, 2L, 2L, 1L, 4L,
2L, 4L, 1L, 4L, 2L, 1L, 1L, 1L, 3L, 2L, 3L, 2L, 4L, 3L, 1L, 3L,
1L, 1L, 3L, 2L, 3L, 2L, 4L, 3L, 3L, 1L, 1L, 3L, 2L, 2L, 1L, 1L,
3L, 3L, 4L, 2L, 2L, 3L, 3L, 1L, 2L, 1L, 2L, 3L, 2L, 3L, 3L, 3L,
3L, 4L, 3L, 2L,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L, 2L, 1L,
2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L), .Label = c("DF",
"SM"), class = "factor")), row.names = c(NA, -367L), class = c("tbl_df",
"tbl", "data.frame"))
With data as your data.frame, this will replace exactly half (rounded down) of the N's with DF with SM:
blnN <- data$DISCLOSURE_1 == "N" & data$TYPE_1 == "DF"
data$TYPE_1[sample(which(blnN), sum(blnN)/2)] <- "SM"
If the 50% requirement is approximate, you can use runif() > 0.5
library(dplyr)
table(df)
TYPE_1
DISCLOSURE_1 DF SM
A 52 51
B 52 53
D 55 51
N 53 0
mut <- df |>
mutate(TYPE_1 = ifelse(DISCLOSURE_1 == "N" &
TYPE_1 == "DF" &
runif(n()) > 0.5,
"SM",
as.character(TYPE_1)))
table(mut)
TYPE_1
DISCLOSURE_1 DF SM
A 52 51
B 52 53
D 55 51
N 27 26

How to reshape conjoint data from wide to long?

users,
I have received a data from a conjoint survey experiment. What I want to do is to reshape from wide to long format. However, this seems to be slightly complicated. I am pretty sure it is possible to do with cj_tidy (package cregg) but can't solve it myself.
In the survey, the respondents were asked to compare two organizations that vary across 7 profiles (Efficiency Opennes Inclusion Leader Gain & System). In total, respondents were presented with four comparisons. So 2 organizations and 4 comparisons (4x2). They had to choose one of the presented organization and rate them separately after choosing one.
At the moment, the profile variables are structured in this way: org1_Efficiency_conj_1, org1_Opennes_conj1 ..etc. The first part "org" indicates whether it is the first or second organization. The last part "conj", indicated the order of the conjoint/comparison, where the "conj4" is the last comparison. The CHOICE variables also follow the order of conjoint – for example,"CHOICE_conj1", "CHOICE_conj2", where =1 means the respondent chose "org1". If =2, then org2 was chosen. The RATING> variable indicates a value from 0 to 10 for each organization: RATING_conj1_org1; RATING_conj1_org2 etc..
The current wide format of the data is not suitable for conjoint analysis - what I need is to create 8 observations for each respondent (4x2=8) where the variable CHOICE would indicate which of the organizations were chosen (where =1 if yes; and =0 if no). In a similar way, the variable RATING should indicate the rating given by respondents for both of the organizations (0 to 10).
This is how I would like the data to look like:
Note please that there are also covariates such as Q1 and Q2 in the picture, they are not a part of the experiment and should remain constant for each individual observation.
Below I share 50 observations from my real data.
> dput(cjdata_wide) structure(list(ID = 1:50, org1_Effeciency_conj_1 =
> c(3L, 2L, 1L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 2L, 1L, 1L, 1L, 1L, 1L, 3L,
> 2L, 3L, 3L, 3L, 2L, 3L, 1L, 2L, 1L, 3L, 3L, 1L, 1L, 3L, 1L, 1L, 3L,
> 3L, 2L, 3L, 2L, 3L, 2L, 1L, 1L, 3L, 2L, 1L, 1L, 1L, 2L, 2L, 1L ),
> org1_Oppenes_conj_1 = c(3L, 3L, 1L, 3L, 1L, 3L, 2L, 3L, 2L, 3L, 1L,
> 1L, 1L, 2L, 3L, 2L, 2L, 1L, 3L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 1L, 3L,
> 1L, 2L, 2L, 3L, 2L, 2L, 1L, 3L, 1L, 3L, 2L, 2L, 1L, 2L, 3L, 3L, 3L,
> 3L, 3L, 2L, 3L, 1L), org1_Inclusion_conj_1 = c(2L, 1L, 1L, 2L, 2L,
> 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L), org1_Leader_conj_1 =
> c(5L, 6L, 3L, 6L, 1L, 4L, 2L, 6L, 1L, 6L, 1L, 2L, 2L, 6L, 3L, 2L, 6L,
> 3L, 5L, 6L, 3L, 1L, 4L, 3L, 5L, 5L, 2L, 1L, 4L, 1L, 3L, 4L, 2L, 3L,
> 5L, 2L, 1L, 3L, 3L, 2L, 1L, 4L, 1L,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, 3L, 1L, 2L, 2L, 3L, 1L, 2L, 1L, 3L,
> 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 977L, 2L, 3L, 3L, 1L, 1L, 3L, 2L,
> 1L, 1L, 3L, 3L, 2L, 3L, 3L, 2L, 1L, 3L, 3L, 3L, 977L, 1L, 3L, 977L,
> 977L, 1L), gender = c(1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
> 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L,
> 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
> 1L, 2L, 2L, 1L), profile_age = c(5L, 2L, 5L, 5L, 3L, 5L, 2L, 5L, 3L,
> 5L, 3L, 3L, 5L, 5L, 5L, 5L, 5L, 5L, 2L, 5L, 5L, 5L, 5L, 2L, 5L, 5L,
> 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 1L, 5L, 5L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L ), educ = c(6L, 5L, 2L, 5L, 6L, 6L, 4L, 6L,
> 3L, 5L, 4L, 5L, 6L, 4L, 4L, 6L, 6L, 6L, 3L, 6L, 5L, 6L, 5L, 5L, 3L,
> 4L, 6L, 6L, 5L, 3L, 3L, 4L, 3L, 6L, 3L, 5L, 5L, 6L, 3L, 5L, 3L, 3L,
> 3L, 3L, 4L, 5L, 5L, 4L, 2L, 3L)), class = "data.frame", row.names =
> c(NA,
> -50L))
What I have done so far is this:
library(cregg)
str(long <- cj_tidy(cjdata_wide,
profile_variables = c("All the profile variables"),
task_variables = c("CHOICE AND RATING VARIABLES HERE"),
id = ~ id))
stopifnot(nrow(long) == nrow(data)*4*2
But I'm keep getting errors. I have tried to follow the example given by the cregg package - but with no success. Any help is much appreciated! I am open to all possible ways, be it so through cregg package or tidyr for instance.
Your data not being in a standard form mades this a difficult problem. Here is a solution using the tidyr package.
The solutions involves 3 parts, dealing with the profiles, the rating and finally the rating choice.
The key to the profiles part was to pivot long and breaking up the profile names into component parts and then pivot wider for the column headings.
The rating and binary choice involved pivoting longer and then aligning the rows.
library(tidyr)
library(dplyr)
#Get the categories part correct
answer <-cjdata_wide %>% pivot_longer(cols=starts_with("org"), names_to=c("org", "Cat", "conj", "order"), values_to= "values", names_sep="_") %>% select(-c("conj"))
answer <-answer %>% select(!starts_with("RATING") & !starts_with("CHOICE"))
answer <-pivot_wider(answer, names_from = "Cat", values_from = "values")
#get the ratings column corretn
rating <-cjdata_wide %>% select(starts_with("RATING") )
rating <- rating%>% pivot_longer(cols=everything(), names_to=c("Rating", "conj", "order"), values_to= "Choice_Rating", names_sep="_") %>% select(-c("conj"))
answer$Choice_Rating <- rating$Choice_Rating
#Get the choice correct
choice <-cjdata_wide %>% select(starts_with("CHOICE") )
choiceRate <- choice%>% pivot_longer(cols=everything(), names_to=c("Choice", "conj"), values_to= "Choice_Rating", names_sep="_") %>% select(-c("conj"))
answer$Choice_binary <-ifelse(substr(answer$org, 4,4) == rep(choiceRate$Choice_Rating,each=2), 1, 0)
answer
It may be possible to simplify the above. Good luck.
Update per Comment
The final data frame has pairs of rows which corresponds to org 1 or 2. I duplicated the choice so that Choice_Rating column is the same length as the Organization ("org" column). I then compared Choice_Rating & Organization and setting the final value to either 0 or 1 depending on the match.
For question in the comment, A simple way is to convert the factor column to integers with as.integer() function, then the first factor becomes 1 and the second becomes 2 etc. (may need to relevel in order to get the proper order).
Another option is to create a new "org" column with your factor names properly listed.
Hopefully this provides enough guidance.

Sort ggplot boxplots by median with facets

I'm trying to get ggplot to order my boxplots based on median value after splittin the data into several different facets.
This is part of a larger Shiny app I've written. Under default parameters, I can generate three faceted boxplots that order correctly:
boxData <- structure(list(Classification = structure(c(4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,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c("Pluripotent/ Undifferentiated",
"Endoderm", "Mesoderm", "Ectoderm"), class = c("ordered", "factor"
)), value = c(0.000255214868214152, 0.000108050996652777, 0.00751505823956855,
8.71801689770664, 5.71059263813113e-05, 4.90291746067526e-05,
0.000129388767504551, 2.52712436532327e-07, 5345.09546573398,
0.0020991194782334, 4.33360773005175e-06, 1.8200776481618, 3.44754305553851e-06,
4.38932775031697, 0.00720892572385782, 7.53517216121544e-05,
0.221288441144887, 0.00104230990042965, 0.00288742662358172,
4.20947546944294e-05, 9.62973878475845e-07, 0.00710967831313203,
26.9833955280036, 0.00265697432110539, 1.41814003567946, 0.261340025051291,
0.00159083508412152, 9.55044905589291e-06, 0.0122931632086495,
8.54789134364452e-06, 2.01899938950824e-05, 1.55354988683742e-06,
0.000441285511108929, 0.000353500530366103, 0.125347054487635,
109.440278770173, 2.03304264082645e-05, 2.01899938950824e-05,
0.000148628664387571, 2.89902659683517e-06, 207.073625180606,
3.52469070261441e-07, 3.15047327017105e-06, 0.639049681601525,
2.11937734339159e-05, 0.484309094613314, 0.0126387710681522,
0.000124981311087457, 0.010701820155981, 0.00520458916051572,
0.002548740132205, 6.70653961877279e-06, 1.1372650836283e-06,
0.0028674817110041, 6.38196191847228, 0.00104230990042965, 2.77791027153022,
0.385285554179204, 3.23552539344696, 0.00129215960928528, 3313.17800288969,
0.42454812322342, 0.427501088945987, 0.0252775421363044, 1.3790172222154e-05,
0.000499925244349826, 0.575943821174679, 3.66456124110476e-05,
0.000979273863184647, 1.71186456807568e-06, 0.000506903940694852,
3.95489796579998e-05, 7.60789146241221e-07, 5.53083255055159e-07,
0.000283178626588241, 5.68632541814152e-07, 89.5114292952616,
2.15183665744117e-06, 9.48447928546097e-06, 1.10616651011032e-06,
6.83831307491562e-05, 0.000231612381626088, 0.361984543094889,
5.91197625260395e-05, 0.000979273863184647, 2.83936549218472e-06,
0.000979273863184647, 5.11112358098405e-05, 1.714153924998e-07,
5.19634300333657e-07, 0.000285939985649123, 0.000340041865397713,
0.11809338012465, 60.884369685235, 2.29364239206782e-05, 1.59952159960469e-05,
0.000213718586351138, 2.65657707341963e-06, 3635.65603745587,
1.08786283557826e-07, 3.36257994807117e-06, 0.482299092292068,
1.40214978558205e-05, 0.506277403675245, 0.00847835446782661,
5.84677257215999e-05, 0.00674484030136259, 0.00483589957358377,
0.0017456741452281, 6.45120458509457e-06, 6.32689066217975e-07,
0.00245170310797391, 9.30496033238278, 0.000922604532223834,
1.94261499108326, 0.348202870167258, 0.000995700862302919, 9.18683915124066e-06,
0.00490340621594781, 9.51081233425213e-06, 1.64449027258861e-05,
1.32828853670982e-06, 0.000283964853893518, 0.000480891817820092,
0.103521332666818, 96.202334596196, 1.57750051307367e-05, 2.09600255345096e-05,
0.000200793473806753, 1.29196641682183e-06, 179.519904082227,
2.39744324779145e-07, 2.44454941589392e-06, 0.492433221447773,
1.07746460295468e-05, 0.437695664847132, 0.00947275639891981,
9.69768554804815e-05, 0.0056325346541415, 0.00470366164543522,
0.00172164093341244, 6.91422987569681e-06, 8.82439067876674e-07,
0.00253816223135828, 5.84822979360013, 0.000929021754230271,
2.31017156910716, 0.278934830581241, 2.84415482117455, 0.00100262650949219,
2661.45599990874, 0.357992185300285, 0.37579036951639, 0.0210213626331535,
1.87597483406766e-05, 4.9165300967331e-05, 0.353063601096188,
2.84344613435294e-05, 0.00277749494255326, 1.32828853670982e-06,
0.00108958918195797, 9.25073867082013e-06, 1.4059026149049e-07,
4.29154362580066e-07, 0.000537294242854559, 8.10925044524043e-06,
0.020165038913309, 9.91469621624329e-06, 1.63313094852695e-05,
8.58308725160133e-07, 2.34183669433728e-05, 0.000352033415883844,
0.28087497575791, 4.58728478413563e-05, 0.0007598488052299, 1.48407969771465e-06,
0.0223745115812679, 1.15479796826903e-05, 1.33006491938229e-07,
4.03200286568411e-07, 83.9815202938853, 211.131788444181, 1.73147313103931,
0.162893393670412, 6347.61978641754, 1.56049096034741, 0.532923368033971,
0.651573574681646, 22.0392007421302, 0.05154584678813, 85997.0767809387,
2.10234581817541, 1994.76074197656, 17462.8329237372, 1.76785506212734,
49735.9012814537, 1.57134503333516, 340.615434516655, 3.73730938753272,
2.07340220203944, 0.974004268543241, 53.8920290309386, 28.8800232787977,
0.0604547706008708, 6.41744933081988, 1.9615580079771, 0.384751805040216,
1.53900722016086, 1.68412590721683, 2.31658561238929, 1.62675839626425,
2.23767420207142, 1.67249279982813, 1.53900722016086, 1.51781925297405,
0.717972255311719, 1.08072540203935, 1.6958399292663, 1.74351647907412,
1.6958399292663, 0.98077900398855, 0.000159075579756261, 1.32133840565826,
1.57134503333516, 1.79253339913881, 2.00277451142267, 1.74351647907412,
2.66105808216138, 0.90250072746243, 2.059080166868, 1.50733490955838,
1.3966785324674, 1.61552155521922, 1.42602571736414, 1.90791910109511,
1.38703096913138, 1.38703096913138, 1.49692298679269, 1.69583992926629,
2.16145080407871, 2.67956720485568, 1.3966785324674, 1.53900722016086,
1.70763542878249, 0.921464186198703, 3.32188009636358, 10.5707072452661,
6.5522935828786, 1.68412590721683, 7.57896056479413, 1.43594451062343,
0.312515575646302, 34.1070955541741, 2339.52511354582, 11.0962477530511,
8.17942824487938, 1.68412590721683, 0.418123199957032, 804.528657067602,
0.679243142274472, 1.47631440568283, 1.75564359521904, 2.81278639982623,
4.14680440407889, 1.68412590721683, 2.33269873957693, 1.68412590721683,
1.70763542878249, 1.37745004638314, 1.68412590721683), listElement = structure(c(3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Endoderm",
"Mesoderm", "Ectoderm"), class = "factor")), .Names = c("Classification",
"value", "listElement"), row.names = c(NA, -270L), class = "data.frame")
To generate the boxplot:
boxData$temp <- paste(substr(boxData$Classification,1,6),
as.character(boxData$listElement))
ggplot(boxData, aes(reorder(boxData$temp, value, median),value, fill=Classification))+
geom_boxplot()+
scale_y_log10()+
ylab("Fold Expression Change")+
xlab("Gene Classification")+
theme(axis.text.x=element_text(angle=90, hjust=1, size=6))+
facet_wrap(~listElement, scales='free', ncol=1)+
scale_x_discrete(labels=setNames(as.character(boxData$Classification), boxData$temp))
But if a parameter is changed and we only have two samples rather than three (In this case, the same data, but with twice as many 'endoderm' samples and no 'mesoderm' samples), the boxplots look really weird:
boxData <- structure(list(Classification = structure(c(4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Pluripotent/ Undifferentiated",
"Endoderm", "Mesoderm", "Ectoderm"), class = c("ordered", "factor"
)), value = c(0.000255214868214152, 0.000108050996652777, 0.00751505823956855,
8.71801689770664, 5.71059263813113e-05, 4.90291746067526e-05,
0.000129388767504551, 2.52712436532327e-07, 5345.09546573398,
0.0020991194782334, 4.33360773005175e-06, 1.8200776481618, 3.44754305553851e-06,
4.38932775031697, 0.00720892572385782, 7.53517216121544e-05,
0.221288441144887, 0.00104230990042965, 0.00288742662358172,
4.20947546944294e-05, 9.62973878475845e-07, 0.00710967831313203,
26.9833955280036, 0.00265697432110539, 1.41814003567946, 0.261340025051291,
0.00159083508412152, 9.55044905589291e-06, 0.0122931632086495,
8.54789134364452e-06, 2.01899938950824e-05, 1.55354988683742e-06,
0.000441285511108929, 0.000353500530366103, 0.125347054487635,
109.440278770173, 2.03304264082645e-05, 2.01899938950824e-05,
0.000148628664387571, 2.89902659683517e-06, 207.073625180606,
3.52469070261441e-07, 3.15047327017105e-06, 0.639049681601525,
2.11937734339159e-05, 0.484309094613314, 0.0126387710681522,
0.000124981311087457, 0.010701820155981, 0.00520458916051572,
0.002548740132205, 6.70653961877279e-06, 1.1372650836283e-06,
0.0028674817110041, 6.38196191847228, 0.00104230990042965, 2.77791027153022,
0.385285554179204, 3.23552539344696, 0.00129215960928528, 3313.17800288969,
0.42454812322342, 0.427501088945987, 0.0252775421363044, 1.3790172222154e-05,
0.000499925244349826, 0.575943821174679, 3.66456124110476e-05,
0.000979273863184647, 1.71186456807568e-06, 0.000506903940694852,
3.95489796579998e-05, 7.60789146241221e-07, 5.53083255055159e-07,
0.000283178626588241, 5.68632541814152e-07, 89.5114292952616,
2.15183665744117e-06, 9.48447928546097e-06, 1.10616651011032e-06,
6.83831307491562e-05, 0.000231612381626088, 0.361984543094889,
5.91197625260395e-05, 0.000979273863184647, 2.83936549218472e-06,
0.000979273863184647, 5.11112358098405e-05, 1.714153924998e-07,
5.19634300333657e-07, 3.36257994807117e-06, 0.482299092292068,
1.40214978558205e-05, 0.00847835446782661, 5.84677257215999e-05,
0.00674484030136259, 0.00483589957358377, 0.0017456741452281,
6.45120458509457e-06, 6.32689066217975e-07, 0.00245170310797391,
9.30496033238278, 0.000922604532223834, 1.94261499108326, 0.348202870167258,
0.506277403675245, 0.000285939985649123, 0.000340041865397713,
0.11809338012465, 60.884369685235, 2.29364239206782e-05, 1.59952159960469e-05,
0.000213718586351138, 2.65657707341963e-06, 3635.65603745587,
1.08786283557826e-07, 83.9815202938853, 211.131788444181, 1.73147313103931,
0.162893393670412, 6347.61978641754, 1.56049096034741, 0.532923368033971,
0.651573574681646, 22.0392007421302, 0.05154584678813, 85997.0767809387,
2.10234581817541, 1994.76074197656, 17462.8329237372, 1.76785506212734,
49735.9012814537, 1.57134503333516, 340.615434516655, 3.73730938753272,
2.07340220203944, 0.974004268543241, 53.8920290309386, 28.8800232787977,
0.0604547706008708, 6.41744933081988, 1.9615580079771, 1.57750051307367e-05,
2.09600255345096e-05, 0.000200793473806753, 1.29196641682183e-06,
179.519904082227, 2.39744324779145e-07, 2.44454941589392e-06,
0.492433221447773, 1.07746460295468e-05, 0.437695664847132, 0.00947275639891981,
9.69768554804815e-05, 0.0056325346541415, 0.00470366164543522,
0.00172164093341244, 6.91422987569681e-06, 8.82439067876674e-07,
1.57134503333516, 1.79253339913881, 2.00277451142267, 1.74351647907412,
2.66105808216138, 0.90250072746243, 2.059080166868, 1.50733490955838,
1.3966785324674, 1.61552155521922, 0.384751805040216, 1.53900722016086,
1.68412590721683, 0.000995700862302919, 9.18683915124066e-06,
0.00490340621594781, 9.51081233425213e-06, 1.64449027258861e-05,
1.32828853670982e-06, 0.000283964853893518, 0.000480891817820092,
0.103521332666818, 96.202334596196, 1.6958399292663, 0.98077900398855,
0.000159075579756261, 2.31658561238929, 1.62675839626425, 2.23767420207142,
1.67249279982813, 1.53900722016086, 1.51781925297405, 0.717972255311719,
1.08072540203935, 1.6958399292663, 1.74351647907412, 1.32133840565826,
0.0210213626331535, 1.87597483406766e-05, 4.9165300967331e-05,
0.00253816223135828, 5.84822979360013, 0.000929021754230271,
2.31017156910716, 0.278934830581241, 2.84415482117455, 0.00100262650949219,
2661.45599990874, 0.357992185300285, 0.37579036951639, 1.42602571736414,
1.90791910109511, 1.38703096913138, 0.353063601096188, 2.84344613435294e-05,
0.00277749494255326, 1.32828853670982e-06, 0.00108958918195797,
9.25073867082013e-06, 1.4059026149049e-07, 4.29154362580066e-07,
0.000537294242854559, 8.10925044524043e-06, 0.020165038913309,
9.91469621624329e-06, 1.63313094852695e-05, 8.58308725160133e-07,
1.43594451062343, 0.312515575646302, 34.1070955541741, 2339.52511354582,
11.0962477530511, 8.17942824487938, 1.68412590721683, 0.418123199957032,
804.528657067602, 0.679243142274472, 10.5707072452661, 6.5522935828786,
1.68412590721683, 1.38703096913138, 1.49692298679269, 1.69583992926629,
2.16145080407871, 2.67956720485568, 1.3966785324674, 1.53900722016086,
1.70763542878249, 0.921464186198703, 3.32188009636358, 7.57896056479413,
2.34183669433728e-05, 0.000352033415883844, 0.28087497575791,
4.58728478413563e-05, 0.0007598488052299, 1.48407969771465e-06,
0.0223745115812679, 1.15479796826903e-05, 1.33006491938229e-07,
4.03200286568411e-07, 1.47631440568283, 1.75564359521904, 2.81278639982623,
4.14680440407889, 1.68412590721683, 2.33269873957693, 1.68412590721683,
1.70763542878249, 1.37745004638314, 1.68412590721683), listElement = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 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c("Classification",
"value", "listElement"), row.names = c(NA, -270L), class = "data.frame")
Running the same code as above:
boxData$temp <- paste(substr(boxData$Classification,1,6),
as.character(boxData$listElement))
ggplot(boxData, aes(reorder(boxData$temp, value, median),value, fill=Classification))+
geom_boxplot()+
scale_y_log10()+
ylab("Fold Expression Change")+
xlab("Gene Classification")+
theme(axis.text.x=element_text(angle=90, hjust=1, size=6))+
facet_wrap(~listElement, scales='free', ncol=1)+
scale_x_discrete(labels=setNames(as.character(boxData$Classification), boxData$temp))
gives a strange-looking graph:
This graph should look the same as the first graph, just with two facets rather than three. If I don't try to reorder the values by median, this graph plots fine. I've fiddled with a number of things, but can't seem to fix this issue. I'm sure I've made a stupid mistake somewhere, but can't seem to find it.
Any help would be greatly appreciated!
It looks to me that you are reordering the factor "temp" without releveling the dataset. What about bringing the ordering operation outside the ggplot call?
boxData$temp <- paste(substr(boxData$Classification,1,6),
as.character(boxData$listElement))
fac <- with(boxData, reorder(temp, value, median, order = TRUE))
boxData$temp <- factor(boxData$temp, levels = levels(fac))
ggplot(boxData, aes(temp,value, fill=Classification))+
geom_boxplot()+
scale_y_log10()+
ylab("Fold Expression Change")+
xlab("Gene Classification")+
theme(axis.text.x=element_text(angle=90, hjust=1, size=6))+
facet_wrap(~listElement, scales='free', ncol=1)+
scale_x_discrete(labels=setNames(as.character(boxData$Classification), boxData$temp))
This is what you would expect, right?

How to get the median line in bwplot thicker?

The following code is a minimal (for some value of minimal....) example that uses lattice to produce boxplots. But the median line on those boxplot is a) coloured and b) very thin. How to get them to be black and tick?
a71<-structure(list(n = structure(c(1L, 2L, 2L, 4L, 4L, 1L, 1L, 4L,
2L, 1L, 1L, 2L, 2L, 4L, 2L, 2L, 3L, 4L, 1L, 2L, 2L, 3L, 2L, 2L,
2L, 4L, 3L, 3L, 4L, 2L, 4L, 2L, 1L, 3L, 2L, 3L, 4L, 1L, 4L, 1L,
3L, 3L, 2L, 1L, 1L, 3L, 3L, 1L, 2L, 4L, 3L, 2L, 3L, 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2L, 1L, 3L, 1L, 1L, 2L, 2L
), .Label = c("-0.4", "0", "0.4"), class = "factor"), bias = c(0.0162558992812201,
0.138354243932496, 0.0205686041691062, 0.269714433604472,
0.381044037439145, 0.0869422119950729, 0.331379037601084,
0.686894150152472, 0.0140922903231885, 0.225078933454863,
0.554444988164574, 0.076032683077827, 0.335284040888653,
0.0630810396519646, 0.358402154233125, 0.260940142571834,
0.141353291599136, 0.0220267076189838, 0.242149484071382,
0.278319984858078, 0.193105829691662, 0.0259815643559331,
0.318504899459259, 0.00277002060524357, 0.212681621053374,
0.418358846098857, 0.358916156777489, 0.438248724241505,
0.194398889511096, 0.2266870834128, 0.144338808446284, 0.149227951210927,
0.268111328952192, 0.123265441389974, 0.0376832357983068,
0.0353605481767078, 0.021227873083535, 0.0385614926552725,
0.130640111978654, 0.161865326447675, 0.174151298764213,
0.292085797406362, 0.198391364913347, 0.0779507859721407,
0.0045571464157577, 0.114734038438965, 0.0469613758623325,
0.64238405800387, 0.74508519247034, 0.0251182457091362, 0.217835062247358,
0.131159910126724, 0.130034859007596, 0.222418419987533,
0.0861715693619894, 0.185660520258661, 0.0940670543815277,
0.105680179626893, 0.215966730684923, 0.109008340760604,
0.0474735195202623, 0.192326789813641, 0.022147195644035,
0.277372858009381, 0.237574293593955, 0.123383946121193,
0.46406480500022, 0.123698482002945, 0.671442441453945, 0.0406004813894845,
0.260472754754191, 0.0151116521560003, 0.0422855023583402,
0.0405517218780402, 0.0441583998205882, 0.0958995639409343,
0.37588506579263, 0.098494760958735, 0.0928763466294421,
0.111205748449328, 0.413083543393392, 0.0138839674143682,
0.22407421093074, 0.72309883706409, 0.423231501875638, 0.141932050342199,
0.133808548118004, 0.331500621801688, 0.127652280721512,
0.132083126730013, 0.261864564503826, 0.208243130464985,
0.18657049493156, 0.333701537602998, 0.404884075502013, 0.470789398932934,
0.115008599462104, 0.177984001517338, 0.331717679106776,
0.0862418839846533), group = structure(c(3L, 2L, 2L, 3L,
1L, 3L, 3L, 2L, 2L, 1L, 3L, 2L, 2L, 2L, 1L, 3L, 2L, 3L, 1L,
3L, 1L, 2L, 1L, 3L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 3L, 1L, 1L,
3L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 3L, 1L, 2L,
3L, 3L, 3L, 1L, 1L, 3L, 2L, 3L, 1L, 1L, 2L, 2L, 2L, 2L, 1L,
2L, 1L, 1L, 1L, 3L, 2L, 2L, 1L, 1L, 3L, 3L, 3L, 2L, 1L, 3L,
3L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 3L, 3L, 1L, 1L, 2L, 3L,
1L, 1L, 3L, 2L, 1L, 3L), .Label = c("1", "2", "3"), class = "factor")), .Names = c("n",
"g", "cr", "bias", "group"), row.names = c(8721L, 6970L, 6686L,
9624L, 352L, 10545L, 7505L, 4216L, 6170L, 3309L, 10429L, 4302L,
5602L, 5680L, 1530L, 9234L, 5007L, 8004L, 721L, 10038L, 502L,
4891L, 2946L, 8502L, 622L, 1972L, 2403L, 3383L, 5880L, 1038L,
4756L, 9506L, 2169L, 1023L, 8506L, 6239L, 7768L, 3221L, 9536L,
5981L, 1507L, 4883L, 414L, 3117L, 3993L, 1923L, 9143L, 2673L,
4430L, 9520L, 9363L, 10602L, 95L, 1141L, 9660L, 4285L, 10704L,
154L, 531L, 6440L, 4876L, 7052L, 4397L, 3375L, 5075L, 1295L,
2620L, 334L, 9510L, 4690L, 4288L, 3576L, 2248L, 7693L, 8820L,
8135L, 4026L, 1906L, 10164L, 8616L, 423L, 5290L, 418L, 6486L,
4485L, 7042L, 955L, 2215L, 9031L, 8049L, 2323L, 1627L, 4212L,
8689L, 439L, 2590L, 8649L, 5447L, 1957L, 10570L), class = "data.frame")
library(lattice)
cl<-c('red','green','blue')
mypanel<-function(...){
panel.bwplot(...,pch="|",col="black",cex=4,fill=cl)
}
o1<-bwplot(a71$bias~a71$group|a71$cr*a71$g,type=c("l","g"),ylim=c(0,1),panel=mypanel)
plot(o1)
By changing some of the parameters of box.rectangle (a lattice-specific graphical parameter), you can manipulate the lines (including the median line) surrounding each of the box plots. This will change all the lines around the boxes, however, not just the median line.
myPars <- list(box.rectangle = list(lwd = 2, col = "black"))
lwd changes the line width (thickness). colchanges the color of the lines. Then pass this list to the par.settings argument in bwplot.
o1 <- bwplot(a71$bias ~ a71$group | a71$cr * a71$g,
type = c("l", "g"), ylim = c(0, 1), panel = mypanel,
par.settings = myPars)
plot(o1)
To see all of the parameters associated with box.rectangle, use
trellis.par.get("box.rectangle")
OP is happy with all lines thicker by #BenBarnes, but for completeness, it is possible to just thicken the median line. Using the fact that box.width defaults to 1/2:
bwplot(a71$bias~a71$group|a71$cr*a71$g,type=c("l","g"),ylim=c(0,1),
panel=function(x,y,...){
panel.bwplot(x,y,...,pch="|",col="black",cex=4,fill=cl)
medy <- by(y,list(x),median)
xx <- sort(unique(as.numeric(x)))
panel.segments(xx-.25,medy,xx+.25,medy,lwd=2)
}
)

Resources