Re: [R] scatterplot to boxplot translation?

2011-12-09 Thread Tom Fletcher
You need to create some grouping for your cut points (0-100, etc). 

See ?cut

Then, you can use boxplot and formula (y ~ NEWVARIABLE from cut) 
boxplot(y ~ cut(x)) 

There may be other ways to do this, but the above should work.

TF

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Vining, Kelly
Sent: Friday, December 09, 2011 1:11 PM
To: Vining, Kelly; r-help@r-project.org
Subject: Re: [R] scatterplot to boxplot translation?

My apologies if anyone is seeing this twice...looks like my previous message 
didn't come through...

Dear UseRs,
I have a feeling this is a relatively simple question, but I'm having a hard 
time getting my head around it. I have a simple x-y scatterplot with many 
points, as shown below(attached). I'd like to make a boxplot of this by 
interval, such that there is one box representing the points in the 0-100 
interval, one for the 101-200 interval, and so on. How do I structure my R data 
frame to be able to generate such a boxplot?


From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Vining, Kelly
Sent: Friday, December 09, 2011 11:01 AM
To: r-help@r-project.org
Subject: [R] scatterplot to boxplot translation?

__
R-help@r-project.org mailing list
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] annotate histogram

2011-11-01 Thread Tom Fletcher
See rug() and use col=2 to get red. So, as an example ...

x - rchisq(100, df=2)
hist(x)
abline(v=median(x), lty=2)
rug(x, col=2)

TF

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Wendy
Sent: Tuesday, November 01, 2011 10:22 AM
To: r-help@r-project.org
Subject: [R] annotate histogram

Hi all,

I want to make a histogram like the one show 
http://nar.oxfordjournals.org/content/39/suppl_1/D1011/F1.expansion.html
here , but I did not figure out how to add the red marks at the bottom of the 
bars. Could anybody help? Thank you very much

--
View this message in context: 
http://r.789695.n4.nabble.com/annotate-histogram-tp3963960p3963960.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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
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] misclassification matrix

2010-10-06 Thread Tom Fletcher
I think what you are looking for is 

?table
and/or 
?prop.table 

So, let's say you have two matrices: ACTUAL and CLASS, you can ...

table(ACTUAL, CLASS)



Or, diag(1-prop.table(table(ACTUAL, CLASS), 1)) to get row percentages
and take the diagonal.

So, using your example:

# table() as above would render the following matrix
mat - matrix(c(100, 25, 10, 250, 100, 5, 50, 25, 40), 3)

and prop.table() renders:

 prop.table(mat, 1)
  [,1]  [,2]  [,3]
[1,] 0.250 0.625 0.125
[2,] 0.167 0.667 0.167
[3,] 0.1818182 0.0909091 0.7272727

In the above, the diagonal is the % correctly classified. 

 diag(1-prop.table(mat, 1))
[1] 0.750 0.333 0.2727273


TF



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Gregory Ryslik
Sent: Wednesday, October 06, 2010 10:19 AM
To: R Help
Subject: [R] misclassification matrix

HI Everyone,

I am working with the following situation. I have n observations and j
possible outcomes and each one of the n observations is assigned a class
from 1 to j.  Furthermore, this process is done m times (for some large
m  1000). 

What I want to do is create a misclassification matrix which tells me
for each one of the possible classes, how many observations were
classified correctly, and then how many were incorrectly at each level.
Here is an example of what I mean

0   12  Misclassification 
0 100 250  50   .75
1   25  100 25  .33
2   10  5   40   .2727273


For each one of the 1 to j elements, I can use a nested for loop to
count how many were classified as 0, are in 1, etc and then construct
such matrix. Thus for each element I have j comparisons and then I have
j total rows leading to an O(j^2) running time.

 Any way I can avoid such a for loop and perhaps make it run a bit
quicker? If not, any ideas then at least how to avoid the double for
loop and make the code more aesthetically pleasing?

As always, thank you for your help!

Kind regards,
Greg
__
R-help@r-project.org mailing list
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
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] does package QuantPsych function lm.beta can handle resultsof a regression with weights?

2010-07-26 Thread Tom Fletcher
The original function was created for a simple example. It never was
written to address weighted regression. A quick fix will work for you
situation.

### The original is:


lm.beta -
function (MOD) 
{
b - summary(MOD)$coef[-1, 1]
sx - sd(MOD$model[-1])
sy - sd(MOD$model[1])
beta - b * sx/sy
return(beta)
}

  A newer modification:

lm.betaW - 
function (MOD) 
{
b - summary(MOD)$coef[-1, 1]
sx - sd(MOD$model[-1][1])
sy - sd(MOD$model[1])
beta - b * sx/sy
return(beta)
}

The above should do the trick.

TF

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Dimitri Liakhovitski
Sent: Thursday, July 22, 2010 12:35 PM
To: r-help@r-project.org
Subject: [R] does package QuantPsych function lm.beta can handle
resultsof a regression with weights?

Hello, and sorry for not providing an example.
I run a regular linear regression (using lm) and use weights with it
(weights = ...).
I use QuantPsych package, its function lm.beta to extract standardized
regression weights from my lm regression object.

When I don't use weights, everything is fine.
But when I do use weights, I get an error that refers to lm.beta code:
In b * sx : longer object length is not a multiple of shorter object
length

This happens because there is an extra column in the object:
regr$model that lm.beta is using to get at the betas.
Is there some other package that just gives me the standardized
regression weights - even if I used weights for regression?

Thank you!

--
Dimitri Liakhovitski
Ninah Consulting
www.ninah.com

__
R-help@r-project.org mailing list
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
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] The output of script is hidden in console

2010-01-05 Thread Tom Fletcher
There are probably numerous ways, but one is to add print() to the
functions that you wish to display in the console. 

For example, in your source file, 

Instead of 
summary(x) 

try

print(summary(x))

This should do the trick. 

Tom Fletcher



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of vtvdung
Sent: Tuesday, January 05, 2010 9:42 AM
To: r-help@r-project.org
Subject: [R] The output of script is hidden in console


Hi everyone,
I execute a script with
source(filename)
The script has effect but i don't see the output on console screen.Why?
I'm a newbie. Thanks :handshake:
-- 
View this message in context:
http://n4.nabble.com/The-output-of-script-is-hidden-in-console-tp999095p
999095.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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
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] Creating Dummy Variables in R

2009-12-16 Thread Tom Fletcher
Is your variable Clarity a categorical with 4 levels? Thus, the need for
k-1 (3) dummies? Your error may be the result of creating k instead of
k-1 dummies, but can't be sure from the example.

In R, you don't have to (unless you really want to) explicitly create
separate variables. You can use the internal contrast functions. 

See

?contr.treatment

Which is dummy coding by default. You can specify which group is the
reference group. 

Alternatively, if you prefer effects coding, you can see
?contr.sum 

There are others as well. 

Tom Fletcher



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of whitaker m. (mw1006)
Sent: Wednesday, December 16, 2009 8:59 AM
To: r-help@r-project.org
Subject: [R] Creating Dummy Variables in R

Hi,
I am trying to create a set of dummy variables to use within a multiple
linear regression and am unable to find the codes within the manuals.

For example i have:
Price Weight Clarity
 IF  VVS1VVS2
5008 1 0  0
1000  5.2  0 0  1
8643  01  0
3402.6  0 0  1
90  0.5  1 0  0 
4502.3  0 1  0

Where price is dependent upon weight (single value in each observation)
and clarity (split into three levels, IF, VVS1, VVS2).
I am having trouble telling the program that clarity is a set of 3 dummy
variables and keep getting error messages, what is the correct way?

Any helps is greatly appreciated.
Matthew

__
R-help@r-project.org mailing list
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
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] How to calculate the area under the curve

2009-10-22 Thread Tom Fletcher
See package ROCR. Then see ?performance; in the details, it describes a
measure of auc.

Tom Fletcher



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of olivier.abz
Sent: Thursday, October 22, 2009 9:23 AM
To: r-help@r-project.org
Subject: [R] How to calculate the area under the curve


Hi all, 

I would like to calculate the area under the ROC curve for my predictive
model. I have managed to plot points giving me the ROC curve. However, I
do not know how to get the value of the area under. 
Does anybody know of a function that would give the result I want using
an array of specificity and an array of sensitivity as input?

Thanks, 

Olivier
--
View this message in context:
http://www.nabble.com/How-to-calculate-the-area-under-the-curve-tp260105
01p26010501.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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
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] ltm package error for grm (IRT)

2009-10-15 Thread Tom Fletcher
Ben,


This is because you do not have all the possible response options
represented for each item. For example, in your data below, item 2 has
no '1's. 

I don't know if there is a workaround for this (other than deleting an
item or faking a response), or if this is a function of IRT itself? 

Tom Fletcher



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of ben kelcey
Sent: Wednesday, October 14, 2009 4:32 PM
To: r-help@r-project.org
Subject: [R] ltm package error for grm (IRT)

Using the grm function (graded response IRT model) in the ltm package I
receive the following error:

Error: subscript out of bounds

for several scales I'd like to examine. Here's a small example that if
run a few times will likley produce the error at least once

 ch-array(round(runif(50,1,5)),c(10,5))
grm(ch,start.val=random)
## or
grm(ch,constrained=F,IRT.param=T,start.val=random)

I have cannot figure out where I have gone wrong and was unable to find
mention of similar errors in the archives. Any help would be much
appreciated. A subset of my actual data that produces the same error is
pasted below

Thank you,
ben

  t2_sr1 t2_sr2 t2_sr3 t2_sr4 t2_sr5
  1  5  1  5  5
  1  4  1  4  4
  4  2  4  2  1
  4  5  4  1  4
  1  5  5  1  5
  1  4  1  5  5
  3  2  4  2  4
  5  3  5  1  1
  4  2  4  4  2
  1  4  1  4  5
  2  4  4  4  2
  1  4  2  3  4
  2  2  4  3  2
  2  4  2  3  3
  4  3  2  3  3
  2  5  2  5  5
  1  4  1  4  4
  3  3  2  3  4
  2  4  2  3  4
  3  3  3  2  2


 sessionInfo()
R version 2.9.2 (2009-08-24)
i386-pc-mingw32
locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached
base packages:
[1] splines   stats graphics  grDevices utils datasets  methods
base
other attached packages:
 [1] car_1.2-16  epicalc_2.9.2.7 survival_2.35-4 foreign_0.8-37
faraway_1.0.4
 [6] ltm_0.9-1   polycor_0.7-7   sfsmisc_1.0-8   mvtnorm_0.9-7
msm_0.9.3
[11] MASS_7.2-48
loaded via a namespace (and not attached):
[1] tools_2.9.2

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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
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] trouble printing from graphics device in R 2.7.2

2008-09-17 Thread Tom Fletcher
Is there a setting change (or other minor fix) that can be done without
an install of either the patched or development versions to address the
printing issue described below. It is my understanding that these
versions are 'source code' and not compiled for 'easy' installation. 

Thanks
Tom

 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Jenny Drnevich
Sent: Tuesday, September 16, 2008 8:47 AM
To: Prof Brian Ripley
Cc: r-help@r-project.org
Subject: Re: [R] trouble printing from graphics device in R 2.7.2

Thank you! It works now. It's good to know that it was a bug and not
something stupid that I was doing.

Cheers,
Jenny

At 01:32 PM 9/12/2008, Prof Brian Ripley wrote:
I've tracked this down to the clipping bug fix reported in the CHANGES 
file.  There is another bug fix in R-devel that does not affect 
printing, so your first option is to use one of the R-devel snapshots 
on CRAN.

I'll move the R-devel fix to R-patched shortly, so tonight's R-patched 
snapshot should also work.

On Wed, 10 Sep 2008, Jenny Drnevich wrote:

Hi,

I've been using R for many years and have always tried to keep my R 
version up to date, and when I switched from 2.7.1 to 2.7.2 I'm 
suddenly having trouble printing from the graphics device. I have 
Windows XP, and installed both versions of R from the binaries. If I 
start 2.7.2 and simply do:

plot(1:10)

the default R Graphics Device window opens as usual. However, when I 
use the menu in that window to File - Print, the graph that is 
printed is cut off below ~2 on the y-axis and ~10 on the x-axis if I 
don't resize the Graphics window; resizing the window bigger does 
result in more of the graph printed, but it's still cut off on the 
y-axis. Everything prints fine in R 2.7.1 (sessionInfo()s below), and 
all other versions of R I've had on this exact same computer for the 
last 3 years printing to the same printer, which is why I think it's 
something with R 2.7.2. I even tried un-installing and re-installing 
2.7.2, but the problem persisted. Using the menu to save the graphic 
in various formats seems to work fine - the entire graph is visible in

the .png, .pdf, etc. files. I didn't see anything in the changes or 
the archives about this... so what's going on and how do I fix it so I

can continue to use 2.7.2?

Thanks,
Jenny


sessionInfo()
R version 2.7.2 (2008-08-25)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base


sessionInfo()
R version 2.7.1 (2008-06-23)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base


Jenny Drnevich, Ph.D.

Functional Genomics Bioinformatics Specialist W.M. Keck Center for 
Comparative and Functional Genomics Roy J. Carver Biotechnology Center

University of Illinois, Urbana-Champaign

330 ERML
1201 W. Gregory Dr.
Urbana, IL 61801
USA

ph: 217-244-7355
fax: 217-265-5066
e-mail: [EMAIL PROTECTED]

__
R-help@r-project.org mailing list
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.

--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org mailing list
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
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.