[R] Repeatability Analysis of Ordinal Data
Greetings, Colleagues: I have several Likert-type ordinal data sets consisting of animal responses with repeated measures. I was able to implement a CLMM model easily enough with the package `ordinal`. However, the package does not support repeatability analyses. Assuming that I subset my data according to treatment and/or sex, I am keen to try the `ordinalRR` package. According to the package documentation (https://cran.r-project.org/web/packages/ordinalRR/ordinalRR.pdf), performing `summary()` on the output from the function `ordinalRR()` returns the point estimates for each rater and for each pairwise combination of raters. However, is it possible to return an overall repeatability value and a 95% credible interval across all raters? What follows is a stock procedure from the package reference document: #--- library(ordinalRR) # load the dataset that comes with the package data(followup) # preprocess data to accommodate the package functions followup.pre <- preprocess(followup) # perform the analysis followup.random <- ordinalRR(followup.pre) summary(followup.random) Call: ordinalRR(followup.pre) Data: 30 parts, 3 operators, 2 repetitions with 4 ordinal categories. Random-effects model MCMC chain: 1000 burn-in and 1 retained. Simple repeatability and model parameter estimates by rater: Rater j Repeatability a_j d_{j,1} d_{j,2} d_{j,3} 1 0.900 12.0-1.5-0.1 0.6 2 0.900 10.9-1.6-0.3 0.5 3 0.933 12.7-1.5-0.2 0.5 Simple repeatability and reproducibility (R) point estimates for pairs of raters: Rater j Rater j' (R)_{j,j'} 120.808 130.900 230.850 #--- Kind Regards, Salvatore Sidoti PhD Candidate The Ohio State University Columbus, Ohio USA __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Data With Ordinal Responses: Calculate ICC & Assessing Model Fit
To begin with, I'm not a fan of cross-posting. However, I posted my question on Stack Exchange more than two weeks ago, but I have yet to receive a sufficient answer: https://stats.stackexchange.com/questions/479600/data-with-ordinal-responses-calculate-icc-assessing-model-fit Here's what I've learned since then (hopefully): 1) ICC of a CLMM: Computed like this: (variance of the random effect) / (variance of the random effect + 1) If this is correct, I would love to see a reference/citation for it. 2) 95% Confidence Interval for the ICC from a CLMM Model To my current understanding, a confidence interval for an ICC is only obtainable via simulation. I've conducted simulations with GLMM model objects ('lme4' package) and the bootMer() function. Unfortunately, bootMer() will not accept a CLMM model ('ordinal' package). 3) Model Fit of a CLMM Assuming that the model converges without incident, the model summary includes a condition number of the Hessian ('cond.H'). This value should be below 10^4 for a "good fit". This is straightforward enough. However, I am not as sure about the value for 'max.grad', which needs to be "well below 1". The question is, to what magnitude should max.grad < 1 for a decent model fit? My reference is linked below (Christensen, 2019), but it does not elaborate further on this point: https://documentcloud.adobe.com/link/track?uri=urn:aaid:scds:US:b6a61fe2-b851-49ce-b8b1-cd760d290636 3) Effect Size of a CLMM The random variable's effect is determined by a comparison between the full model to a model with only the fixed effects via the anova() function. I found this information on the 'rcompanion' package website: https://rcompanion.org/handbook/G_12.html The output of this particular anova() will include a value named 'LR.stat', the likelihood ratio statistic. The LR.stat is twice the difference of each log-likelihood (absolute value) of the respective models. Is LR.stat the mixed-model version of an "effect size"? If so, how does one determine if the effect is small, large, in-between, etc? Cheers, Sal Salvatore A. Sidoti PhD Candidate Behavioral Ecology The Ohio State University __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Interpolating Splines: Equidistant Points
I am attempting to smooth the jagged paths of animal tracks to determine their distances with greater accuracy. The data is in the form of (x,y) 2D coordinates. My end goal is to produce a set of interpolating points whereby their Cartesian distances are equal to each other. So far, I have been able to produce a path with a specified number of interpolating points via spline(). However, these points are not equidistant. An example data set and my code thus far: df <- structure(list(x = c(329L, 329L, 329L, 329L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 331L, 331L, 331L, 332L, 332L, 333L, 333L, 333L, 333L, 333L, 333L, 333L, 333L, 333L, 333L, 333L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 334L, 333L, 333L, 332L, 332L, 332L, 332L, 332L, 332L, 333L, 333L, 333L, 332L, 333L, 331L, 331L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 330L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 329L, 328L, 327L, 327L, 327L, 327L, 327L, 326L, 326L, 325L, 325L, 325L, 325L, 325L, 323L, 322L, 321L, 320L, 319L, 319L, 319L, 319L, 319L, 319L ), y = c(255L, 256L, 256L, 256L, 257L, 257L, 257L, 257L, 257L, 257L, 257L, 257L, 257L, 257L, 258L, 259L, 259L, 259L, 261L, 261L, 262L, 263L, 263L, 264L, 265L, 266L, 266L, 267L, 268L, 269L, 270L, 272L, 272L, 273L, 274L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 276L, 277L, 278L, 278L, 279L, 280L, 281L, 283L, 284L, 285L, 287L, 288L, 290L, 291L, 291L, 294L, 295L, 297L, 298L, 299L, 300L, 301L, 302L, 302L, 304L, 305L, 306L, 306L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 308L, 309L, 310L, 311L, 311L, 312L, 313L, 314L, 315L, 318L, 319L, 320L, 322L, 323L, 324L, 325L, 325L, 325L, 325L, 326L, 326L, 327L)), .Names = c("x", "y"), row.names = c(NA, -150L), class = "data.frame") require(Momocs) cumdist <- coo_perimcum(df) sx <- spline(cumdist, df[, 1], method = "natural", n = 10) sy <- spline(cumdist, df[, 2], method = "natural", n = 10) splines <- cbind.data.frame(x = sx$y, y = sy$y) par(pty = "s") with(df, plot(x, y, main = "Example Locomotor Path - Cubic Spline Smoothing", axes = FALSE, frame.plot = TRUE, type = "l", col = "light gray", lwd = 3)) with(splines, lines(x, y, type = "b", col = "red", lwd = 3)) Thank you! Salvatore A. Sidoti PhD Student Behavioral Ecology __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Principle Component Analysis: Ranking Animal Size Based On Combined Metrics
Fascinating! So it appears that I can simply take the geometric mean of all 4 metrics (unscaled), including weight, then designate that value as a relative measure of "size" within my sample population. The justification for using the geometric mean is shown by the high correlation between PC1 and the size values: pc1 gm pc1 1.000 -0.8458024 gm -0.8458024 1.000 Pearson's product-moment correlation data: pc1 and gm t = -10.869, df = 47, p-value = 2.032e-14 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: -0.9104585 -0.7407939 sample estimates: cor -0.8458024 Salvatore A. Sidoti PhD Student Behavioral Ecology -Original Message- From: David L Carlson [mailto:dcarl...@tamu.edu] Sent: Monday, November 14, 2016 11:07 AM To: Sidoti, Salvatore A. <sidoti...@buckeyemail.osu.edu>; Jim Lemon <drjimle...@gmail.com>; r-help mailing list <r-help@r-project.org> Subject: RE: [R] Principle Component Analysis: Ranking Animal Size Based On Combined Metrics The first principal component should be your estimate of "size" since it captures the correlations between all 4 variables. The second principle component must be orthogonal to the first so that if the first is "size", the second pc is independent of size, perhaps some measure of "shape". As would be expected, the first principal component is highly correlated with the geometric mean of the three linear measurements and moderately correlated with weight: > gm <- apply(df[, -1], 1, prod)^(1/3) > pc1 <- prcomp(df, scale.=TRUE)$x[, 1] > plot(pc1, gm) > cor(cbind(pc1, gm, wgt=df$weight)) pc1 gmwgt pc1 1.000 -0.9716317 -0.5943594 gm -0.9716317 1.000 0.3967369 wgt -0.5943594 0.3967369 1.000 - David L Carlson Department of Anthropology Texas A University College Station, TX 77840-4352 -Original Message----- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Sidoti, Salvatore A. Sent: Sunday, November 13, 2016 7:38 PM To: Jim Lemon; r-help mailing list Subject: Re: [R] Principle Component Analysis: Ranking Animal Size Based On Combined Metrics Hi Jim, Nice to see you again! First of all, apologies to all for bending the rules a bit with respect to the mailing list. I know this is a list for R programming specifically, and I have received some great advice in this regard in the past. I just thought this was an interesting applied problem that would generate some discussion about PCA in R. Yes, that is an excellent question! Indeed, why not just volume? Since this is still a work in progress and we have not published as of yet, I would rather not be more specific about the type of animal at this time ;>}. Nonetheless, I can say that the animals I study change "size" depending on their feeding and hydration state. The abdomen in particular undergoes drastic size changes. That being said, there are key anatomical features that remain fixed in the adult. Now, there *might* be a way to work volume into the PCA. Although volume is not a reliable metric since the abdomen size is so changeable while the animal is alive, but what about preserved specimens? I have many that have been marinating in ethanol for months. Wouldn't the tissues have equilibrated by now? Probably... I could measure volume by displacement or suspension, I suppose. In the meantime, here's a few thoughts: 1) Use the contribution % (known as C% hereafter) of each variable on principle components 1 and 2. 2) The total contribution of a variable that explains the variations retained by PC1 an PC2 is calculated by: sum(C%1 * eigenvalue1, C%2 * eigenvalue2) 3) Scale() to mean-center the columns of the data set. 4) Use these total contributions as the weights of an arithmetic mean. For example, we have an animal with the following data (mean-centered): weight: 1.334 interoc:-0.225 clength:0.046 cwidth: -0.847 The contributions of these variables on PC1 and PC2 are (% changed to proportions): weight: 0.556 interoc:0.357 clength:0.493 cwidth: 0.291 To calculate size: 1.334(0.556) - 0.225(0.357) + 0.046(0.493) - 0.847(0.291) = 0.43758 Then divide by the sum of the weights: 0.43758 / 1.697 = 0.257855 = "animal size" This value can then be used to rank the animal according to its size for further analysis... Does this sound like a reasonable application of my PCA data? Salvatore A. Sidoti PhD Student Behavioral Ecology -Original Message----- From: Jim Lemon [mailto:drjimle...@gmail.com] Sent: Sunday, November 13, 2016 3:53 PM To: Sidoti, Salvatore A. <sidoti...@buckeyemail.osu.edu>; r-help mailing list <r-help@r-project.org> Subject: Re: [R] Principle Component Analysis: Ranking Animal Size Based On Com
Re: [R] Principle Component Analysis: Ranking Animal Size Based On Combined Metrics
Hi Jim, Nice to see you again! First of all, apologies to all for bending the rules a bit with respect to the mailing list. I know this is a list for R programming specifically, and I have received some great advice in this regard in the past. I just thought this was an interesting applied problem that would generate some discussion about PCA in R. Yes, that is an excellent question! Indeed, why not just volume? Since this is still a work in progress and we have not published as of yet, I would rather not be more specific about the type of animal at this time ;>}. Nonetheless, I can say that the animals I study change "size" depending on their feeding and hydration state. The abdomen in particular undergoes drastic size changes. That being said, there are key anatomical features that remain fixed in the adult. Now, there *might* be a way to work volume into the PCA. Although volume is not a reliable metric since the abdomen size is so changeable while the animal is alive, but what about preserved specimens? I have many that have been marinating in ethanol for months. Wouldn't the tissues have equilibrated by now? Probably... I could measure volume by displacement or suspension, I suppose. In the meantime, here's a few thoughts: 1) Use the contribution % (known as C% hereafter) of each variable on principle components 1 and 2. 2) The total contribution of a variable that explains the variations retained by PC1 an PC2 is calculated by: sum(C%1 * eigenvalue1, C%2 * eigenvalue2) 3) Scale() to mean-center the columns of the data set. 4) Use these total contributions as the weights of an arithmetic mean. For example, we have an animal with the following data (mean-centered): weight: 1.334 interoc:-0.225 clength:0.046 cwidth: -0.847 The contributions of these variables on PC1 and PC2 are (% changed to proportions): weight: 0.556 interoc:0.357 clength:0.493 cwidth: 0.291 To calculate size: 1.334(0.556) - 0.225(0.357) + 0.046(0.493) - 0.847(0.291) = 0.43758 Then divide by the sum of the weights: 0.43758 / 1.697 = 0.257855 = "animal size" This value can then be used to rank the animal according to its size for further analysis... Does this sound like a reasonable application of my PCA data? Salvatore A. Sidoti PhD Student Behavioral Ecology -Original Message- From: Jim Lemon [mailto:drjimle...@gmail.com] Sent: Sunday, November 13, 2016 3:53 PM To: Sidoti, Salvatore A. <sidoti...@buckeyemail.osu.edu>; r-help mailing list <r-help@r-project.org> Subject: Re: [R] Principle Component Analysis: Ranking Animal Size Based On Combined Metrics Hi Salvatore, If by "size" you mean volume, why not directly measure the volume of your animals? They appear to be fairly small. Sometimes working out what the critical value actually means can inform the way to measure it. Jim On Sun, Nov 13, 2016 at 4:46 PM, Sidoti, Salvatore A. <sidoti...@buckeyemail.osu.edu> wrote: > Let's say I perform 4 measurements on an animal: three are linear > measurements in millimeters and the fourth is its weight in milligrams. So, > we have a data set with mixed units. > > Based on these four correlated measurements, I would like to obtain one > "score" or value that describes an individual animal's size. I considered > simply taking the geometric mean of these 4 measurements, and that would give > me a "score" - larger values would be for larger animals, etc. > > However, this assumes that all 4 of these measurements contribute equally to > an animal's size. Of course, more than likely this is not the case. I then > performed a PCA to discover how much influence each variable had on the > overall data set. I was hoping to use this analysis to refine my original > approach. > > I honestly do not know how to apply the information from the PCA to this > particular problem... > > I do know, however, that principle components 1 and 2 capture enough of the > variation to reduce the number of dimensions down to 2 (see analysis below > with the original data set). > > Note: animal weights were ln() transformed to increase correlation with the 3 > other variables. > > df <- data.frame( > weight = log(1000*c(0.0980, 0.0622, 0.0600, 0.1098, 0.0538, 0.0701, 0.1138, > 0.0540, 0.0629, 0.0930, > 0.0443, 0.1115, 0.1157, 0.0734, 0.0616, 0.0640, 0.0480, 0.1339, > 0.0547, 0.0844, > 0.0431, 0.0472, 0.0752, 0.0604, 0.0713, 0.0658, 0.0538, 0.0585, > 0.0645, 0.0529, > 0.0448, 0.0574, 0.0577, 0.0514, 0.0758, 0.0424, 0.0997, 0.0758, > 0.0649, 0.0465, > 0.0748, 0.0540, 0.0819, 0.0732, 0.0725, 0.0730, 0.0777, 0.0630, > 0.0466)), > interoc = c(0.853, 0.865, 0.811, 0.840, 0.783, 0.868, 0.818, 0.847, 0.838,
[R] Principle Component Analysis: Ranking Animal Size Based On Combined Metrics
Let's say I perform 4 measurements on an animal: three are linear measurements in millimeters and the fourth is its weight in milligrams. So, we have a data set with mixed units. Based on these four correlated measurements, I would like to obtain one "score" or value that describes an individual animal's size. I considered simply taking the geometric mean of these 4 measurements, and that would give me a "score" - larger values would be for larger animals, etc. However, this assumes that all 4 of these measurements contribute equally to an animal's size. Of course, more than likely this is not the case. I then performed a PCA to discover how much influence each variable had on the overall data set. I was hoping to use this analysis to refine my original approach. I honestly do not know how to apply the information from the PCA to this particular problem... I do know, however, that principle components 1 and 2 capture enough of the variation to reduce the number of dimensions down to 2 (see analysis below with the original data set). Note: animal weights were ln() transformed to increase correlation with the 3 other variables. df <- data.frame( weight = log(1000*c(0.0980, 0.0622, 0.0600, 0.1098, 0.0538, 0.0701, 0.1138, 0.0540, 0.0629, 0.0930, 0.0443, 0.1115, 0.1157, 0.0734, 0.0616, 0.0640, 0.0480, 0.1339, 0.0547, 0.0844, 0.0431, 0.0472, 0.0752, 0.0604, 0.0713, 0.0658, 0.0538, 0.0585, 0.0645, 0.0529, 0.0448, 0.0574, 0.0577, 0.0514, 0.0758, 0.0424, 0.0997, 0.0758, 0.0649, 0.0465, 0.0748, 0.0540, 0.0819, 0.0732, 0.0725, 0.0730, 0.0777, 0.0630, 0.0466)), interoc = c(0.853, 0.865, 0.811, 0.840, 0.783, 0.868, 0.818, 0.847, 0.838, 0.799, 0.737, 0.788, 0.731, 0.777, 0.863, 0.877, 0.814, 0.926, 0.767, 0.746, 0.700, 0.768, 0.807, 0.753, 0.809, 0.788, 0.750, 0.815, 0.757, 0.737, 0.759, 0.863, 0.747, 0.838, 0.790, 0.676, 0.857, 0.728, 0.743, 0.870, 0.787, 0.773, 0.829, 0.785, 0.746, 0.834, 0.829, 0.750, 0.842), cwidth = c(3.152, 3.046, 3.139, 3.181, 3.023, 3.452, 2.803, 3.050, 3.160, 3.186, 2.801, 2.862, 3.183, 2.770, 3.207, 3.188, 2.969, 3.033, 2.972, 3.291, 2.772, 2.875, 2.978, 3.094, 2.956, 2.966, 2.896, 3.149, 2.813, 2.935, 2.839, 3.152, 2.984, 3.037, 2.888, 2.723, 3.342, 2.562, 2.827, 2.909, 3.093, 2.990, 3.097, 2.751, 2.877, 2.901, 2.895, 2.721, 2.942), clength = c(3.889, 3.733, 3.762, 4.059, 3.911, 3.822, 3.768, 3.814, 3.721, 3.794, 3.483, 3.863, 3.856, 3.457, 3.996, 3.876, 3.642, 3.978, 3.534, 3.967, 3.429, 3.518, 3.766, 3.755, 3.706, 3.785, 3.607, 3.922, 3.453, 3.589, 3.508, 3.861, 3.706, 3.593, 3.570, 3.341, 3.916, 3.336, 3.504, 3.688, 3.735, 3.724, 3.860, 3.405, 3.493, 3.586, 3.545, 3.443, 3.640)) pca_morpho <- princomp(df, cor = TRUE) summary(pca_morpho) Importance of components: Comp.1 Comp.2 Comp.3 Comp.4 Standard deviation 1.6041070.8827323 0.7061206 0.3860275 Proportion of Variance 0.6432900.1948041 0.1246516 0.0372543 Cumulative Proportion 0.6432900.8380941 0.9627457 1.000 Loadings: Comp.1 Comp.2 Comp.3 Comp.4 weight -0.371 0.907 -0.201 interoc -0.486 -0.227 -0.840 cwidth -0.537 -0.349 0.466 -0.611 clength -0.582 0.278 0.761 Comp.1 Comp.2 Comp.3 Comp.4 SS loadings 1.001.001.001.00 Proportion Var 0.250.250.250.25 Cumulative Var 0.250.500.751.00 Any guidance will be greatly appreciated! Salvatore A. Sidoti PhD Student The Ohio State University Behavioral Ecology __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Spicing Up Native Circular Plot Using ggplot2
I have some angle data from an animal behavior study that I would like to plot for publication using ggplot2. What follows is my current workflow with some example data. ### BEGIN SCRIPT ### ### Create two data frames of random Cartesian coordinates ### df1 <- data.frame( x = sample(10, 11, replace = TRUE), y = sample(10, 11, replace = TRUE)) df2 <- data.frame( x = sample(10, 11, replace = TRUE), y = sample(10, 11, replace = TRUE)) ### Write a function that converts continuous Cartesian coordinates to velocities ### get.polar <- function(df) { x <- diff(df$x) y <- diff(df$y) d <- complex(real = x, imaginary = y) steps <- data.frame(speed = Mod(d), angle = Arg(d)) steps[-1,] # Deletes the first row as it does not contain an angle measurement steps$time <- (1:nrow(steps))/30 # generates a time column in seconds (1 data point = 1/30 of a second) return(steps) } df1_polar <- get.polar(df1) df2_polar <- get.polar(df2) require(circular) ### Convert angles into an object of type 'circular' ### df1_rad <- circular(df1_polar$angle, type = 'angles', units = 'radians', zero=0, rotation = "counter") df2_rad <- circular(df2_polar$angle, type = 'angles', units = 'radians', zero=0, rotation = "counter") ### Convert radians to degrees with a clockwise rotation and zero at "north" ### df1_deg <- conversion.circular(df1_rad, type = "angles", units = "degrees", zero = pi/2, rotation = "clock") df2_deg <- conversion.circular(df2_rad, type = "angles", units = "degrees", zero = pi/2, rotation = "clock") ### Convert negative rotations to positive ### df1_deg[df1_deg < 0] <- df1_deg[df1_deg < 0] + 360 df2_deg[df2_deg < 0] <- df2_deg[df2_deg < 0] + 360 par(pty = "s") plot(df1_deg, units = "degrees") ticks.circular(circular(seq(0,(11/6)*pi, pi/6)), zero = pi/2, rotation = "clock", tcl = 0.075) points(df2_deg, zero = pi/2, rotation = "clock", pch = 16, col = "darkgrey", next.points = -0.2) ### END SCRIPT ### Some suggestions for turning this rough plot into something publishable using ggplot2? Thank you! Salvatore A. Sidoti __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Splitting Numerical Vector Into Chunks
Greetings! I have several large data sets of animal movements. Their pauses (zero magnitude vectors) are of particular interest in addition to the speed distributions that precede the periods of rest. Here is an example of the kind of data I am interested in analyzing: x <- abs(c(rnorm(2),replicate(3,0),rnorm(4),replicate(5,0),rnorm(6),replicate(7,0))) length(x) This example has 27 elements with strings of zeroes (pauses) situated among the speed values. Is there a way to split the vector into zero and nonzero chunks and store them in a form where they can be analyzed? I have tried various forms of split() to no avail. Thank you! Salvatore A. Sidoti __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Nested Avova: Unequal # of Observations
I have two experimental groups (treatment & control) with 6 sets of observations nested within each group. The number of observations in each set is not equal. How do I set up a such an ANOVA in R? Thank You! Salvatore Sidoti PhD Student Graduate Teaching Assistant [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Hexbin: Counting Bins That Meet Certain Criteria
Thank you, David! I adapted this code and it works very nicely with my data. Just to give you a bit of background, I am a behavioral ecologist. I am currently studying the general search patterns of wolf spiders and I have a lot of tracking data to process. I am not a coder, although I am slowing becoming one out of necessity! I created a new post today, so everyone should be seeing it shortly... Salvatore A. Sidoti PhD Student Graduate Teaching Assistant -Original Message- From: David L Carlson [mailto:dcarl...@tamu.edu] Sent: Tuesday, December 15, 2015 12:18 PM To: Sidoti, Salvatore A. <sidoti...@buckeyemail.osu.edu>; r-help@r-project.org Subject: RE: Hexbin: Counting Bins That Meet Certain Criteria Something like > library(hexbin) > set.seed(42) > xy <- matrix(rnorm(1000), 500) > xy.hex <- hexbin(xy) > table(xy.hex@count) 1 2 3 4 5 6 7 8 159 60 33 16 6 1 2 1 > sum(xy.hex@count >= 3) [1] 59 - David L Carlson Department of Anthropology Texas A University College Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Sidoti, Salvatore A. Sent: Monday, December 14, 2015 6:49 PM To: r-help@r-project.org Subject: [R] Hexbin: Counting Bins That Meet Certain Criteria Greetings! Is there a way to count the bins in a hexbin plot that meet certain criteria? For instance, what if I wanted to count the bins (hexes) that have a datapoint density of some number x? Thank you! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Converting from Continuous 2D Points to Continuous 2D Vectors
Greetings! I have a fairly large dataframe (df) with pathing information in the form of continuous x,y coordinates: df$x df$y With these data, I would like to: 1. Calculate a set of continuous vectors 2. Determine the angle between each of these vectors (in degrees) 3. Count the number of angles in the dataframe that meet a certain threshold (i.e. <90°) Here's what I've come up with so far: ### Function that calculates the angle between two vectors in 2D space: angle <- function(x,y){ # x and y are vectors dot.prod <- x%*%y norm.x <- norm(x,type="2") norm.y <- norm(y,type="2") theta <- acos(dot.prod / (norm.x * norm.y)) (180*as.numeric(theta))/pi # returns the angle in degrees } ### Test the function: x <- as.matrix(c(2,1)) y <- as.matrix(c(1,2)) angle(t(x),y) [1] 36.8699 Thank you! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Hexbin: Counting Bins That Meet Certain Criteria
Greetings! Is there a way to count the bins in a hexbin plot that meet certain criteria? For instance, what if I wanted to count the bins (hexes) that have a datapoint density of some number x? Thank you! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.