similar to: Cannot grasp how to apply "by" here...

Displaying 20 results from an estimated 1000 matches similar to: "Cannot grasp how to apply "by" here..."

2008 Jan 07
3
Polynomial fitting
I wonder how one in R can fit a 3rd degree polynomial to some data? Say the data is: y <- c(15.51, 12.44, 31.5, 21.5, 17.89, 27.09, 15.02, 13.43, 18.18, 11.32) x <- seq(3.75, 6, 0.25) And resulting degrees of polynomial are: 5.8007 -91.6339 472.1726 -774.2584 THanks in advance! -- Jonas Malmros Stockholm University Stockholm, Sweden
2007 Oct 27
3
How to make own function load automatically on startup
Dear list members, I have written a function, called say Analysis. I supply an Excel file name as an argument, it does analysis on this file and returns a pdf file with specific plots, and a text file with several statistical models' output (I extract certain values from the output and create my own custom dataframe with output). As of now I have to open the script file and load the function
2008 Mar 19
3
How to remove double loop?
Bill, Alberto, Gabor, Thank you for answering my question. Now I learned about outer() function. That was a straightforward example. But what if I had a matrix, where the last column was filled with values first (again, a for loop), and the rest was filled by using a double loop? OVal <- matrix(0, n+1, n+1) for(i in 0:n){ OVal[i+1, n+1] <- max(Val[i+1, n+1]-K, 0) } for(i in seq(n,1,
2007 Nov 13
1
Cleaning database: grep()? apply()?
Dear R users, I have a huge database and I need to adjust it somewhat. Here is a very little cut out from database: CODE NAME DATE DATA1 4813 ADVANCED TELECOM 1987 0.013 3845 ADVANCED THERAPEUTIC SYS LTD 1987 10.1 3845 ADVANCED THERAPEUTIC SYS LTD 1989 2.463 3845 ADVANCED THERAPEUTIC SYS LTD 1988 1.563 2836 ADVANCED TISSUE
2007 Dec 17
1
How to create a mixed col.names?
Hello, I have a vector of names, say : names <- c("Factor 1", "Factor 2", Factor 3") I am creating a dataframe and I want the column names to be mixed like this: "Factor 1" " Sign Factor 1" "Factor 2" "Sign Factor 2" "Factor 3" "Sign Factor 3" How can I automate the creation of such a mixed vector? I tried
2013 Feb 25
3
How to plot 2 continous variables on double y-axis with 2 factors: ggplot2, gplot, lattice, sciplot?
Hi, I have a data set with two continous variables that I want to plot MEANS (I am not intrerested in median values) on a double-y graph. I also have 2 factors. I want the factor combinations plotted in different panes. Dummy dataset: mydata <- data.frame(factor1 = factor(rep(LETTERS[1:3], each = 40)), factor2 = factor(rep(c(1:4), each = 10)), y1 =
2007 Oct 31
1
textplot() in gplots causes problems (0x9)
Hello, I am using textplot function in gplots package to put some model output inside a PDF file, but it does not seem to work properly with PDF. I am doing follwing: pdf(file="C:/...", paper="a4", width=8, height=12) .model <- lm(.model.formula, data=database) textplot(capture.output(summary(.model)), valign="top", halign="left") I am getting these
2013 Mar 07
3
ggpliot2: reordering of factors in facets facet.grid(). Reordering of factor on x-axis no problem.
Hi everyone (again), before you all start screaming that the reordering of factors has been discusse on several threads and is not particular to ggplot2, hear me out. I can easily reorder my x-axis factor in facet.grid() in ggplot2. What I cannot reorder are the factors represented on the strips. I can see that the graphs are changing, so I am afraid of what it is I am doing. Why is ggplot2
2013 Mar 06
6
Ggplot2: Moving legend, change fill and removal of space between plots when using grid.arrange() possible use of facet_grid?
Hi, # For publications, I am not allowed to repeat the axes. I have tried to remove the axes using: # yaxt="n", but it did not work. I have not understood how to do this in ggplot2. Can you help me? # I also do not want loads of space between the graphs (see below script with Dummy Data). # If I could make it look like the examples on the (nice) examples page: #
2009 Nov 08
3
MCMC gradually slows down
Hello, I have written a simple Metropolis-Hastings MCMC algorithm for a binomial parameter: MHastings = function(n,p0,d){ theta = c() theta[1] = p0 t =1 while(t<=n){ phi = log(theta[t]/(1-theta[t])) phisim = phi + rnorm(1,0,d) thetasim = exp(phisim)/(1+exp(phisim)) r = (thetasim)^4*(1-thetasim)^8/(theta[t]^4*(1-theta[t])^8) if(runif(1,0,1)<r){ theta[t+1] = thetasim }
2008 Mar 19
3
How to remove double for loop?
Hello everyone. I use double for loops to fill in matrices, but there are surely better (and computationally faster) ways to perform that task. Could someone show me, given the following example of a double for loop, how this could be done? It is much easier to learn by examples. Val <- matrix(0, nrow=n+1, ncol=n+1) for( i in 0:n){ for(j in 0:i){ Val[j+1, i+1] <- u^j*d^(i-j)
2007 Jan 14
4
Controlling size of boxplot when it is added in a plot
Greetings, I am trying to add a boxplot to the bottom of a histogram, right between the histogram bars and the x axis. Here is the code I am using at the moment (the par line is probably not relevant for our discussion): hs <- hist(x, breaks = 20, plot = F) par(mar = c(3,3,2,1)) hist(x, breaks = 20, main = NULL, ylim = c(-2, max(hs$counts))) boxplot(x, horizontal = T, axes = T, add =
2009 Dec 11
3
Correcting for missing data combinations
I can think of many brute-force ways to do this outside of R, but was wondering if there was a simple/elegant solution within R instead. I have a table that looks something like the following: Factor1 Factor2 Value A 11/11/2009 5 A 11/12/2009 4 B 11/11/2009 7 B 11/13/2009 8 >From that I need to generate all permutations of Factor1 and Factor2 and force a 0 for any combination that doesn?t
2002 Nov 29
2
Obtaining the variable names of a glm object
Is names(model1$coef) what you're looking for? -----Original Message----- From: Kenneth Cabrera [mailto:krcabrer at epm.net.co] Sent: 29 November 2002 10:36 Cc: R-help at stat.math.ethz.ch Subject: [R] Obtaining the variable names of a glm object Hi, R users! Suppose I make a model like this:
2003 Mar 06
6
type III Sum Sq in ANOVA table - Howto?
Hello, as far as I see, R reports type I sums of squares. I'd like to get R to print out type III sums of squares. e.g. I have the following model: vardep~factor1*factor2 to get the type III sum of squares for factor1 I've tried anova(lm(vardep~factor2+factor1:factor2),lm(vardep~factor1*factor2)) but that didn't yield the desired result. Could anyone give me a hint how to proceed?
2004 Jul 29
2
aov for unbalanced design (PR#7144)
Full_Name: Tanya Logvinenko Version: 1.7.0 OS: Windows 2000 Submission from: (NULL) (132.183.156.125) For unbalanced design, I ran into problem with ANOVA (aov function). The sum of squares for only for the second factor and total are computed correctly, but sum of squares for the first factor is computed incorreclty. Changing order of factors in the formula changes the ANOVA table. For the
2010 Jan 12
3
How to get minimum value by group
I'd like to get a long data set of minimum values from groups in another data set. The following almost does what I want. (Note, I'm using the word factor differently from it's meaning in R; bad choice of words) myframe = data.frame(factor1 = rep(1:2,each=8), factor2 = rep(c("a","b"),each=4, times=2), factor3 = rep(c("x","y"),each=2, times=4),
2010 Jun 06
1
Why did TukeyHSD not work when I used it for post-hoc for 2way within-subjects anova?
Dear R people, I have a couple of questions about post-doc analyses for 2 by 2 within subjects ANOVA. I conducted a psycholinguistic study that combined a 2 by 2 design and a latin square design. Specifically, I had 32 items each of which generated 4 conditions. Participants saw each of the 32 items only once: 8 in Condition A, 8 in B, 8 in C, and 8 in D. The table below serves as an example.
2009 Dec 08
1
{Lattice} help.
Hi All, I have a 4-dimensional data. I'm using barchart() function from lattice package. The R code and data are below - code includes one for stack=TRUE and other for stack=FALSE. I would like to present the data in another form which would be plotting Factor3 levels (P, Q, R, S) as two stacked bars (side by side). Like, for each level of Factor1 there should be two bars: first bar showing
2009 Jul 30
3
What is the best method to produce means by categorical factors?
I am attempting to replicate some of my experience from SAS in R and assume there are best methods for using a combination of summary(), subset, and which() to produce a subset of mean values by categorical or ordinal factors. within sas I would write proc means mean data=dataset; class factor1 factor2 var variable1 variable2; RUN; producing an output with means for each variable by factor