Displaying 20 results from an estimated 10000 matches similar to: "Conditional correlation in R?"
2012 Apr 25
1
recommended way to group function calls in Sweave
Dear all
When using Sweave, I'm always hitting the same bump: I want to group
repetitive calls in a function, but I want both the results and the
function calls in the printed output. Let me explain myself.
Consider the following computation in an Sweave document:
summary(iris[,1:2])
cor(iris[,1:2])
When using these two calls directly, I obtain the following output:
> summary(iris[,1:2])
2007 Dec 03
1
cor(data.frame) infelicities
In using cor(data.frame), it is annoying that you have to explicitly
filter out non-numeric columns, and when you don't, the error message
is misleading:
> cor(iris)
Error in cor(iris) : missing observations in cov/cor
In addition: Warning message:
In cor(iris) : NAs introduced by coercion
It would be nicer if stats:::cor() did the equivalent *itself* of the
following for a data.frame:
2007 Sep 19
2
By() with method = spearman
I have a data set where I want the correlations between 2 variables
conditional on a students grade level.
This code works just fine.
by(tmp[,c('mtsc07', 'DCBASmathscoreSPRING')], tmp$Grade, cor,
use='complete', method='pearson')
However, this generates an error
by(tmp[,c('mtsc07', 'DCBASmathscoreSPRING')], tmp$Grade, cor,
use='complete',
2006 Oct 26
2
distance between legend title and legend box
Hi,
I've looked at the parameters available for the legend function and
cannot find a way to change the distance between the top of the box
surrounding a legend and the legend's title. I have a math expression
that raises the height of my title.
If you don't mind the non-sensical title I give to the legend for
this plot (Figure 3.20 in R Graphics):
with(iris,
2013 Mar 02
2
Multiple left hand side variables in a formula
The lattice package uses special logic to allow for multiple left-hand-side
variables in a formula, e.g. y1 + y2 ~ x. Is there an elegant way to do
this outside of lattice? I'm trying to implement a data summarization
function that logically takes multiple dependent variables. The usual
invocation of model.frame( ) causes R to try to do arithmetic addition to
create a single dependent
2006 Sep 17
2
histogram frequency weighing
Fellow R-helpers,
Suppose we create a histogram as follows (although it could be any vector
with zeroes in it):
R> lenh <- hist(iris$Sepal.Length, br=seq(4, 8, 0.05))
R> lenh$counts
[1] 0 0 0 0 0 1 0 3 0 1 0 4 0 2 0 5 0 6 0 10 0 9 0 4 0
[26] 1 0 6 0 7 0 6 0 8 0 7 0 3 0 6 0 6 0 4 0 9 0 7 0 5
[51] 0 2 0 8 0 3 0 4 0 1 0 1 0 3
2008 Feb 27
2
multiple plots per page using hist and pdf
Hello,
I am puzzled by the behavior of hist() when generating multiple plots
per page on the pdf device. In the following example two pdf files
are generated. The first results in 4 plots on one pdf page as
expected. However, the second, which swaps one of the plot() calls
for hist(), results in a 4 page pdf with one plot per page.
How might I get the histogram with 3 other scatter
2008 Oct 13
2
split data, but ensure each level of the factor is represented
Hello,
I'll use part of the iris dataset for an example of what I want to
do.
> data(iris)
> iris<-iris[1:10,1:4]
> iris
Sepal.Length Sepal.Width Petal.Length Petal.Width
1 5.1 3.5 1.4 0.2
2 4.9 3.0 1.4 0.2
3 4.7 3.2 1.3 0.2
4 4.6 3.1 1.5
2006 May 31
2
a problem 'cor' function
Hi list,
One of my co-workers found this problem with 'cor' in his code and I confirm it too (see below). He's using R 2.2.1 under Win 2K and I'm using R 2.3.0 under Win XP.
===========================================
> R.Version()
$platform
[1] "i386-pc-mingw32"
$arch
[1] "i386"
$os
[1] "mingw32"
$system
[1] "i386, mingw32"
$status
2010 Jun 09
4
question about "mean"
Hi there:
I have a question about generating mean value of a data.frame. Take
iris data for example, if I have a data.frame looking like the following:
---------------------
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4
0.2 setosa
2 4.9 3.0 1.4
0.2
2013 Jan 16
4
Get a percent variable based on group
Dear all, I'd like to get a percentage variable based on a group, but without creating a new data frame.
For example:
data(iris)
iris$percent <-unlist(tapply(iris$Sepal.Length,iris$Species,function(x) x/sum(x, na.rm=TRUE)))
This does not work, I should have only three standard values, respectively for setosa, versicolor, and virginica. How can I do this?
MANY THANKS,
Karine
2010 Nov 24
3
Límites de confianza de la mediana en distribuciones simétricas
Por si alguno pudiera ayudarme.
Al realizar el t.test para una muestra, junto con el valor de t y el
p-valor, la función proporciona la estimación de la media y su INTERVALO
DE CONFIANZA.
Desde el punto de vista de la estadística de rangos esto se puede hacer
mediante:
> iris$MEDIANA <- with(iris, 2.95)
> median(iris$Sepal.Width - iris$MEDIANA, na.rm=TRUE) # median difference
[1]
2008 Dec 01
1
request: how to assign alphabets to integer values
Dear R community
I am trying to assign alphabets to integer values 1, 2, 3 etc. in y given below. Can any body suggest some simple way to do the same job?
ds=iris; dl=nrow(ds)
c1=ds[,1]; c2=ds[,2]; c3=ds[,3]; c4=ds[,4]; c5=ds[,5]; iris=cbind(c1,c2,c3,c4,c5)
y=iris[,5]
y1=which(y==1); y[y1] <- c("a"); y2=which(y==2); y[y2] <- c("b"); y3=which(y==3); y[y3] <-
2007 Oct 09
2
lattice/xyplot: horizontal y-axis labels with scales(relation="free")
I would like to create an xyplot with varying y-axis limits and horizontal labels at the y-axis tickmarks.
The following does not seem to work, although I think it should, going by the documentation for par.
R version 2.5.1, Windows XP Prof.
Thanks for a clue.
Andreas Krause
library(lattice)
# axis labels for y-axis are horizontal
xyplot(Sepal.Length ~ Sepal.Width | Species, data=iris)
#
2011 Jul 28
2
not working yet: Re: lattice overlay
Hi Dieter and R community:
I tried both of these three versions with ylim as suggested, none work: I
am getting only single (pch = 16) not overlayed (pch =3) everytime.
*vs 1*
require(lattice)
xyplot(Sepal.Length ~ Sepal.Width | Species , data= iris,
panel= function(x, y, subscripts) {
panel.xyplot(x, y, pch=16, col = "green4", ylim = c(0, 10))
panel.lmline(x, y, lty=4, col =
2009 Apr 08
2
Doubt about aov and lm function... bug?
Hi,
The below very strange:
# a) aov function
av <- aov(Sepal.Length ~ Species, data=iris)
# Error in parse(text = x) :
# unexpected symbol in "Sepal(Sepal.Length+Species)Length"
av <- aov(iris[, 1] ~ iris[, 5])
# summary(av)
# Df Sum Sq Mean Sq F value Pr(>F)
# iris[, 5] 2 63.2 31.6 119 <2e-16 ***
# Residuals 147 39.0 0.3
# ---
2012 Jul 10
3
fill 0-row data.frame with 1 line of NAs
Dear all
Is there a simpler method to achieve the following: When I obtain an
empty data.frame after subsetting, I need for it to contain one line
of NAs. Here's a dummy example:
> (.xb <- iris[ iris$Species=='zz', ])
[1] Sepal.Length Sepal.Width Petal.Length Petal.Width Species
<0 rows> (or 0-length row.names)
> dim(.xb)
[1] 0 5
> (.xa <-
2005 Sep 16
6
How do I get the row indices?
Hi,
I was wondering if it's possible to get the row
numbers from a filtering. Here's an example:
# give me the rows with sepal.length == 6.2
iris[(iris[,1]==6.2),]
# output
Sepal.Length Sepal.Width Petal.Length Petal.Width
Species
69 6.2 2.2 4.5 1.5
versicolor
98 6.2 2.9 4.3 1.3
versicolor
127 6.2
2003 Sep 09
2
lattice.xyplot: adding grid lines
Hallo,
I'd like to add grid lines to a lattice graph having 2 series of Y data.
See these 2 examples:
data(iris)
[1]
xyplot(Sepal.Length + Sepal.Width ~ Petal.Length ,
data = iris, allow.multiple = TRUE, scales = "same",type="l",
)
[2]
xyplot(Sepal.Length + Sepal.Width ~ Petal.Length ,
data = iris, allow.multiple = TRUE, scales =
2011 Aug 16
3
Newbie question - struggling with boxplots
Hopefully I will not be flamed for this on the list, but I am starting out
with R and having some trouble with combining plots.
I am playing with the famous iris dataset (checking out example dataset in R
while reading through Introduction to datamining)
What I would like to do is create three graphs (combined boxplots) besides
each other for each of the three species (Setosa, Versicolour and