[R] hierarchical model with heteroscedastic variances

2014-12-01 Thread Rafael Moral
Dear useRs,I have been wondering whether it would be possible to fit a linear mixed model including heteroscedastic variances for a 2-level hierarchical study with subsampling.Suppose that I had three levels for the first hierarchical level and 4 for the second, with 2 subsamples, e.g.

[R] changing model matrix restriction in lm()

2013-10-23 Thread Rafael Moral
Dear useRs, I was wondering if there was a way of changing the model matrix restriction automatically in the formula statement when fitting a model using, for example, lm(). When we do set.seed(100) y - rnorm(12) A - gl(3, 4) summary(lm(y ~ A)) we obtain A1=0 as a baseline and A2 and A3 as

Re: [R] changing model matrix restriction in lm()

2013-10-23 Thread Rafael Moral
, 11:29 ?contrasts ?C Cheers, Bert On Wed, Oct 23, 2013 at 6:00 AM, Rafael Moral wrote: Dear useRs, I was wondering if there was a way of changing the model matrix restriction automatically in the formula statement when fitting a model using, for example, lm(). When we do

[R] 2 plots with different scales in the same graphical window

2010-12-09 Thread Rafael Moral
Dear useRs, I have two sets of data that I would like to plot in the same window, but their ranges are really different, e.g. a - c(0.2, 0.5, 0.8, 0.3, 0.4, 0.5, 0.2, 0.2, 0.3) b - c(100, 2000, 800, 200, 100, 50, 4, 2, 0) If I do plot(a, ty='l'); points(b, ty='l') I won't be able to see

[R] confidence intervals for mean (GLM)

2010-01-22 Thread Rafael Moral
Dear useRs, How could I obtain the confidence intervals for the means of my treatments, when my data was fitted to a GLM? I need the CI's for the Poisson and Negative Binomial distributions. Here's what I have: mydata1 - data.frame('treatments'=gl(4,20), 'value'=rpois(80, 1)) model1 -

[R] splitting a factor in an analysis of deviance table (negative binomial model)

2010-01-19 Thread Rafael Moral
Dears useRs, I have 2 factors, (for the sake of explanation - A and B), with 4 levels each. I've already fitted a negative binomial generalized linear model to my data, and now I need to split the factors in two distinct analysis of deviance table:  - A within B1, A within B2, A within B3 and A

[R] help with for loop

2010-01-01 Thread Rafael Moral
Dear useRs, I want to write a function that generates all the possible combinations of diff(). Example: If my vector has length 5, I need the diff() until lag=4 - c(diff(my.vec), diff(my.vec, lag=2), diff(my.vec, lag=3), diff(my.vec, lag=4)) If it has length 4, I need until lag=3 -

[R] Res: how to create three new variables? Thanks a lot!

2009-12-20 Thread Rafael Moral
Hello! Here is a way: mydata - data.frame(third_before=c(6,10), second_before=c(9,10), first_before=c(10,8)) mydata   third_before second_before first_before 1    6 9   10 2   10    10    8 And if you already have a dataset and wants only

[R] Conditional statement

2009-11-16 Thread Rafael Moral
Dear useRs, I wrote a function that simulates a stochastic model in discrete time. The problem is that the stochastic parameters should not be negative and sometimes they happen to be. How can I conditionate it to when it draws a negative number, it transforms into zero in that time step? Here

[R] fit an exponential curve

2009-10-26 Thread Rafael Moral
Dear useRs, I have the following plot: pos - c(27/44, 11/32, 8/40, 4/42, 3/40, 4/40, 2/40) tmin - c(15.8, 12.6, 10.5, 2.4, 5.2, 8.5, 7.9) plot(tmin, pos) I would like to fit an exponential curve to it. How could I be able to do this? Thanks in advance, Rafael.

[R] simulating a model

2009-09-24 Thread Rafael Moral
Dear useRs, I have written an ecological model, based on the epidemiology SIR model. I've been trying to simulate it in R. However, I can't simulate it properly. Two guesses: my script isn't right; I'm not setting the parameters properly I have uploaded an image to the model here:

[R] barplot with lines instead of bars

2009-09-08 Thread Rafael Moral
Dear useRs, I want to plot the following barplot with lines instead of bars. Is there a way? data - data.frame(cbind(k = 0:3, fk = c(11, 20,7,2), f0k = c(13.72, 17.64, 7.56, 1.08), fkest = c(11.85, 17.78, 8.89, 1.48))) d - t(data[,2:4]) barplot(d, beside=TRUE) Regards, Rafael.

[R] model simulation

2009-09-07 Thread Rafael Moral
Dear useRs, Is there a package or a function able to simulate models with sets of differential equations? Where we could input our model and give R some value to start with and it would generate the graphs? Regards, Rafael.

[R] categorized barplot

2009-08-20 Thread Rafael Moral
Dear useRs, I can't seem to find out how to categorize my histogram. I have the following dataset: Time    First.day  Second.day 08:00-10:00    9     8 10:00-12:00   13   15 12:00-14:00    9     9 14:00-16:00   10    9 I attached a jpeg

[R] categorized barplot

2009-08-20 Thread Rafael Moral
Sorry for the double post, I couldn't attach the image in the previous one, so I uploaded it to imageshack, the link is http://img32.imageshack.us/img32/2042/imageyvh.jpg Thanks! Dear useRs, I can't seem to find out how to categorize my histogram. I have the following dataset: Time   

[R] line plot

2009-08-19 Thread Rafael Moral
Dear useRs, How can I draw a barplot, but instead of bars, I'd get lines? Thanks, Kind regards, Rafael. [[elided Yahoo spam]] [[alternative HTML version deleted]]

[R] math expressions in graphs

2009-07-13 Thread Rafael Moral
Dear useRs, I want to put a math expression in the ylab in my plot which should be a Delta and a 'y' with a trace and a hat above it and a 't' as subscription. How could I manage to do it? Thanks in advance, Regards, Rafael.

[R] Mann-Kendall test

2009-05-13 Thread Rafael Moral
Dear useRs, I've been trying to run a Mann-Kendall test in my data in order to detect trends. I studied the examples given at the Kendall package and I can understand pretty well how it works on time-series data. However, my data consists of values in different sites per year, as I display

[R] help with loop

2009-03-12 Thread Rafael Moral
Dear useRs, I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. So, I wrote something like this:   c - list()   for(i in 1:ncol(mydata)) {   for(j in 2:nrow(mydata)) {   c[[i]] -