Re: [R] R lapack routines cannot be loaded

2012-11-24 Thread Prof Brian Ripley
This was answered this week in 
https://stat.ethz.ch/pipermail/r-help/2012-November/329946.html


On 23/11/2012 16:05, arysar wrote:

I usually ran different statistical analysis in R with routines that
use lapack like gam() lm(), etc but after several updates of libraries
the following error appears:

library(mgcv)
This is mgcv 1.7-22. For overview type 'help(mgcv-package)'.

model - with(chlaR,gam(ClorMAX ~ s(DegDay_NM)))
Error en eigen(St, symmetric = TRUE) :
lapack routines  cannot be loaded
Además: Mensajes de aviso perdidos
In eigen(St, symmetric = TRUE) :
   unable to load shared object '/usr/lib/R/modules//lapack.so':
   /usr/lib/R/modules//lapack.so: undefined symbol: dpstrf_

model - with(chlaR,lm(ClorMAX ~ DegDay_NM))
summary(model)
Error en chol2inv(Qr$qr[p1, p1, drop = FALSE]) :
   lapack routines  cannot be loaded

The version information is:

platform i686-pc-linux-gnu
arch i686
os linux-gnu
system i686, linux-gnu
status
major 2
minor 15.2
year 2012
month 10
day 26
svn rev 61015
language R

I am using Ubuntu 12.04.1 LTS

Any ideas?

__
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,  rip...@stats.ox.ac.uk
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] How to discretize the Variance Gamma Process for stock price simulation?

2012-11-24 Thread Maximilian Lklweryc
Hi,

I want to do stock price simulation. First of all, I used the
geometric brownian motion. To simulate the values, I used not the
closed form solution for the GBM given by:

S_t=S_0*exp[(μ−σ^2)t+σWt]

but the discrete version, so I can see every day realization:

S_i+1=μΔt∗S_i+σφΔt∗S_i+S_i

Now I wanted to do the same with the variance gamma distribution model
given by:
S_T=S_0*exp((r−q)T+w+z)

but the problem is, that with this formula I can only observe the
final realizations on time point T. Not the values between. I need a
discrete version. Can you tell me which formula I have to use? Or how
can I solve this problem?

I found several papers, but I could not find a solution for my
problem, the most famous paper could be the following:
Variance-Gamma and Monte Carlo, Michael C. Fu
http://www.rhsmith.umd.edu/faculty/mfu/fu_files/Fu07.pdf

I have the implementation of the variance gamma process for the final
T values from Hull: Options Futures and Other Derivatives 7 ed page
587 the basic steps are (simplified):
1. sample gamma distributed values g
2. sample normal distributed values z with mean theta*g and standard
deviation sigma * sqrt(g)
3. put the values in the formula (calculate w before)
4. this gives the final values S_T


Thanks a lot for your help

__
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] SEM raw moment matrix

2012-11-24 Thread Maya Abou Zeid
Dear John,

Many thanks for your response.
I'd just still like to double check that I have indeed used the raw moment 
matrix method correctly in sem. In my model, some equations are in deviations 
form and have no intercept, while some have intercept.


sem.QT.1 - sem(mod.QT.1, data=QTrav, formula = ~ X1 + X2 +  + UNIT -1, 
fixed.x=c('X1','X2',...,'UNIT'), raw=TRUE)

where UNIT is a variable equal to 1 which I appended to the dataset. I used 
UNIT multiplied by a constant in the model equations that require an intercept.

I mainly wanted to check if the above specification of formula, with -1 written 
after UNIT, is correct. The model runs fine.

Thank you,
Maya


-Original Message-
From: John Fox [mailto:j...@mcmaster.ca] 
Sent: Friday, November 23, 2012 2:39 PM
To: Maya Abou Zeid
Cc: r-help@r-project.org
Subject: Re: [R] SEM raw moment matrix

Dear Maya,

sem() computes the fit statistics that I know how to compute for a model fit to 
a raw moment matrix. If you know how to compute the others (and if they're 
defined), then you could do that youself using the object returned by sem().

I'm not sure why you want the likelihood under the model in addition to the 
model chisquare, but you can get the *log*-likelihood from logLik(your.model).

Finally, you don't have to compute the raw moment matrix in a separate step (if 
you in fact did that) if you have the original data -- you can use the data 
argument to sem().

I hope this helps,
 John


John Fox
Sen. William McMaster Prof. of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/

On Fri, 23 Nov 2012 00:33:51 +0200
 Maya Abou Zeid ma...@aub.edu.lb wrote:
 Hello,
 
 I estimated a model using SEM package in R, which was fit to a raw moment 
 matrix, and includes an intercept term. The only goodness of fit statistics 
 that are output are Model Chisquare, AIC, AICc, BIC, CAIC, and normalized 
 residuals.
 
 How can I get the other goodness of fit statistics, like adjusted goodness of 
 fit, RMSEA, and R-squared? And how can I get the final value of the 
 log-likelihood of the model?
 
 Thanks,
 Maya
 
   [[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] Results displayed in Console

2012-11-24 Thread Anthony Damico
# load example linear model from ?lm
ctl - c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt - c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group - gl(2,10,20, labels=c(Ctl,Trt))
weight - c(ctl, trt)
lm.D90 - lm(weight ~ group - 1) # omitting intercept

# store the summary() output into a new variable
x - summary(lm.D90)

# access the coefficients attribute directly
x$coefficients

# or just look at the first six
head( x$coefficients )

# choose a place to store the file on your local disk
tf - c:/my directory/myfile.csv

# write the coefficients to a csv
write.csv( x$coefficients , tf )



On Fri, Nov 23, 2012 at 5:42 PM, cavan cavan.constanta...@gmail.com wrote:

 General question concerning summary results of a linear model. I've tried
 to
 look in help and search online but I either don't understand it or I can't
 find the answer.

 I've defined a model with a really large number of variables and levels.
 The
 summary results are so big that not all of the coefficients etc  can be
 displayed completely in the console. I try to scroll back and I've tried to
 'page up' but I can't seem to get to a previous page where I presume the
 'upper' missing portion of my results would be. In the meantime, I've
 reduced my model size but I would really appreciate it if I could see the
 model results for the model I really wanted to investigate.

 Please could someone tell me how to 'retrieve' my results.

 Also, is there a way to export these results into Excel?



 --
 View this message in context:
 http://r.789695.n4.nabble.com/Results-displayed-in-Console-tp4650607.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.


[[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.


Re: [R] Student-t distributed random value generation within a confidence interval?

2012-11-24 Thread Thomas Schu

allvals - rt(1000,df=11)  
## 1000 samples is overkill: slightly more than 
##500*(1.05) should be large enough
subvals - (allvals[abs(allvals)qt(0.975,df=11)])
vals lt;- m+subvals[1:500]*s/sqrt(n)

I'm subsetting before transforming, it seems slightly easier.
lt;/quote

Thank you very much bbolker. It works very well!

Best regards
Thomas



--
View this message in context: 
http://r.789695.n4.nabble.com/Student-t-distributed-random-value-generation-within-a-confidence-interval-tp4650561p4650640.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.


Re: [R] function call from another r file

2012-11-24 Thread Suzen, Mehmet
If you want to handle a generic case, best thing is to create an R
package. It is
much easier to manage that using source(), if you have lots of
different functionality
and data files. Also look at ?system.file.

On Sat, Nov 24, 2012 at 7:49 AM, Jeff Newmiller
jdnew...@dcn.davis.ca.us wrote:
 It is straightforward to load function definitions into memory using the 
 source() function.
 ---
 Jeff NewmillerThe .   .  Go Live...
 DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
   Live:   OO#.. Dead: OO#..  Playing
 Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
 /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
 ---
 Sent from my phone. Please excuse my brevity.

 sheenmaria sheenmar...@gmail.com wrote:

How to call a function from another r file ?
Anyone can help me .

Having a function named like fun1 which is saved in r file file1.r
and i have another r file like file2.r, and  i need to call the fun1
(which
is in  file1) within file2.

Thank you




--
View this message in context:
http://r.789695.n4.nabble.com/function-call-from-another-r-file-tp4650627.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.

__
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] function call from another r file

2012-11-24 Thread Barry Rowlingson
On Sat, Nov 24, 2012 at 12:26 PM, Suzen, Mehmet msu...@gmail.com wrote:
 If you want to handle a generic case, best thing is to create an R
 package.

And better than best is to use devtools to save you a fiddly
edit/build/install cycle. You don't even have to think of it as a
package, its just a folder called R with your .R files in, and a
DESCRIPTION file (metadata is always a good thing), and your functions
get attached in a separate position so they don't clutter ls(), and
load_all() will load the just the ones you've edited. Magic.

 http://rpubs.com/geospacedman/lazydevtools

Easy peasy.

Barry

__
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] Building factors across two columns, is this possible?

2012-11-24 Thread Rui Barradas

Hello,

You can do what you want, but the coding of factors starts at 1 not at 0.


dat - read.table(text=
V1V2   V3
1   sun  moonstars
2 stars  moon  sun
3   cat   dog   catdog
4   dog  moon  sun
5  bird plane superman
6  1000   dog 2000
, header = TRUE)

levs - unique(unlist(dat))

dat$V1 - factor(dat$V1, levels = levs)
dat$V2 - factor(dat$V2, levels = levs)
dat$V3 - factor(dat$V3, levels = levs)

str(dat)
'data.frame':   6 obs. of  3 variables:
 $ V1: Factor w/ 11 levels sun,stars,..: 1 2 3 4 5 6
 $ V2: Factor w/ 11 levels sun,stars,..: 7 7 4 7 8 4
 $ V3: Factor w/ 11 levels sun,stars,..: 2 1 9 1 10 11


Hope this helps,

Rui Barradas
Em 24-11-2012 07:33, Brian Feeny escreveu:

To clarify on my previous post, here is a representation of what I am trying to 
accomplish:

I would like every unique value in either column to be assigned a number so 
like so:

 V1V2   V3
1   sun  moonstars
2 stars  moon  sun
3   cat   dog   catdog
4   dog  moon  sun
5  bird plane superman
6  1000   dog 2000

Level   Value
sun -   0
stars   -   1
cat -   2
dog -   3
bird-   4
1000-   5
moon-   6
plane   -   7
catdog  -   8
superman-   9
2000-   10
etc
etc

so internally its represented as:

 V1V2   V3
1   0   6   1
2   1   6   0
3   2   3   8
4   3   6   0
5   4   7   9
6   5   3   10

does this make sense?  I am hoping there is a way to accomplish this.

Brian

On Nov 23, 2012, at 11:42 PM, Brian Feeny bfe...@mac.com wrote:


I am trying to make it so two columns with similar data use the same internal 
numbers for same factors, here is the example:


read.csv(test.csv,header =FALSE,sep=,)

 V1V2   V3
1   sun  moonstars
2 stars  moon  sun
3   cat   dog   catdog
4   dog  moon  sun
5  bird plane superman
6  1000   dog 2000

data - read.csv(test.csv,header =FALSE,sep=,)
str(data)

'data.frame':   6 obs. of  3 variables:
$ V1: Factor w/ 6 levels 1000,bird,..: 6 5 3 4 2 1
$ V2: Factor w/ 3 levels dog,moon,plane: 2 2 1 2 3 1
$ V3: Factor w/ 5 levels 2000,catdog,..: 3 4 2 4 5 1


as.numeric(data$V1)

[1] 6 5 3 4 2 1

as.numeric(data$V2)

[1] 2 2 1 2 3 1

as.factor(data$V1)

[1] sun   stars cat   dog   bird  1000
Levels: 1000 bird cat dog stars sun

as.factor(data$V2)

[1] moon  moon  dog   moon  plane dog
Levels: dog moon plane


So notice dog is 4 in V1, yet its 1 in V2.  Is there a way, either on import, 
or after, to have factors computed for both columns and assigned
the same internal values?

Brian


__
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] SEM raw moment matrix

2012-11-24 Thread John Fox
Dear Maya,

I think that what you've done should work fine, though I'm not sure why you 
created your own UNIT variable rather than allowing sem() to generate the 
constant.

Best,
 John

On Sat, 24 Nov 2012 10:33:50 +0200
 Maya Abou Zeid ma...@aub.edu.lb wrote:
 Dear John,
 
 Many thanks for your response.
 I'd just still like to double check that I have indeed used the raw moment 
 matrix method correctly in sem. In my model, some equations are in deviations 
 form and have no intercept, while some have intercept.
 
 
 sem.QT.1 - sem(mod.QT.1, data=QTrav, formula = ~ X1 + X2 +  + UNIT -1, 
 fixed.x=c('X1','X2',...,'UNIT'), raw=TRUE)
 
 where UNIT is a variable equal to 1 which I appended to the dataset. I used 
 UNIT multiplied by a constant in the model equations that require an 
 intercept.
 
 I mainly wanted to check if the above specification of formula, with -1 
 written after UNIT, is correct. The model runs fine.
 
 Thank you,
 Maya
 
 
 -Original Message-
 From: John Fox [mailto:j...@mcmaster.ca] 
 Sent: Friday, November 23, 2012 2:39 PM
 To: Maya Abou Zeid
 Cc: r-help@r-project.org
 Subject: Re: [R] SEM raw moment matrix
 
 Dear Maya,
 
 sem() computes the fit statistics that I know how to compute for a model fit 
 to a raw moment matrix. If you know how to compute the others (and if they're 
 defined), then you could do that youself using the object returned by sem().
 
 I'm not sure why you want the likelihood under the model in addition to the 
 model chisquare, but you can get the *log*-likelihood from logLik(your.model).
 
 Finally, you don't have to compute the raw moment matrix in a separate step 
 (if you in fact did that) if you have the original data -- you can use the 
 data argument to sem().
 
 I hope this helps,
  John
 
 
 John Fox
 Sen. William McMaster Prof. of Social Statistics
 Department of Sociology
 McMaster University
 Hamilton, Ontario, Canada
 http://socserv.mcmaster.ca/jfox/
   
 On Fri, 23 Nov 2012 00:33:51 +0200
  Maya Abou Zeid ma...@aub.edu.lb wrote:
  Hello,
  
  I estimated a model using SEM package in R, which was fit to a raw moment 
  matrix, and includes an intercept term. The only goodness of fit statistics 
  that are output are Model Chisquare, AIC, AICc, BIC, CAIC, and normalized 
  residuals.
  
  How can I get the other goodness of fit statistics, like adjusted goodness 
  of fit, RMSEA, and R-squared? And how can I get the final value of the 
  log-likelihood of the model?
  
  Thanks,
  Maya
  
  [[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] daily maximum temperature

2012-11-24 Thread arun
Hi,

If I understand your question, this would do it:
z2-transform(z2,Hr=format(index(z2),%H))
 z2
#    Ta   HR  RS v   Hr
#2010-01-01 11:00:00 5.51 100 0  1.1 11
#2010-01-02 11:00:00 5.64 100 0  2.4 11
#2010-01-03 06:00:00 5.40 100 0  2.3 06
A.K.



- Original Message -
From: Dominic Roye dominic.r...@gmail.com
To: arun smartpink...@yahoo.com
Cc: 
Sent: Saturday, November 24, 2012 6:36 AM
Subject: Re: [R] daily maximum temperature

Hello,

Your first option works well, but how i can get also the hour of the
daily maximum temperature?

Thanks!


2012/11/23 arun smartpink...@yahoo.com:


 Hi,
 Since you mentioned filtering the daily maximum temperature, this may help:
 datos-read.table(text=
 X, Ta, HR, RS, v
 1/1/2010 1:00:00,5.28,100,0,2.3
 1/1/2010 6:00:00,5.45,100,0,2.5
 1/1/2010 11:00:00,5.51,100,0,1.1
 2/1/2010 1:00:00,5.33,100,0,2.1
 2/1/2010 6:00:00,5.48,100,0,2.3
 2/1/2010 11:00:00,5.64,100,0,2.4
 3/1/2010 1:00:00,5.12,100,0,2.0
 3/1/2010 6:00:00,5.40,100,0,2.3
 3/1/2010 11:00:00,5.32,100,0,1.7
 ,sep=,,header=TRUE,stringsAsFactors=FALSE)
 library(zoo)
 z-zoo(datos[,-1],order.by=as.POSIXct(datos[,1],format=%d/%m/%Y %H:%M:%S))

  aggregate(z$Ta,by=list(as.Date(index(z))),max) #gives the daily maximum 
temperatures
 #2010-01-01 2010-01-02 2010-01-03
  #     5.51       5.64       5.40


 For filtering the data:


 flag-unlist(lapply(split(z,as.Date(index(z))),function(x) 
 data.frame(x[,1]==max(x[,1]))),use.names=F)
  z1-transform(z,flag=flag)
 z2-z1[,1:4][z1$flag==1,] #filtered the maximum daily temp data
 z2
 #                      Ta  HR RS   v
 #2010-01-01 11:00:00 5.51 100  0 1.1
 #2010-01-02 11:00:00 5.64 100  0 2.4
 #2010-01-03 06:00:00 5.40 100  0 2.3

  str(z2)
 #‘zoo’ series from 2010-01-01 11:00:00 to 2010-01-03 06:00:00
  # Data: num [1:3, 1:4] 5.51 5.64 5.4 100 100 100 0 0 0 1.1 ...
  #- attr(*, dimnames)=List of 2
   #..$ : NULL
   #..$ : chr [1:4] Ta HR RS v
   #Index:  POSIXct[1:3], format: 2010-01-01 11:00:00 2010-01-02 11:00:00 
...

 #or
 z3-z
  z3$Max-ave(z[,1],as.Date(index(z)),FUN=max)
  z4-z3[,-5][z3$Ta==z3$Max,]
  z4
 #                      Ta  HR RS   v
 #2010-01-01 11:00:00 5.51 100  0 1.1
 #2010-01-02 11:00:00 5.64 100  0 2.4
 #2010-01-03 06:00:00 5.40 100  0 2.3

 Hope it helps

 A.K.



 - Original Message -
 From: Dominic Roye dominic.r...@gmail.com
 To: r-help@r-project.org
 Cc:
 Sent: Friday, November 23, 2012 1:04 PM
 Subject: [R] daily maximum temperature

 Hello,

 I want to filter the daily maximum temperature. For this i made this
 skript, but it come out wrong results. Can anybody help me?

 Thanks for your help!

 Best regards


 datos$X - as.POSIXct(strptime(datos$X, %d/%m/%Y %H:%M:%S))
 z - aggregate(zoo(datos$Ta), as.POSIXct(datos$X), max)


 str(datos)
 'data.frame':   17137 obs. of  5 variables:
 $ X : Factor w/ 17136 levels 00/01/1900 0:00:00,..: 2 3 4 5 6 7 8 9 10 11 
 ...
 $ Ta: num  5.28 5.45 5.54 5.54 5.51 5.51 5.5 5.56 5.58 5.63 ...
 $ HR: int  100 100 100 100 100 100 100 100 100 100 ...
 $ RS: int  0 0 0 0 0 0 0 0 0 0 ...
 $ v : num  2.3 2.5 1.1 2.3 2.2 2.1 2.2 2.9 2.4 2.6 ...



 str(z)
 ‘zoo’ series from 2010-01-01 00:10:00 to 2010-04-29 23:50:00
   Data: num [1:17129] 5.28 5.45 5.54 5.54 5.51 5.51 5.5 5.56 5.58 5.63 ...
   Index:  POSIXct[1:17129], format: 2010-01-01 00:10:00 2010-01-01
 00:20:00 2010-01-01 00:30:00 2010-01-01 00:40:00 ...


 __
 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] Building factors across two columns, is this possible?

2012-11-24 Thread Rui Barradas

Hello,

If you want the factor sorted, you'll have to do it manually.

levs - sort(unique(as.character(unlist(dat

Rui Barradas
Em 24-11-2012 12:57, Rui Barradas escreveu:

Hello,

You can do what you want, but the coding of factors starts at 1 not at 0.


dat - read.table(text=
V1V2   V3
1   sun  moonstars
2 stars  moon  sun
3   cat   dog   catdog
4   dog  moon  sun
5  bird plane superman
6  1000   dog 2000
, header = TRUE)

levs - unique(unlist(dat))

dat$V1 - factor(dat$V1, levels = levs)
dat$V2 - factor(dat$V2, levels = levs)
dat$V3 - factor(dat$V3, levels = levs)

str(dat)
'data.frame':   6 obs. of  3 variables:
 $ V1: Factor w/ 11 levels sun,stars,..: 1 2 3 4 5 6
 $ V2: Factor w/ 11 levels sun,stars,..: 7 7 4 7 8 4
 $ V3: Factor w/ 11 levels sun,stars,..: 2 1 9 1 10 11


Hope this helps,

Rui Barradas
Em 24-11-2012 07:33, Brian Feeny escreveu:
To clarify on my previous post, here is a representation of what I am 
trying to accomplish:


I would like every unique value in either column to be assigned a 
number so like so:


 V1V2   V3
1   sun  moonstars
2 stars  moon  sun
3   cat   dog   catdog
4   dog  moon  sun
5  bird plane superman
6  1000   dog 2000

LevelValue
sun-0
stars-1
cat-2
dog-3
bird-4
1000-5
moon-6
plane-7
catdog-8
superman-9
2000-   10
etc
etc

so internally its represented as:

 V1V2   V3
1   061
2   160
3   238
4   360
5   479
6   5310

does this make sense?  I am hoping there is a way to accomplish this.

Brian

On Nov 23, 2012, at 11:42 PM, Brian Feeny bfe...@mac.com wrote:

I am trying to make it so two columns with similar data use the same 
internal numbers for same factors, here is the example:



read.csv(test.csv,header =FALSE,sep=,)

 V1V2   V3
1   sun  moonstars
2 stars  moon  sun
3   cat   dog   catdog
4   dog  moon  sun
5  bird plane superman
6  1000   dog 2000

data - read.csv(test.csv,header =FALSE,sep=,)
str(data)

'data.frame':6 obs. of  3 variables:
$ V1: Factor w/ 6 levels 1000,bird,..: 6 5 3 4 2 1
$ V2: Factor w/ 3 levels dog,moon,plane: 2 2 1 2 3 1
$ V3: Factor w/ 5 levels 2000,catdog,..: 3 4 2 4 5 1


as.numeric(data$V1)

[1] 6 5 3 4 2 1

as.numeric(data$V2)

[1] 2 2 1 2 3 1

as.factor(data$V1)

[1] sun   stars cat   dog   bird  1000
Levels: 1000 bird cat dog stars sun

as.factor(data$V2)

[1] moon  moon  dog   moon  plane dog
Levels: dog moon plane


So notice dog is 4 in V1, yet its 1 in V2.  Is there a way, either 
on import, or after, to have factors computed for both columns and 
assigned

the same internal values?

Brian


__
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.


__
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] Error in Random Effect Panel

2012-11-24 Thread Hard Core
I tried to run a Random effect Panel regression and i get this error:

Errore in swar(object, data, effect) : 
  the estimated variance of the individual effect is negative
 

can you help me trying to understand the problem? (sorry for m bad english)
Thanks to everybody



--
View this message in context: 
http://r.789695.n4.nabble.com/Error-in-Random-Effect-Panel-tp4650654.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.


Re: [R] postForm() in RCurl and library RHTMLForms

2012-11-24 Thread veepsirtt
Why I am getting this error?
Error in getHTMLFormDescription(docNifty)[[1]] : subscript out of bounds 




--
View this message in context: 
http://r.789695.n4.nabble.com/postForm-in-RCurl-and-library-RHTMLForms-tp3026742p4650636.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.


Re: [R] Summary statistics for matrix columns

2012-11-24 Thread frespider


HI A.k,

I need one more question, if you can answer it please

M - matrix(sample(1:8000),nrow=100)
colnames(M)- paste(Col,1:ncol(M),sep=)
apply(M,2,function(x) c(Min=min(x),1st Qu =quantile(x, 0.25,names=FALSE),
Range = range(x),
Median = quantile(x, 0.5, names=FALSE),
Mean= mean(x),Std=sd(x),
3rd Qu = quantile(x,0.75,names=FALSE),
IQR=IQR(x),Max = max(x)))

why I get two range . isn't range mean the different between the max and min


Thanks 
Date: Fri, 23 Nov 2012 16:08:12 -0800
From: ml-node+s789695n4650613...@n4.nabble.com
To: frespi...@hotmail.com
Subject: Re: Summary statistics for matrix columns



Hi,

No problem.


There are a couple of other libraries which deal with summary statistics:

library(pastecs)

?stat.desc() # 


library(matrixStats) 

#Using the functions from package: matrixStats

fun1-function(x){

res-rbind(colMins(x),colQuantiles(x)[,2],colMedians(x),colMeans(x),colSds(x),colQuantiles(x)[,4],colIQRs(x),colMaxs(x))

row.names(res)-c(Min.,1st Qu.,Median,Mean,sd,3rd Qu.,IQR,Max.)

res}


set.seed(125)

x - matrix(sample(1:80),nrow=8)

colnames(x)- paste(Col,1:ncol(x),sep=)  

fun1(x)

#Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8

#Min.10.0  1.0 17.0  3.0 18.0 11.0 13.0 15.0

#1st Qu. 24.75000 29.5 26.0  7.75000 40.0 17.25000 27.5 34.75000

#Median  34.0 46.0 42.5 35.5 49.5 23.5 51.5 51.5

#Mean42.5 42.75000 41.75000 35.75000 44.87500 26.87500 44.75000 50.12500

#sd  25.05993 27.77846 19.57221 28.40397 16.39196 16.60841 21.97239 25.51995

#3rd Qu. 67.75000 58.5 50.0 63.25000 54.25000 30.25000 56.25000 70.5

#IQR 43.0 29.0 24.0 55.5 14.25000 13.0 28.75000 35.75000

#Max.74.0 77.0 76.0 70.0 65.0 63.0 79.0 80.0

 #   Col9Col10

#Min. 2.0  6.0

#1st Qu. 24.5 12.5

#Median  33.5 48.0

#Mean34.87500 40.75000

#sd  24.39811 28.21727

#3rd Qu. 45.25000 63.0

#IQR 20.75000 50.5

#Max.71.0 72.0


I thought this could be faster than the previous methods.  But, it was the 
slowest.


set.seed(125)

x1 - matrix(sample(1:80),nrow=1000)

colnames(x)- paste(Col,1:ncol(x1),sep=)


system.time(fun1(x1))

#   user  system elapsed 

 # 0.968   0.000   0.956 

A.K.











From: Fares Said [hidden email]

To: arun [hidden email] 

Cc: Pete Brecknock [hidden email]; R help [hidden email] 

Sent: Friday, November 23, 2012 10:23 AM

Subject: Re: [R] Summary statistics for matrix columns


Thank you all 


Sent from my iPhone


On 2012-11-23, at 10:19, arun [hidden email] wrote:


 HI,

 You are right.

 It is slower when compared to Pete's solution:

 set.seed(125)

 x - matrix(sample(1:80),nrow=1000)

 colnames(x)- paste(Col,1:ncol(x),sep=)

 

 system.time({

 res-sapply(data.frame(x),function(x) c(summary(x),sd=sd(x),IQR=IQR(x)))

  res1-as.matrix(res) 

 res2-res1[c(1:4,7,5,8,6),] })

 # user  system elapsed 

 #  0.596   0.000   0.597 

 

 system.time({

 res-apply(x,2,function(x) c(Min=min(x),

 1st Qu =quantile(x, 0.25,names=FALSE),

 Median = quantile(x, 0.5, names=FALSE),

 Mean= mean(x),

 Sd=sd(x),

 3rd Qu = quantile(x,0.75,names=FALSE),

 IQR=IQR(x),

 Max = max(x))) })

 # user  system elapsed 

  # 0.384   0.000   0.384 

 

 

 A.K.

 

 

 

 - Original Message -

 From: Pete Brecknock [hidden email]

 To: [hidden email]

 Cc: 

 Sent: Friday, November 23, 2012 8:42 AM

 Subject: Re: [R] Summary statistics for matrix columns

 

 frespider wrote

 Hi,

 

 it is possible. but don't you think it will slow the code if you convert

 to data.frame?

 

 Thanks 

 

 Date: Thu, 22 Nov 2012 18:31:35 -0800

 From:

 

 ml-node+s789695n4650500h51@.nabble

 

 To:

 

 frespider@

 

 Subject: RE: Summary statistics for matrix columns

 

 

 

 HI,

 

 Is it possible to use as.matrix()?

 

 res-sapply(data.frame(x),function(x) c(summary(x),sd=sd(x),IQR=IQR(x)))

 

   res1-as.matrix(res)

 

   is.matrix(res1)

 

 #[1] TRUE

 

 res1[c(1:4,7,5,8,6),]

 

 #Col1 Col2 Col3 Col4 Col5 Col6 Col7

 Col8

 

 #Min.10.0  1.0 17.0  3.0 18.0 11.0 13.0

 15.0

 

 #1st Qu. 24.75000 29.5 26.0  7.75000 40.0 17.25000 27.5

 34.75000

 

 #Median  34.0 46.0 42.5 35.5 49.5 23.5 51.5

 51.5

 

 #Mean42.5 42.75000 41.75000 35.75000 44.88000 26.88000 44.75000

 50.12000

 

 #sd  25.05993 27.77846 19.57221 28.40397 16.39196 16.60841 21.97239

 25.51995

 

 #3rd 

Re: [R] R lapack routines cannot be loaded

2012-11-24 Thread arysar
Yes I read that link but I have lapack version 3.3.1-1:


Paquete: liblapack3gf
Nuevo: sí
Estado: instalado
Instalado automáticamente: sí
Versión: 3.3.1-1
Prioridad: opcional
Sección: libs
Desarrollador: Ubuntu Developers ubuntu-devel-disc...@lists.ubuntu.com
Arquitectura: i386
Tamaño sin comprimir: 8.098 k
Depende de: debconf (= 0.5) | debconf-2.0, libblas3gf |
libblas.so.3gf | libatlas3gf-base, libc6 (=
2.1.3), libgcc1 (= 1:4.1.1), libgfortran3 (= 4.6)
Tiene conflictos con: lapack99
Reemplaza: lapack99
Proporciona: liblapack.so.3gf


just to confirm the problem:

leonardo@LyP:~$ R

R version 2.15.2 (2012-10-26) -- Trick or Treat
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i686-pc-linux-gnu (32-bit)

R es un software libre y viene sin GARANTIA ALGUNA.
Usted puede redistribuirlo bajo ciertas circunstancias.
Escriba 'license()' o 'licence()' para detalles de distribucion.

R es un proyecto colaborativo con muchos contribuyentes.
Escriba 'contributors()' para obtener más información y
'citation()' para saber cómo citar R o paquetes de R en publicaciones.

Escriba 'demo()' para demostraciones, 'help()' para el sistema on-line de ayuda,
o 'help.start()' para abrir el sistema de ayuda HTML con su navegador.
Escriba 'q()' para salir de R.

 example(chol)

chol ( m - matrix(c(5,1,1,3),2,2) )
 [,1] [,2]
[1,]51
[2,]13

chol ( cm - chol(m) )
Error en chol.default(m) : rutinas lapack no pueden ser cargadas
Además: Mensajes de aviso perdidos
In chol.default(m) :
  unable to load shared object '/usr/lib/R/modules//lapack.so':
  /usr/lib/R/modules//lapack.so: undefined symbol: dpstrf_


but the object lapack.so exist and is properly linked to
liblapack.so.3gf library


leonardo@LyP:~$ ldd  /usr/lib/R/modules/lapack.so
linux-gate.so.1 =  (0x009ec000)
libR.so = /usr/lib/libR.so (0x0023a000)
liblapack.so.3gf = /usr/lib/liblapack.so.3gf (0x00ba3000)
libm.so.6 = /lib/i386-linux-gnu/libm.so.6 (0x00622000)
libc.so.6 = /lib/i386-linux-gnu/libc.so.6 (0x0064e000)
libblas.so.3gf = /usr/lib/libblas.so.3gf (0x00186000)
libreadline.so.6 = /lib/i386-linux-gnu/libreadline.so.6 (0x0011)
libpcre.so.3 = /lib/i386-linux-gnu/libpcre.so.3 (0x0014a000)
liblzma.so.5 = /usr/lib/i386-linux-gnu/liblzma.so.5 (0x00203000)
libbz2.so.1.0 = /lib/i386-linux-gnu/libbz2.so.1.0 (0x008d)
libz.so.1 = /lib/i386-linux-gnu/libz.so.1 (0x005d4000)
librt.so.1 = /lib/i386-linux-gnu/librt.so.1 (0x0022a000)
libdl.so.2 = /lib/i386-linux-gnu/libdl.so.2 (0x00233000)
libgomp.so.1 = /usr/lib/i386-linux-gnu/libgomp.so.1 (0x00a17000)
libpthread.so.0 = /lib/i386-linux-gnu/libpthread.so.0 (0x005ea000)
/lib/ld-linux.so.2 (0x00b4f000)
libgfortran.so.3 = /usr/lib/i386-linux-gnu/libgfortran.so.3 (0x008e1000)
libgcc_s.so.1 = /lib/i386-linux-gnu/libgcc_s.so.1 (0x007f8000)
libtinfo.so.5 = /lib/i386-linux-gnu/libtinfo.so.5 (0x00816000)
libquadmath.so.0 = /usr/lib/i386-linux-gnu/libquadmath.so.0 (0x00835000)



leonardo@LyP:~$

On Sat, Nov 24, 2012 at 5:05 AM, Prof Brian Ripley
rip...@stats.ox.ac.uk wrote:
 This was answered this week in
 https://stat.ethz.ch/pipermail/r-help/2012-November/329946.html


 On 23/11/2012 16:05, arysar wrote:

 I usually ran different statistical analysis in R with routines that
 use lapack like gam() lm(), etc but after several updates of libraries
 the following error appears:

 library(mgcv)
 This is mgcv 1.7-22. For overview type 'help(mgcv-package)'.

 model - with(chlaR,gam(ClorMAX ~ s(DegDay_NM)))
 Error en eigen(St, symmetric = TRUE) :
 lapack routines  cannot be loaded
 Además: Mensajes de aviso perdidos
 In eigen(St, symmetric = TRUE) :
unable to load shared object '/usr/lib/R/modules//lapack.so':
/usr/lib/R/modules//lapack.so: undefined symbol: dpstrf_

 model - with(chlaR,lm(ClorMAX ~ DegDay_NM))
 summary(model)
 Error en chol2inv(Qr$qr[p1, p1, drop = FALSE]) :
lapack routines  cannot be loaded

 The version information is:

 platform i686-pc-linux-gnu
 arch i686
 os linux-gnu
 system i686, linux-gnu
 status
 major 2
 minor 15.2
 year 2012
 month 10
 day 26
 svn rev 61015
 language R

 I am using Ubuntu 12.04.1 LTS

 Any ideas?

 __
 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,  rip...@stats.ox.ac.uk
 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 

Re: [R] characters, mathematical expressions and computed values

2012-11-24 Thread mee1d3hs
I still can't get this to work, I am just trying to learn and this is
supposed to be a feature of R, the ability to combine math notation in
charts and exhibits

I did some more work to try to show what I am trying it to and what is not
working

 x - rnorm(1000,mean=10,sd=2)
 
 par(mfcol=c(3,3))
 meanx - round(mean(x),digits=2)
 
  x - rnorm(1000,mean=10,sd=2)
 
 par(mfcol=c(4,2))
 meanx - round(mean(x),digits=2)
 
 #chart 1:
 hist(x,main=paste( 1. Mean of X =,bquote(.(meanx
 #chart 2:
 hist(x,main=paste( 2. Mean of X = ,substitute(meanx,list(meanx=meanx
 #chart 3:
 hist(x,main=expression(3. *bar(x)* = ))
 #chart 4:
 hist(x,main=expression(paste(4. ,bar(x), = ,bquote(.(meanx)
 #chart 5:
 hist(x,main=expression(paste(5. ,bar(x), =
,substitute(meanx,list(meanx=meanx)
 #chart 6:
 hist(x,main=bquote(paste(6. ,expression(bar(x)), = ,.(meanx
 #chart 7:
 hist(x,main=paste(7. ,expression(bar(x)), =
,substitute(meanx,list(meanx=meanx
#chart 8:
 hist(x,main=bquote(Heart Attack ( * bar(X)==.(meanx) *)))
  
 

what i want to do is to show a title that says X Bar = mean, where Bar X is
the mathematical notation for the mean X with a bar on top and mean is the
mean value

the first 2 charts on top work using bquote() or substitute(), but they
write the word 'mean' instead of X bar. The third one shows the X Bar with
no value (it was a first attempt and I never included the value)

charts 4 and 5 and 6 attempt to incorporate either bquote() or substitute
into #3 to make it work, in both cases it seems the bquote or the substitute
is not properly being evaluated. In 6 and 7 specifically I put the
expression inside the bquote or paste to see if reversing would work,
finally 8 is the one suggested with slight modifications to replace round
and mean for the variable with that result. (the output I get is attached)

I am hoping that someone can help me understand what I am doing wrong, and I
guess how the nested functions are being evaluated. I am learning to use R,
and while I may really never need to use math notation (in fact in my work I
may confuse people more with X bar than using mean), I believe there is
value to learning how to use the functions, I can see how they would be
useful for writing code.functions that write code so one can dynamically
solve problems. I have done that in SAS and I may do it in R

I appreciate anyones help. Sorry for the long post, but I wanted to show my
process to solve and learn what is going on

Mario


sample.png http://r.789695.n4.nabble.com/file/n4650645/sample.png  



--
View this message in context: 
http://r.789695.n4.nabble.com/characters-mathematical-expressions-and-computed-values-tp4645916p4650645.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] Performing operations only on selected data

2012-11-24 Thread Marcel Curlin
I spent some time on this simple question, also searched the forum,
eventually hacked my way to an ugly solution for my particular problem but I
would like to improve my coding:

I have data of the form:
df - expand.grid(group=c('copper', 'zinc', 'aluminum', 'nickel'),
condition1=c(1:4))

I would like to add a new data column condition2, with values equal to the
value of condition1 plus a random number from 0-1 (uniform distribution)  if
the value of condition1 is  1, or just condition1 if the value of
condition1 is  1. More generally, my interest is in manipulating the values
of condition1 if they meet one or more criteria, or keeping the values the
same otherwise. Thanks for any thoughts!

 



--
View this message in context: 
http://r.789695.n4.nabble.com/Performing-operations-only-on-selected-data-tp4650646.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] How to Label Cases in Scatterplots?

2012-11-24 Thread john55
Hi everyone,

i´m trying to graphically display distributions with r and i´m working with
makrodata from the WVS.

the command i´m using is
  
 plot (Makrodata$v11, Makrodata$v12, xlab=Democracy Score Economist,
 ylab= share religious people)


i´m having an additional variable that identifies respectively labels the
cases with its country name.
how can i implement that variable, so it identifies the various cases in the
scatterplot and looks like the spss screenshot i posted below?

http://r.789695.n4.nabble.com/file/n4650650/Unbenannt.gif 

thanks in advance!



--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-Label-Cases-in-Scatterplots-tp4650650.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!!!!!

2012-11-24 Thread anoumou
Dear R users.
I am little lost and i need your  help.
I have such data.
DATE   i Symptomes t
1   2009-04-24 Mexique 0 14358
2   2009-04-24 usa 0 14358
3   2009-04-26 Mexique18 14360
4   2009-04-26 usa   100 14360
5   2009-04-27  Canada 6 14361
6   2009-04-27 Mexique26 14361
7   2009-04-27   Spain 1 14361
8   2009-04-27 usa40 14361
9   2009-04-28 Canada  6 14362
10  2009-04-28 Israel  2 14362
11  2009-04-28 Mexique26 14362
12  2009-04-28   New Zealand   3 14362
13  2009-04-28  Spain  2 14362
14  2009-04-28 United Kingdom  2 14362
15  2009-04-28 usa64 14362
16  2009-04-29 Canada 13 14363
17  2009-04-29Austria  1 14363
18  2009-04-29 Germany 3 14363
19  2009-04-29 Israel  2 14363
20  2009-04-29 Mexique26 14363
21  2009-04-29   New Zealand   3 14363
22  2009-04-29   SPAIN 4 14363
23  2009-04-29 United Kingdom  5 14363
A data with a date in character format,i wich reprent a country,Symptomes
wich is a number of subjects having a disease,t the date convert in numeric.
I want to create two other variables (for example INCUBATION and CONTAGIEUX)
Incubation[ i ] add values for symptomes for the two previous days (for
t=t-1)

CONTAGIEUX [ i ] add values for symptomes for the 7 next days (for t=t+6).
I want the two variables INCUBATION and CONTAGIEUX to be cumulative for next
and previous date.

For example for 

date   i   Symptomes   Incubation CONTAGIEUX
2009-04-24 Mexique   018+0   0

2009-04-26 Mexique   18   18+26   18+0

2009-04-27 MEXIQUE   26   18+26+...   18+26...
Thanks.




--
View this message in context: http://r.789695.n4.nabble.com/Help-tp4650647.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.


Re: [R] Summary statistics for matrix columns

2012-11-24 Thread William Dunlap
 isn't range mean the different between the max and min

That is one meaning of range.  There are many.  To see what R's definition is 
type
   ? range
or
   help(range)

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of frespider
 Sent: Saturday, November 24, 2012 4:58 AM
 To: r-help@r-project.org
 Subject: Re: [R] Summary statistics for matrix columns
 
 
 
 HI A.k,
 
 I need one more question, if you can answer it please
 
 M - matrix(sample(1:8000),nrow=100)
 colnames(M)- paste(Col,1:ncol(M),sep=)
 apply(M,2,function(x) c(Min=min(x),1st Qu =quantile(x, 0.25,names=FALSE),
 Range = range(x),
 Median = quantile(x, 0.5, names=FALSE),
 Mean= mean(x),Std=sd(x),
 3rd Qu = quantile(x,0.75,names=FALSE),
 IQR=IQR(x),Max = max(x)))
 
 why I get two range . isn't range mean the different between the max and min
 
 
 Thanks
 Date: Fri, 23 Nov 2012 16:08:12 -0800
 From: ml-node+s789695n4650613...@n4.nabble.com
 To: frespi...@hotmail.com
 Subject: Re: Summary statistics for matrix columns
 
 
 
   Hi,
 
 No problem.
 
 
 There are a couple of other libraries which deal with summary statistics:
 
 library(pastecs)
 
 ?stat.desc() #
 
 
 library(matrixStats)
 
 #Using the functions from package: matrixStats
 
 fun1-function(x){
 
 res-
 rbind(colMins(x),colQuantiles(x)[,2],colMedians(x),colMeans(x),colSds(x),colQuantiles(x)[
 ,4],colIQRs(x),colMaxs(x))
 
 row.names(res)-c(Min.,1st Qu.,Median,Mean,sd,3rd 
 Qu.,IQR,Max.)
 
 res}
 
 
 set.seed(125)
 
 x - matrix(sample(1:80),nrow=8)
 
 colnames(x)- paste(Col,1:ncol(x),sep=)
 
 fun1(x)
 
 #Col1 Col2 Col3 Col4 Col5 Col6 Col7 
 Col8
 
 #Min.10.0  1.0 17.0  3.0 18.0 11.0 13.0 
 15.0
 
 #1st Qu. 24.75000 29.5 26.0  7.75000 40.0 17.25000 27.5 
 34.75000
 
 #Median  34.0 46.0 42.5 35.5 49.5 23.5 51.5 
 51.5
 
 #Mean42.5 42.75000 41.75000 35.75000 44.87500 26.87500 44.75000 
 50.12500
 
 #sd  25.05993 27.77846 19.57221 28.40397 16.39196 16.60841 21.97239 
 25.51995
 
 #3rd Qu. 67.75000 58.5 50.0 63.25000 54.25000 30.25000 56.25000 
 70.5
 
 #IQR 43.0 29.0 24.0 55.5 14.25000 13.0 28.75000 
 35.75000
 
 #Max.74.0 77.0 76.0 70.0 65.0 63.0 79.0 
 80.0
 
  #   Col9Col10
 
 #Min. 2.0  6.0
 
 #1st Qu. 24.5 12.5
 
 #Median  33.5 48.0
 
 #Mean34.87500 40.75000
 
 #sd  24.39811 28.21727
 
 #3rd Qu. 45.25000 63.0
 
 #IQR 20.75000 50.5
 
 #Max.71.0 72.0
 
 
 I thought this could be faster than the previous methods.  But, it was the 
 slowest.
 
 
 set.seed(125)
 
 x1 - matrix(sample(1:80),nrow=1000)
 
 colnames(x)- paste(Col,1:ncol(x1),sep=)
 
 
 system.time(fun1(x1))
 
 #   user  system elapsed
 
  # 0.968   0.000   0.956
 
 A.K.
 
 
 
 
 
 
 
 
 
 
 
 From: Fares Said [hidden email]
 
 To: arun [hidden email]
 
 Cc: Pete Brecknock [hidden email]; R help [hidden email]
 
 Sent: Friday, November 23, 2012 10:23 AM
 
 Subject: Re: [R] Summary statistics for matrix columns
 
 
 Thank you all
 
 
 Sent from my iPhone
 
 
 On 2012-11-23, at 10:19, arun [hidden email] wrote:
 
 
  HI,
 
  You are right.
 
  It is slower when compared to Pete's solution:
 
  set.seed(125)
 
  x - matrix(sample(1:80),nrow=1000)
 
  colnames(x)- paste(Col,1:ncol(x),sep=)
 
 
 
  system.time({
 
  res-sapply(data.frame(x),function(x) c(summary(x),sd=sd(x),IQR=IQR(x)))
 
   res1-as.matrix(res)
 
  res2-res1[c(1:4,7,5,8,6),] })
 
  # user  system elapsed
 
  #  0.596   0.000   0.597
 
 
 
  system.time({
 
  res-apply(x,2,function(x) c(Min=min(x),
 
  1st Qu =quantile(x, 0.25,names=FALSE),
 
  Median = quantile(x, 0.5, names=FALSE),
 
  Mean= mean(x),
 
  Sd=sd(x),
 
  3rd Qu = quantile(x,0.75,names=FALSE),
 
  IQR=IQR(x),
 
  Max = max(x))) })
 
  # user  system elapsed
 
   # 0.384   0.000   0.384
 
 
 
 
 
  A.K.
 
 
 
 
 
 
 
  - Original Message -
 
  From: Pete Brecknock [hidden email]
 
  To: [hidden email]
 
  Cc:
 
  Sent: Friday, November 23, 2012 8:42 AM
 
  Subject: Re: [R] Summary statistics for matrix columns
 
 
 
  frespider wrote
 
  Hi,
 
 
 
  it is possible. but don't you think it will slow the code if you convert
 
  to data.frame?
 
 
 
  Thanks
 
 
 
  Date: Thu, 22 Nov 2012 18:31:35 -0800
 
  From:
 
 
 
  ml-node+s789695n4650500h51@.nabble
 
 
 
  To:
 
 
 
  frespider@
 
 
 
  Subject: RE: Summary statistics for matrix columns
 
 
 
 
 
 
 
  HI,
 
 
 
  Is it 

Re: [R] Performing operations only on selected data

2012-11-24 Thread Jeff Newmiller
?ifelse
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Marcel Curlin cemar...@u.washington.edu wrote:

I spent some time on this simple question, also searched the forum,
eventually hacked my way to an ugly solution for my particular problem
but I
would like to improve my coding:

I have data of the form:
df - expand.grid(group=c('copper', 'zinc', 'aluminum', 'nickel'),
condition1=c(1:4))

I would like to add a new data column condition2, with values equal
to the
value of condition1 plus a random number from 0-1 (uniform
distribution)  if
the value of condition1 is  1, or just condition1 if the value of
condition1 is  1. More generally, my interest is in manipulating the
values
of condition1 if they meet one or more criteria, or keeping the values
the
same otherwise. Thanks for any thoughts!

 



--
View this message in context:
http://r.789695.n4.nabble.com/Performing-operations-only-on-selected-data-tp4650646.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] characters, mathematical expressions and computed values

2012-11-24 Thread William Dunlap
My message much earlier in the thread was
   I think that bquote, with its .() operator, suffices for [almost?] any 
single title;
   don't bother fiddling with expression(), substitute(), or parse().   (You 
can make
   those work in many situations, but if you stick with just bquote then you 
can
   spend your time on the title itself.)

I still think that is a good suggestion.  While you are learning this stuff, 
don't
even consider solutions that are not of the form
   main=bquote(...)
That leaves you with two of your nine attempts
#chart 6:
hist(x,main=bquote(paste(6. ,expression(bar(x)), = ,.(meanx
   #chart 8:
hist(x,main=bquote(Heart Attack ( * bar(X)==.(meanx) *)))
I would ignore #6 as well because it has a call to expression() inside
the call to bquote.

What do you want to change about #8?

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of mee1d3hs
 Sent: Saturday, November 24, 2012 5:21 AM
 To: r-help@r-project.org
 Subject: Re: [R] characters, mathematical expressions and computed values
 
 I still can't get this to work, I am just trying to learn and this is
 supposed to be a feature of R, the ability to combine math notation in
 charts and exhibits
 
 I did some more work to try to show what I am trying it to and what is not
 working
 
  x - rnorm(1000,mean=10,sd=2)
 
  par(mfcol=c(3,3))
  meanx - round(mean(x),digits=2)
 
   x - rnorm(1000,mean=10,sd=2)
 
  par(mfcol=c(4,2))
  meanx - round(mean(x),digits=2)
 
  #chart 1:
  hist(x,main=paste( 1. Mean of X =,bquote(.(meanx
  #chart 2:
  hist(x,main=paste( 2. Mean of X = ,substitute(meanx,list(meanx=meanx
  #chart 3:
  hist(x,main=expression(3. *bar(x)* = ))
  #chart 4:
  hist(x,main=expression(paste(4. ,bar(x), = ,bquote(.(meanx)
  #chart 5:
  hist(x,main=expression(paste(5. ,bar(x), =
 ,substitute(meanx,list(meanx=meanx)
  #chart 6:
  hist(x,main=bquote(paste(6. ,expression(bar(x)), = ,.(meanx
  #chart 7:
  hist(x,main=paste(7. ,expression(bar(x)), =
 ,substitute(meanx,list(meanx=meanx
 #chart 8:
  hist(x,main=bquote(Heart Attack ( * bar(X)==.(meanx) *)))
 
 
 
 what i want to do is to show a title that says X Bar = mean, where Bar X is
 the mathematical notation for the mean X with a bar on top and mean is the
 mean value
 
 the first 2 charts on top work using bquote() or substitute(), but they
 write the word 'mean' instead of X bar. The third one shows the X Bar with
 no value (it was a first attempt and I never included the value)
 
 charts 4 and 5 and 6 attempt to incorporate either bquote() or substitute
 into #3 to make it work, in both cases it seems the bquote or the substitute
 is not properly being evaluated. In 6 and 7 specifically I put the
 expression inside the bquote or paste to see if reversing would work,
 finally 8 is the one suggested with slight modifications to replace round
 and mean for the variable with that result. (the output I get is attached)
 
 I am hoping that someone can help me understand what I am doing wrong, and I
 guess how the nested functions are being evaluated. I am learning to use R,
 and while I may really never need to use math notation (in fact in my work I
 may confuse people more with X bar than using mean), I believe there is
 value to learning how to use the functions, I can see how they would be
 useful for writing code.functions that write code so one can dynamically
 solve problems. I have done that in SAS and I may do it in R
 
 I appreciate anyones help. Sorry for the long post, but I wanted to show my
 process to solve and learn what is going on
 
 Mario
 
 
 sample.png http://r.789695.n4.nabble.com/file/n4650645/sample.png
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/characters-mathematical-
 expressions-and-computed-values-tp4645916p4650645.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] Building factors across two columns, is this possible?

2012-11-24 Thread David Winsemius


On Nov 23, 2012, at 8:42 PM, Brian Feeny wrote:



I am trying to make it so two columns with similar data use the same  
internal numbers for same factors, here is the example:



read.csv(test.csv,header =FALSE,sep=,)

V1V2   V3
1   sun  moonstars
2 stars  moon  sun
3   cat   dog   catdog
4   dog  moon  sun
5  bird plane superman
6  1000   dog 2000

data - read.csv(test.csv,header =FALSE,sep=,)
str(data)

'data.frame':   6 obs. of  3 variables:
$ V1: Factor w/ 6 levels 1000,bird,..: 6 5 3 4 2 1
$ V2: Factor w/ 3 levels dog,moon,plane: 2 2 1 2 3 1
$ V3: Factor w/ 5 levels 2000,catdog,..: 3 4 2 4 5 1


as.numeric(data$V1)

[1] 6 5 3 4 2 1

as.numeric(data$V2)

[1] 2 2 1 2 3 1

as.factor(data$V1)

[1] sun   stars cat   dog   bird  1000
Levels: 1000 bird cat dog stars sun

as.factor(data$V2)

[1] moon  moon  dog   moon  plane dog
Levels: dog moon plane


So notice dog is 4 in V1, yet its 1 in V2.  Is there a way, either  
on import, or after, to have factors computed for both columns and  
assigned

the same internal values?


 dat[] - lapply(dat, function(x) factor(as.character(x),
  levels=  
levels(unlist(dat)) ) )

 dat
 V1V2   V3
1   sun  moonstars
2 stars  moon  sun
3   cat   dog   catdog
4   dog  moon  sun
5  bird plane superman
6  1000   dog 2000
 levels(dat[[1]])
 [1] 1000 bird cat  dog  starssun
 [7] moon plane2000 catdog   superman

I see your clarification. Reordering the representation can be done  
with :


levels(dat) - character vector

--

David Winsemius, MD
Alameda, CA, USA

__
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] characters, mathematical expressions and computed values

2012-11-24 Thread David Winsemius


On Nov 24, 2012, at 5:20 AM, mee1d3hs wrote:


I still can't get this to work,


I sent a message yesterday that indicated that one of you earlier  
attempts was successful on my machine running the same (or roughly the  
same OS) and a current version of R. You seem to be ignoring the  
possibility that your R installation is broken.



I am just trying to learn and this is
supposed to be a feature of R, the ability to combine math notation in
charts and exhibits

I did some more work to try to show what I am trying it to and what  
is not

working

x - rnorm(1000,mean=10,sd=2)

par(mfcol=c(3,3))
meanx - round(mean(x),digits=2)

 x - rnorm(1000,mean=10,sd=2)

par(mfcol=c(4,2))
meanx - round(mean(x),digits=2)

#chart 1:
hist(x,main=paste( 1. Mean of X =,bquote(.(meanx
#chart 2:
hist(x,main=paste( 2. Mean of X =  
,substitute(meanx,list(meanx=meanx

#chart 3:
hist(x,main=expression(3. *bar(x)* = ))


This should work, at least to the extent of putting nothing  after  
the equal sign. As should this:


hist(x,main=expression(3.~~bar(X)==phantom() ) )

The bquote function allows you to specify what portion of the  
expression will be evaluated. Otherwise everything gets displayed as  
typed (or interpreted by the plotmath evaluation engine). The tilde  
and asterisk are plotmath separators. Using them to bind together  
plotmath or text items will generally be much more readable than using  
paste.




#chart 4:
hist(x,main=expression(paste(4. ,bar(x), = ,bquote(.(meanx)


It's either bquote() or expression(). Do not mix them unless you  
understand why they shouldn't be mixed.  Should be:


hist(x,main=bquote(4.~~bar(x)==.(meanx) ) )



#chart 5:
hist(x,main=expression(paste(5. ,bar(x), =
,substitute(meanx,list(meanx=meanx)
#chart 6:
hist(x,main=bquote(paste(6. ,expression(bar(x)), = ,.(meanx


This displays on my machine. (with expression(.) where the dot is a  
correctly drawn x-bar

)

#chart 7:
hist(x,main=paste(7. ,expression(bar(x)), =
,substitute(meanx,list(meanx=meanx
#chart 8:
hist(x,main=bquote(Heart Attack ( * bar(X)==.(meanx) *)))


That displays properly on my machine.


--
David.



what i want to do is to show a title that says X Bar = mean, where  
Bar X is
the mathematical notation for the mean X with a bar on top and mean  
is the

mean value

the first 2 charts on top work using bquote() or substitute(), but  
they
write the word 'mean' instead of X bar. The third one shows the X  
Bar with

no value (it was a first attempt and I never included the value)

charts 4 and 5 and 6 attempt to incorporate either bquote() or  
substitute
into #3 to make it work, in both cases it seems the bquote or the  
substitute

is not properly being evaluated. In 6 and 7 specifically I put the
expression inside the bquote or paste to see if reversing would work,
finally 8 is the one suggested with slight modifications to replace  
round
and mean for the variable with that result. (the output I get is  
attached)


I am hoping that someone can help me understand what I am doing  
wrong, and I
guess how the nested functions are being evaluated. I am learning to  
use R,
and while I may really never need to use math notation (in fact in  
my work I
may confuse people more with X bar than using mean), I believe there  
is
value to learning how to use the functions, I can see how they would  
be
useful for writing code.functions that write code so one can  
dynamically

solve problems. I have done that in SAS and I may do it in R

I appreciate anyones help. Sorry for the long post, but I wanted to  
show my

process to solve and learn what is going on

Mario


sample.png http://r.789695.n4.nabble.com/file/n4650645/sample.png



--
View this message in context: 
http://r.789695.n4.nabble.com/characters-mathematical-expressions-and-computed-values-tp4645916p4650645.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.


David Winsemius, MD
Alameda, CA, USA

__
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] Does R has any SVG devices that allow setting of zooming and panning (in addition to Tooltips and Hyperlinks) ?

2012-11-24 Thread chakri
This question is in continuation to the one posted in StackOverflow :
http://stackoverflow.com/q/13542480/1029725

Thanks in Advance
Ch



--
View this message in context: 
http://r.789695.n4.nabble.com/Does-R-has-any-SVG-devices-that-allow-setting-of-zooming-and-panning-in-addition-to-Tooltips-and-Hyp-tp4650657.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] A Question About Plotting

2012-11-24 Thread Marcus Tullius
Hallo there, I've got a simple question concerning a plot attempt of mine. I am 
trying to plot two variables using the following code: # Creating a Graph 
attach(Jitirana) plot(Sozialkapital, Migration) 
abline(lm(Migration~Sozialkapital)) title(Regression of Sozialkapital on 
Migration) Simple thing, but the problem lies in the fact that I keep 
receiving a square plot depicting y on the left and the frequency on the right 
side of the square. Well, in the plot shown on the Quick-R page the frequency 
is on the left side and there is a line running right in the middle. Have 
anyone got an idea as to where my keeps cropping up entirely different from 
the example on the Quick-R page? Thanks in advance. Marcus Tullius

[[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.


Re: [R] Help!!!!!

2012-11-24 Thread Rui Barradas

Hello,
Try the following.

incub - function(x){
x$Incubation - 0
x$Incubation[1] - x$Symptomes[1]
if(nr  1)
x$Incubation[2] - sum(x$Symptomes[1:2])
for(i in seq_len(nrow(x))[-(1:2)])
x$Incubation[i] - sum(x$Symptomes[i - (0:2)])
x
}
contag - function(x){
x$CONTAGIEUX - 0
for(i in seq_len(nrow(x)))
x$CONTAGIEUX[i] - sum(x$Symptomes[i + 0:6], na.rm = TRUE)
x
}
result - lapply(split(dat, dat$i), incub)
result - lapply(result, contag)
result - do.call(rbind, result)
rownames(result) - seq_len(nrow(result))
result


Hope this helps,

Rui Barradas
Em 24-11-2012 14:39, anoumou escreveu:

Dear R users.
I am little lost and i need your  help.
I have such data.
DATE   i Symptomes t
1   2009-04-24 Mexique 0 14358
2   2009-04-24 usa 0 14358
3   2009-04-26 Mexique18 14360
4   2009-04-26 usa   100 14360
5   2009-04-27  Canada 6 14361
6   2009-04-27 Mexique26 14361
7   2009-04-27   Spain 1 14361
8   2009-04-27 usa40 14361
9   2009-04-28 Canada  6 14362
10  2009-04-28 Israel  2 14362
11  2009-04-28 Mexique26 14362
12  2009-04-28   New Zealand   3 14362
13  2009-04-28  Spain  2 14362
14  2009-04-28 United Kingdom  2 14362
15  2009-04-28 usa64 14362
16  2009-04-29 Canada 13 14363
17  2009-04-29Austria  1 14363
18  2009-04-29 Germany 3 14363
19  2009-04-29 Israel  2 14363
20  2009-04-29 Mexique26 14363
21  2009-04-29   New Zealand   3 14363
22  2009-04-29   SPAIN 4 14363
23  2009-04-29 United Kingdom  5 14363
A data with a date in character format,i wich reprent a country,Symptomes
wich is a number of subjects having a disease,t the date convert in numeric.
I want to create two other variables (for example INCUBATION and CONTAGIEUX)
Incubation[ i ] add values for symptomes for the two previous days (for
t=t-1)

CONTAGIEUX [ i ] add values for symptomes for the 7 next days (for t=t+6).
I want the two variables INCUBATION and CONTAGIEUX to be cumulative for next
and previous date.

For example for

date   i   Symptomes   Incubation CONTAGIEUX
2009-04-24 Mexique   018+0   0

2009-04-26 Mexique   18   18+26   18+0

2009-04-27 MEXIQUE   26   18+26+...   18+26...
Thanks.




--
View this message in context: http://r.789695.n4.nabble.com/Help-tp4650647.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] Summary statistics for matrix columns

2012-11-24 Thread arun
Hi, 

You are right.  Range is supposed to be one value (i.e the 
difference between largest and smallest).  For some reason, the function
 range(x) gives both the values. 
The description for ?range() is: 
Description: 

     ‘range’ returns a vector containing the minimum and maximum of all 
     the given arguments. 
 
I looked for similar function in library(matrixStats) .  There it was 
colRanges(), rowRanges(). 
 set.seed(125) 
 x - matrix(sample(1:80),nrow=8) 
 colnames(x)- paste(Col,1:ncol(x),sep=)   
apply(x,2,function(x) range(x)) 
#     Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 Col9 Col10 
#[1,]   10    1   17    3   18   11   13   15    2     6 
#[2,]   74   77   76   70   65   63   79   80   71    72 
library(matrixStats) 
colRanges(x) 
   #   [,1] [,2] 
 #[1,]   10   74 
 #[2,]    1   77 
 #[3,]   17   76 
 - 
You could do this to get the range: 
 apply(x,2,function(x) diff(range(x))) 
 #Col1  Col2  Col3  Col4  Col5  Col6  Col7  Col8  Col9 Col10 
  # 64    76    59    67    47    52    66    65    69    66 
#or i 
 diff(t(colRanges(x))) 
#     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] 
#[1,]   64   76   59   67   47   52   66   65   69    66 
#or 
rowDiffs(colRanges(x)) 
A.K. 



- Original Message -
From: frespider frespi...@hotmail.com
To: r-help@r-project.org
Cc: 
Sent: Saturday, November 24, 2012 7:58 AM
Subject: Re: [R] Summary statistics for matrix columns



HI A.k,

I need one more question, if you can answer it please

M - matrix(sample(1:8000),nrow=100)
colnames(M)- paste(Col,1:ncol(M),sep=)
apply(M,2,function(x) c(Min=min(x),1st Qu =quantile(x, 0.25,names=FALSE),
                        Range = range(x),
                        Median = quantile(x, 0.5, names=FALSE),
                        Mean= mean(x),Std=sd(x),
                        3rd Qu = quantile(x,0.75,names=FALSE),
                        IQR=IQR(x),Max = max(x)))

why I get two range . isn't range mean the different between the max and min


Thanks 
Date: Fri, 23 Nov 2012 16:08:12 -0800
From: ml-node+s789695n4650613...@n4.nabble.com
To: frespi...@hotmail.com
Subject: Re: Summary statistics for matrix columns



    Hi,

No problem.


There are a couple of other libraries which deal with summary statistics:

library(pastecs)

?stat.desc() # 


library(matrixStats) 

#Using the functions from package: matrixStats

fun1-function(x){

res-rbind(colMins(x),colQuantiles(x)[,2],colMedians(x),colMeans(x),colSds(x),colQuantiles(x)[,4],colIQRs(x),colMaxs(x))

row.names(res)-c(Min.,1st Qu.,Median,Mean,sd,3rd Qu.,IQR,Max.)

res}


set.seed(125)

x - matrix(sample(1:80),nrow=8)

colnames(x)- paste(Col,1:ncol(x),sep=)  

fun1(x)

#            Col1     Col2     Col3     Col4     Col5     Col6     Col7     Col8

#Min.    10.0  1.0 17.0  3.0 18.0 11.0 13.0 15.0

#1st Qu. 24.75000 29.5 26.0  7.75000 40.0 17.25000 27.5 34.75000

#Median  34.0 46.0 42.5 35.5 49.5 23.5 51.5 51.5

#Mean    42.5 42.75000 41.75000 35.75000 44.87500 26.87500 44.75000 50.12500

#sd      25.05993 27.77846 19.57221 28.40397 16.39196 16.60841 21.97239 25.51995

#3rd Qu. 67.75000 58.5 50.0 63.25000 54.25000 30.25000 56.25000 70.5

#IQR     43.0 29.0 24.0 55.5 14.25000 13.0 28.75000 35.75000

#Max.    74.0 77.0 76.0 70.0 65.0 63.0 79.0 80.0

#           Col9    Col10

#Min.     2.0  6.0

#1st Qu. 24.5 12.5

#Median  33.5 48.0

#Mean    34.87500 40.75000

#sd      24.39811 28.21727

#3rd Qu. 45.25000 63.0

#IQR     20.75000 50.5

#Max.    71.0 72.0


I thought this could be faster than the previous methods.  But, it was the 
slowest.


set.seed(125)

x1 - matrix(sample(1:80),nrow=1000)

colnames(x)- paste(Col,1:ncol(x1),sep=)


system.time(fun1(x1))

#   user  system elapsed 

# 0.968   0.000   0.956 

A.K.











From: Fares Said [hidden email]

To: arun [hidden email] 

Cc: Pete Brecknock [hidden email]; R help [hidden email] 

Sent: Friday, November 23, 2012 10:23 AM

Subject: Re: [R] Summary statistics for matrix columns


Thank you all 


Sent from my iPhone


On 2012-11-23, at 10:19, arun [hidden email] wrote:


 HI,

 You are right.

 It is slower when compared to Pete's solution:

 set.seed(125)

 x - matrix(sample(1:80),nrow=1000)

 colnames(x)- paste(Col,1:ncol(x),sep=)

 

 system.time({

 res-sapply(data.frame(x),function(x) c(summary(x),sd=sd(x),IQR=IQR(x)))

  res1-as.matrix(res) 

 res2-res1[c(1:4,7,5,8,6),] })

 # user  system elapsed 

 #  0.596   0.000   0.597 

 

 system.time({

 res-apply(x,2,function(x) c(Min=min(x),

                         1st Qu =quantile(x, 0.25,names=FALSE),

                         Median = quantile(x, 0.5, names=FALSE),

                         Mean= mean(x),

                         Sd=sd(x),

                         3rd Qu = quantile(x,0.75,names=FALSE),

 

[R] Bootstrap lmekin model

2012-11-24 Thread Roberta Carriero

Hi,I use the 'lmekin' model of the 'kinship' package of R in order to estimate 
heritability. I want to estimate the confidence interval of the variance 
coefficient and so I should use a bootstrap simulation. The pedigree file has 
1386 subjects so I create a kinship matrix [1386*1386].This is the code of R I 
use:
kfit2 - lmekin(IT~1+AGE +(1|ID), dati1, varlist=list(kmat))kfit2kfit2$vcoef
library(boot)
var - function(formula,data,indices,varlist) {   d - data[indices,] # allows 
boot to select sample   kfit2 - lmekin(formula, data=d, varlist=list(kmat))  
return(kfit2$vcoef)} 
# bootstrapping with 1000 replications results - boot(data=dati1, 
statistic=var,R=1000, formula=IT~1+AGE +(1|ID),varlist=list(kmat))
## WARNING MESSAGE: wrong number of indices for a matrix
What can I do with the kinship matrix??
Thanks for help!!
Best regards
Roberta   
[[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] bootstrap lmekin model

2012-11-24 Thread Roberta Carriero

Hi,I use the 'lmekin' model of the 'kinship' package of R in order to estimate 
heritability. I want to estimate the confidence interval of the variance 
coefficient and so I should use a bootstrap simulation. The pedigree file has 
1386 subjects so I create a kinship matrix [1386*1386].This is the code of R I 
use:



kfit2 - lmekin(IT~1+AGE +(1|ID), dati1, varlist=list(kmat))

kfit2$vcoef

library(boot)


var - function(formula,data,indices,varlist) {   d - data[indices,] # allows 
boot to select sample   kfit2 - lmekin(formula, data=d, varlist=list(kmat))  
return(kfit2$vcoef)} 



# bootstrapping with 1000 replications 
results - boot(data=dati1, statistic=var,   R=1000, formula=IT~1+AGE 
+(1|ID),varlist=list(kmat))


## WARNING MESSAGE: wrong number of indices for a matrix
What can I do with the kinship matrix??
Thanks for help!!
Best regards
Roberta   
[[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] robustbase error message

2012-11-24 Thread Torvon
Hey there.

I am running a multiple regression and want to see whether a robust
regression would provide different results, since there is some
heteroscedasticity and other minor violations of regression assumptions.

When I run the model using the robustbase package,
 modelrob=lmrob(m1)

I receive the following error:
 Error in qr.default(x * sqrt(ret$weights)) :
  NA/NaN/Inf in foreign function call (arg 1)

Google wasn't helpful, maybe you can help me out. If this problem is not
obvious to someone who uses R regularly, please let me know what further
information to provide.

Thank you!
Torvon

[[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.


Re: [R] How to Label Cases in Scatterplots?

2012-11-24 Thread Richard M. Heiberger
Johannes,

This will get you started

tmp - data.frame(x=rnorm(10), y=rnorm(10, 1000, 100), txt=letters[1:10])
plot(y ~ x, data=tmp)
text(x=tmp$x+.05, y=tmp$y-20, labels=tmp$txt)
rect(tmp$x-.05, tmp$y-25, tmp$x+.1, tmp$y-10)

Rich


You will probably need to use the xlim and ylim arguments on the plot
function call.
You will need to experiment with the constant adjustments on the text
and rect calls.  You might need vector adjustments rather than scalars on
those calls.

On Sat, Nov 24, 2012 at 11:04 AM, john55 johannes...@gmail.com wrote:

 Hi everyone,

 i´m trying to graphically display distributions with r and i´m working with
 makrodata from the WVS.

 the command i´m using is

  plot (Makrodata$v11, Makrodata$v12, xlab=Democracy Score Economist,
  ylab= share religious people)


 i´m having an additional variable that identifies respectively labels the
 cases with its country name.
 how can i implement that variable, so it identifies the various cases in
 the
 scatterplot and looks like the spss screenshot i posted below?

 http://r.789695.n4.nabble.com/file/n4650650/Unbenannt.gif

 thanks in advance!



 --
 View this message in context:
 http://r.789695.n4.nabble.com/How-to-Label-Cases-in-Scatterplots-tp4650650.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.


[[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.


Re: [R] A Question About Plotting

2012-11-24 Thread Richard M. Heiberger
Marcus,

Best guess is one of those variables is a factor and you are thinking it is
numeric.

Please use
dput(head(Jitirana))
and send the resulting exeutable statement.

Please control your email so that the lines are properly transmitted.
Your entire email came as one paragraph.

Please read the posting guide referenced in the trailer of all R-help
messages

Rich

On Sat, Nov 24, 2012 at 12:02 PM, Marcus Tullius tull...@europe.com wrote:

 Hallo there, I've got a simple question concerning a plot attempt of mine.
 I am trying to plot two variables using the following code: # Creating a
 Graph attach(Jitirana) plot(Sozialkapital, Migration)
 abline(lm(Migration~Sozialkapital)) title(Regression of Sozialkapital on
 Migration) Simple thing, but the problem lies in the fact that I keep
 receiving a square plot depicting y on the left and the frequency on the
 right side of the square. Well, in the plot shown on the Quick-R page the
 frequency is on the left side and there is a line running right in the
 middle. Have anyone got an idea as to where my keeps cropping up entirely
 different from the example on the Quick-R page? Thanks in advance. Marcus
 Tullius

 [[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.


[[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.


Re: [R] Coefficient of determination for non-linear equations system (nlsystemfit)

2012-11-24 Thread Arne Henningsen
Dear Antti

On 20 November 2012 10:24, Antti Simola asimol...@gmail.com wrote:
 I have estimated system of three linear equations with one non-linear
 restrictions with nlsystemfit.

Please read the FAQ at http://www.systemfit.org/

 I was wondering how I can calculate the
 R-squared (or some alternative coefficient of determination) for the whole
 system. This is automatically given by linear systemfit but not by
 nlsystemfit. I can get the values for each of the equations separately, but
 apparently not for the whole system.

You have to do this manually, e.g. by equation (43) in the paper:
   http://www.jstatsoft.org/v23/i04/paper

 I'm also wondering why separate equations' objects all appear in together
 with a command like:

 nl.system - nlsystemfit()

 nl.system$eq[i]

 but e.g. the following produces NULL as the value for the individual
 objects, e.g. R-squared

As the eq component is a list (see documentation), you must use
double brackets:
   nl.system$eq[[i]]

 eq.1 - nl.system$eq[1]

 eq.1$r2

You can directly use:
   nl.system$eq[[i]]$r2

Best wishes from Copenhagen,
Arne

--
Arne Henningsen
http://www.arne-henningsen.name

__
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] Designating a new year (Sept-Aug) in R

2012-11-24 Thread nick pardikes
If I have data (below) and need some help in figuring out how I can change the 
values of my date column, so that a year will be from September-August? So the 
year 
1990 = September 89-August 90; 1991
 = September 90-August 91, etc... 

I was trying to use the if() function, but am unable to figure it out. I 
basically need to change the years associated with September-December to the 
following year. Any 
help would be greatly appreciated. Otherwise I will have to power through
 it and do it all manually in excel. I am sorry that I do not have the original 
data associated with this posting, nor any R code with it. I really do not have 
a clue how to even start designating the new year. 

head(mydata)
class(mydata)
data.frame
 sitedateprecipitation temp_max temp_min
1 Castle Peak January-70 0   32   18
2 Castle Peak January-70 0   399
3 Castle Peak January-70 0   345
4 Castle Peak January-70 0   307
5 Castle Peak January-70 0   406
6 Castle Peak January-70 0   45   10

Thank you in advance and please let me know what else I can include to help 
solve this issue. this is my first posting on R-help. 



Nick Pardikes
PhD Student
Program in Ecology, Evolution and Conservation Biology
University of Nevada, Reno
303-550-1072
http://wolfweb.unr.edu/homepage/npardikes/MySite/Welcome.html
  
[[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] Please help me

2012-11-24 Thread emable_wahid
i want to generate an odf report using R,
the report is generated but the run stop just after the instruction:
odfWeave(inputFile,outputFile)
and i get this error:

Error in odfWeave(inf, outf) : Error removing work dir

please help me it's an emergency.
thanks



--
View this message in context: 
http://r.789695.n4.nabble.com/Please-help-me-tp4650674.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.


Re: [R] Help!!!!!

2012-11-24 Thread Rui Barradas

Hello,

Right, sorry, it should be nrow(x). I had created a variable nr - 
nrow(x) and forgot to check it after changing it.



incub - function(x){
x$Incubation - 0
x$Incubation[1] - x$Symptomes[1]
if(nrow(x)  1)
x$Incubation[2] - sum(x$Symptomes[1:2])
for(i in seq_len(nrow(x))[-(1:2)])
x$Incubation[i] - sum(x$Symptomes[i - (0:2)])
x
}


Now it works.

Rui Barradas
Em 24-11-2012 18:18, arun escreveu:

HI Rui,
Seems like nr is not defined.
  lapply(split(dat1, dat1$i), incub)
#Error in FUN(X[[1L]], ...) : object 'nr' not found
A.K.




- Original Message -
From: Rui Barradas ruipbarra...@sapo.pt
To: anoumou teko_maur...@yahoo.fr
Cc: r-help@r-project.org
Sent: Saturday, November 24, 2012 12:47 PM
Subject: Re: [R] Help!

Hello,
Try the following.

incub - function(x){
 x$Incubation - 0
 x$Incubation[1] - x$Symptomes[1]
 if(nr  1)
 x$Incubation[2] - sum(x$Symptomes[1:2])
 for(i in seq_len(nrow(x))[-(1:2)])
 x$Incubation[i] - sum(x$Symptomes[i - (0:2)])
 x
}
contag - function(x){
 x$CONTAGIEUX - 0
 for(i in seq_len(nrow(x)))
 x$CONTAGIEUX[i] - sum(x$Symptomes[i + 0:6], na.rm = TRUE)
 x
}
result - lapply(split(dat, dat$i), incub)
result - lapply(result, contag)
result - do.call(rbind, result)
rownames(result) - seq_len(nrow(result))
result


Hope this helps,

Rui Barradas
Em 24-11-2012 14:39, anoumou escreveu:

Dear R users.
I am little lost and i need your  help.
I have such data.
DATE   i Symptomes t
1   2009-04-24 Mexique 0 14358
2   2009-04-24 usa 0 14358
3   2009-04-26 Mexique18 14360
4   2009-04-26 usa   100 14360
5   2009-04-27  Canada 6 14361
6   2009-04-27 Mexique26 14361
7   2009-04-27   Spain 1 14361
8   2009-04-27 usa40 14361
9   2009-04-28 Canada  6 14362
10  2009-04-28 Israel  2 14362
11  2009-04-28 Mexique26 14362
12  2009-04-28   New Zealand   3 14362
13  2009-04-28  Spain  2 14362
14  2009-04-28 United Kingdom  2 14362
15  2009-04-28 usa64 14362
16  2009-04-29 Canada 13 14363
17  2009-04-29Austria  1 14363
18  2009-04-29 Germany 3 14363
19  2009-04-29 Israel  2 14363
20  2009-04-29 Mexique26 14363
21  2009-04-29   New Zealand   3 14363
22  2009-04-29   SPAIN 4 14363
23  2009-04-29 United Kingdom  5 14363
A data with a date in character format,i wich reprent a country,Symptomes
wich is a number of subjects having a disease,t the date convert in numeric.
I want to create two other variables (for example INCUBATION and CONTAGIEUX)
Incubation[ i ] add values for symptomes for the two previous days (for
t=t-1)

CONTAGIEUX [ i ] add values for symptomes for the 7 next days (for t=t+6).
I want the two variables INCUBATION and CONTAGIEUX to be cumulative for next
and previous date.

For example for

date   i   Symptomes   Incubation CONTAGIEUX
2009-04-24 Mexique   018+0   0

2009-04-26 Mexique   18   18+26   18+0

2009-04-27 MEXIQUE   26   18+26+...   18+26...
Thanks.




--
View this message in context: http://r.789695.n4.nabble.com/Help-tp4650647.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.



__
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] IMPORTANT!!!! PLEASE HELP ME

2012-11-24 Thread chuck.01
1st.  Calm down, this doesn't seem that important. 
Then you will need to know some base functions.
see 

?rnorm

Doing this 10,000 times and making them of size 50 is no problem.

FYI: I don't understand what with replacement case means; could you
clarify?



Jasmin wrote
 Hi,
 I want to generate 1 samples from normal distribution with 
 replacement case and every sample size is 50. What should I do ?





--
View this message in context: 
http://r.789695.n4.nabble.com/IMPORTANT-PLEASE-HELP-ME-tp4650676p4650677.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] Grouped data objects within GLS and Variogram

2012-11-24 Thread Matlack, Glenn
Dear R Help,

I am having difficulty using Variogram within GLS to examine spatial structure 
of nested data.  My data frame consists of ecological measurements of a forest, 
in which three landscape positions (landposi) are compared.  Each landscape 
position is replicated five times (replicat), and the environment is measured 
(canopy, litdepth, etc.) one hundred times at 50-cm intervals along a 
transect (distanc).  Thus, there are 1,500 rows of data.  The raw data file 
begins:

site landposi   replicat distanc  canopy litdepth   
 soilmoist  shrubcov soildepth
PionBbottom 1  0.5  2  14   
0  20   
1.82
PionBbottom 1  1  2  20 
  0  20 
  4.17
PionBbottom 1  1.5  3  26   
0  20   
2.6
PionBbottom 1  2  3  23 
  0  18 
  2.86
PionBbottom 1  2.5  1  14   
0  16.2 
   2.34

The general strategy follows Pinheiro and Bates' (2000; pp. 260-266) and 
Crawley's (2007; pp. 778-785) wheat-trials example: 1) groupedData is used to 
specify the nesting structure, 2) a GLS model is fit assuming no spatial 
autocorrelation, 3) spatial covariance is added using the Variogram function, 
and 4) spatial correlation structures are compared.  Before beginning, canopy 
(a percentage) is arcsin sqareroot transformed to trancano, and replicat is 
specified as a factor.

 smith-read.table(C:\\Users\\matlack\\Desktop\\Documents\\Undergrad 
 Research\\Nicole Smith\\smith.txt,header=T)
 attach(smith)
 trancano=(asin(sqrt(canopy/100)))
 replicat=factor(replicat)
 library(nlme)

Thus, the data are entered and transformed, and the appropriate library 
summoned.

 structure-groupedData(trancano~landposi|landposi/replicat)

Trancano is the response variable, landposi is the factor of interest, and 
replicat is a random effect nested within landposi.

 model-gls(trancano~landposi,structure)
 summary(model)

Generalized least squares fit by REML
Model: trancano ~ landposi
Data: structure
   AIC  BIC logLik
-4968.469 -4947.224 2488.235

Coefficients:
ValueStd.Error  
 t-value p-value
(Intercept)  0.17966306  0.002040385   88.05352 
 0.
landposiridge 0.00095435  0.002885540   0.33073 
0.7409
landposislope0.01226755  0.002885540   4.25139 
0.

   Correlation:
(Intr) lndpsr
Landposiridge-0.707
landposislope-0.7070.500

Standardized residuals:
   Min Q1  Med  
Q3  Max
-3.9587908  -0.7265938  -0.0819489  0.7360712   
 3.8154715

Residual standard error: 0.04562439
Degrees of freedom: 1500 total; 1497 residual

 plot(Variogram(model, form=~distanc) )

Error in as.data.frame.default(data, optional = TRUE) :
cannot coerce class 'function' into a data.frame

And here it stops.  For some reason, R seems to think there is a function in 
the grouped data object.  Despite a considerable amount of time spent in 
debugging, I cannot discover the reason.  I notice that Christina Silva 
described the same problem in the R-Help log a few years ago (11/19/2002), but 
her question doesn't seem to have been answered.

I greatly appreciate any advice or suggestions anyone can give me on this!

Many thanks,
Glenn Matlack
Athens, Ohio

[[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] Adding a new variable to each element of a list

2012-11-24 Thread Stephen Politzer-Ahles
Hello,

I have a list of data with multiple elements, and each element in the list
has multiple variables in it. Here's an example:

### Make the fake data
dv - c(1,3,4,2,2,3,2,5,6,3,4,4,3,5,6)
subject - factor(c(s1,s1,s1,s2,s2,s2,s3,s3,s3,
s4,s4,s4,s5,s5,s5))
myfactor - factor(c(f1,f2,f3,f1,f2,f3,f1,f2,f3,
f1,f2,f3,f1,f2,f3))
mydata - data.frame(dv, subject, myfactor)

### Do the anova and store the summary in result
mydata.aov - aov( dv ~ myfactor + Error(subject/myfactor), mydata )
( result - summary( mydata.aov ) ) # see the anova

str(result)

List of 2
 $ Error: subject :List of 1
  ..$ :Classes ‘anova’ and 'data.frame':1 obs. of  5 variables:
  .. ..$ Df : num 4
  .. ..$ Sum Sq : num 12.4
  .. ..$ Mean Sq: num 3.1
  .. ..$ F value: num NA
  .. ..$ Pr(F) : num NA
  ..- attr(*, class)= chr [1:2] summary.aov listof
 $ Error: subject:myfactor:List of 1
  ..$ :Classes ‘anova’ and 'data.frame':2 obs. of  5 variables:
  .. ..$ Df : num [1:2] 2 8
  .. ..$ Sum Sq : num [1:2] 14.9 4.4
  .. ..$ Mean Sq: num [1:2] 7.47 0.55
  .. ..$ F value: num [1:2] 13.6 NA
  .. ..$ Pr(F) : num [1:2] 0.00268 NA
  ..- attr(*, class)= chr [1:2] summary.aov listof

As you can see, each element in result has several variables (Df, Sum Sq,
Mean Sq, F value, Pr(F)):
str( result[[2]][[1]] )
Classes ‘anova’ and 'data.frame':   2 obs. of  5 variables:
 $ Df : num  2 8
 $ Sum Sq : num  14.9 4.4
 $ Mean Sq: num  7.47 0.55
 $ F value: num  13.6 NA
 $ Pr(F) : num  0.00268 NA

Now I also have another vector of numbers that I would like to add to the
list, as a 6th variable for each element:
y - c(.5, .7724138)

Ideally, I would like each element in the list (Error: subject and
Error: subject:myfactor) to have a 6th variable, so the new str() would
look like:
List of 2
 $ Error: subject :List of 1
  ..$ :Classes ‘anova’ and 'data.frame':1 obs. of  5 variables:
  .. ..$ Df : num 4
  .. ..$ Sum Sq : num 12.4
  .. ..$ Mean Sq: num 3.1
  .. ..$ F value: num NA
  .. ..$ Pr(F) : num NA
 * .. ..$ Thing  : num 0.50*
  ..- attr(*, class)= chr [1:2] summary.aov listof
 $ Error: subject:myfactor:List of 1
  ..$ :Classes ‘anova’ and 'data.frame':2 obs. of  5 variables:
  .. ..$ Df : num [1:2] 2 8
  .. ..$ Sum Sq : num [1:2] 14.9 4.4
  .. ..$ Mean Sq: num [1:2] 7.47 0.55
  .. ..$ F value: num [1:2] 13.6 NA
  .. ..$ Pr(F) : num [1:2] 0.00268 NA
  *.. ..$ Thing  : num **0.772413*
  ..- attr(*, class)= chr [1:2] summary.aov listof

Now, I know how to do this if I want to just add the variable to one
element at a time:
result[[1]][[1]]$Thing - 0.5

But I can't figure out how to do it for every element at once (other than
using a for loop). I am able to index an existing variable from each
element of a list (using lapply or sapply, based on the examples from
http://stackoverflow.com/questions/1355355/how-to-avoid-a-loop-in-r-selecting-items-from-a-listand
http://tolstoy.newcastle.edu.au/R/help/05/05/4678.html), but I can't figure
out how to *set* a new variable for each element in a list. Does anyone
know how to do this?

Thank you,
Steve Polizer-Ahles

-- 
Stephen Politzer-Ahles
University of Kansas
Linguistics Department
http://people.ku.edu/~sjpa/

[[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.


Re: [R] Designating a new year (Sept-Aug) in R

2012-11-24 Thread arun
Hi,
Try this:
dat1-read.table(text=
site,date,precipitation,temp_max,temp_min
Castle Peak,January-70,0,32,18
Castle Peak,January-70,0,39,9
Castle Peak,September-70,0,34,5
Castle Peak,September-70,0,30,7
Castle Peak,October-70,0,40,6
Castle Peak,November-70,0,45,10
Castle Peak,December-70,0,43,8
Castle Peak,October-71,0,42,7
Castle Peak,November-71,0,46,11
Castle Peak,December-71,0,41,9
,sep=,,stringsAsFactors=FALSE,header=TRUE)

Month1-c(September,October,November,December)

 dat1$date[gsub((.*)\\-.*,\\1,dat1$date)%in%Month1]-paste0(gsub((.*\\-).*,\\1,dat1$date[gsub((.*)\\-.*,\\1,dat1$date)%in%Month1]),as.numeric(gsub(.*\\-(.*),\\1,dat1$date[gsub((.*)\\-.*,\\1,dat1$date)%in%Month1]))+1)
dat1
#  site date precipitation temp_max temp_min
#1  Castle Peak   January-70 0   32   18
#2  Castle Peak   January-70 0   39    9
#3  Castle Peak September-71 0   34    5
#4  Castle Peak September-71 0   30    7
#5  Castle Peak   October-71 0   40    6
#6  Castle Peak  November-71 0   45   10
#7  Castle Peak  December-71 0   43    8
#8  Castle Peak   October-72 0   42    7
#9  Castle Peak  November-72 0   46   11
#10 Castle Peak  December-72 0   41    9
A.K.

A.K.




- Original Message -
From: nick pardikes npardi...@hotmail.com
To: r-help@R-project.org r-help@r-project.org
Cc: 
Sent: Saturday, November 24, 2012 4:01 PM
Subject: [R] Designating a new year (Sept-Aug) in R

If I have data (below) and need some help in figuring out how I can change the 
values of my date column, so that a year will be from September-August? So the 
year 
1990 = September 89-August 90; 1991
= September 90-August 91, etc... 

I was trying to use the if() function, but am unable to figure it out. I 
basically need to change the years associated with September-December to the 
following year. Any 
help would be greatly appreciated. Otherwise I will have to power through
it and do it all manually in excel. I am sorry that I do not have the original 
data associated with this posting, nor any R code with it. I really do not have 
a clue how to even start designating the new year. 

head(mydata)
class(mydata)
data.frame
         site            date                precipitation temp_max temp_min
1 Castle Peak January-70             0       32       18
2 Castle Peak January-70             0       39        9
3 Castle Peak January-70             0       34        5
4 Castle Peak January-70             0       30        7
5 Castle Peak January-70             0       40        6
6 Castle Peak January-70             0       45       10

Thank you in advance and please let me know what else I can include to help 
solve this issue. this is my first posting on R-help. 



Nick Pardikes
PhD Student
Program in Ecology, Evolution and Conservation Biology
University of Nevada, Reno
303-550-1072
http://wolfweb.unr.edu/homepage/npardikes/MySite/Welcome.html
                          
    [[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] Designating a new year (Sept-Aug) in R

2012-11-24 Thread Rui Barradas

Hello,

I don't know if this is it, do you want a 4 digit year or month-yy? The 
following function returns month-yy.



fun - function(x, format = %B-%y){
fmt - format
x - as.Date(paste(01, x, sep = -), format = paste(%d, fmt, 
sep = -))

m - as.integer(format(x, %m))
y - as.integer(format(x, %y))
y - ifelse(9 = m  m = 12, y + 1, y)
format(as.Date(paste(y, m, 1), %y %m %d), fmt)
}

x - Sys.Date() + 30*(-12:12)
x - format(x, %B-%y)

fun(x)

I don't believe it's hard to change to 4 digit year, just change the 
return format to %Y (last line of code).


Hope this helps,

Rui Barradas
Em 24-11-2012 21:01, nick pardikes escreveu:

If I have data (below) and need some help in figuring out how I can change the 
values of my date column, so that a year will be from September-August? So the 
year
1990 = September 89-August 90; 1991
  = September 90-August 91, etc...

I was trying to use the if() function, but am unable to figure it out. I 
basically need to change the years associated with September-December to the 
following year. Any
help would be greatly appreciated. Otherwise I will have to power through
  it and do it all manually in excel. I am sorry that I do not have the 
original data associated with this posting, nor any R code with it. I really do 
not have a clue how to even start designating the new year.

head(mydata)
class(mydata)
data.frame
  sitedateprecipitation temp_max temp_min
1 Castle Peak January-70 0   32   18
2 Castle Peak January-70 0   399
3 Castle Peak January-70 0   345
4 Castle Peak January-70 0   307
5 Castle Peak January-70 0   406
6 Castle Peak January-70 0   45   10

Thank you in advance and please let me know what else I can include to help 
solve this issue. this is my first posting on R-help.



Nick Pardikes
PhD Student
Program in Ecology, Evolution and Conservation Biology
University of Nevada, Reno
303-550-1072
http://wolfweb.unr.edu/homepage/npardikes/MySite/Welcome.html

[[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] Adding a new variable to each element of a list

2012-11-24 Thread arun
HI,

The example data you gave have only one row for the 1st element of list.  So, 
it would be better to add it as:
 lapply(result,function(x) {x[[2]]-y
 return(x)})
#$`Error: subject`
#Component 1 :
 #     Df Sum Sq Mean Sq F value Pr(F)
#Residuals  4   12.4 3.1   
#
#Component 2 :
#[1] 0.500 0.7724138
-
You can also do:
 lapply(result,function(x) {x[[1]][6]-y[1]
 x[[1]][7]-y[2]
 return(x)})
#$`Error: subject`
 #     Df Sum Sq Mean Sq F value Pr(F)  V6 V7
#Residuals  4   12.4 3.1    0.5 0.7724

#$`Error: subject:myfactor`
 #     Df Sum Sq Mean Sq F value   Pr(F)  V6 V7
#myfactor   2  14.93   7.467   13.58 0.002683 0.5 0.7724
#Residuals  8   4.40   0.550  0.5 0.7724    #Here it got 
repeated

May be there are better methods

A.K.





- Original Message -
From: Stephen Politzer-Ahles politzerahl...@gmail.com
To: r-help@r-project.org
Cc: 
Sent: Saturday, November 24, 2012 5:33 PM
Subject: [R] Adding a new variable to each element of a list

Hello,

I have a list of data with multiple elements, and each element in the list
has multiple variables in it. Here's an example:

### Make the fake data
dv - c(1,3,4,2,2,3,2,5,6,3,4,4,3,5,6)
subject - factor(c(s1,s1,s1,s2,s2,s2,s3,s3,s3,
s4,s4,s4,s5,s5,s5))
myfactor - factor(c(f1,f2,f3,f1,f2,f3,f1,f2,f3,
f1,f2,f3,f1,f2,f3))
mydata - data.frame(dv, subject, myfactor)

### Do the anova and store the summary in result
mydata.aov - aov( dv ~ myfactor + Error(subject/myfactor), mydata )
( result - summary( mydata.aov ) ) # see the anova

str(result)

List of 2
$ Error: subject         :List of 1
  ..$ :Classes ‘anova’ and 'data.frame':        1 obs. of  5 variables:
  .. ..$ Df     : num 4
  .. ..$ Sum Sq : num 12.4
  .. ..$ Mean Sq: num 3.1
  .. ..$ F value: num NA
  .. ..$ Pr(F) : num NA
  ..- attr(*, class)= chr [1:2] summary.aov listof
$ Error: subject:myfactor:List of 1
  ..$ :Classes ‘anova’ and 'data.frame':        2 obs. of  5 variables:
  .. ..$ Df     : num [1:2] 2 8
  .. ..$ Sum Sq : num [1:2] 14.9 4.4
  .. ..$ Mean Sq: num [1:2] 7.47 0.55
  .. ..$ F value: num [1:2] 13.6 NA
  .. ..$ Pr(F) : num [1:2] 0.00268 NA
  ..- attr(*, class)= chr [1:2] summary.aov listof

As you can see, each element in result has several variables (Df, Sum Sq,
Mean Sq, F value, Pr(F)):
str( result[[2]][[1]] )
Classes ‘anova’ and 'data.frame':       2 obs. of  5 variables:
$ Df     : num  2 8
$ Sum Sq : num  14.9 4.4
$ Mean Sq: num  7.47 0.55
$ F value: num  13.6 NA
$ Pr(F) : num  0.00268 NA

Now I also have another vector of numbers that I would like to add to the
list, as a 6th variable for each element:
y - c(.5, .7724138)

Ideally, I would like each element in the list (Error: subject and
Error: subject:myfactor) to have a 6th variable, so the new str() would
look like:
List of 2
$ Error: subject         :List of 1
  ..$ :Classes ‘anova’ and 'data.frame':        1 obs. of  5 variables:
  .. ..$ Df     : num 4
  .. ..$ Sum Sq : num 12.4
  .. ..$ Mean Sq: num 3.1
  .. ..$ F value: num NA
  .. ..$ Pr(F) : num NA
* .. ..$ Thing  : num 0.50*
  ..- attr(*, class)= chr [1:2] summary.aov listof
$ Error: subject:myfactor:List of 1
  ..$ :Classes ‘anova’ and 'data.frame':        2 obs. of  5 variables:
  .. ..$ Df     : num [1:2] 2 8
  .. ..$ Sum Sq : num [1:2] 14.9 4.4
  .. ..$ Mean Sq: num [1:2] 7.47 0.55
  .. ..$ F value: num [1:2] 13.6 NA
  .. ..$ Pr(F) : num [1:2] 0.00268 NA
  *.. ..$ Thing  : num **0.772413*
  ..- attr(*, class)= chr [1:2] summary.aov listof

Now, I know how to do this if I want to just add the variable to one
element at a time:
result[[1]][[1]]$Thing - 0.5

But I can't figure out how to do it for every element at once (other than
using a for loop). I am able to index an existing variable from each
element of a list (using lapply or sapply, based on the examples from
http://stackoverflow.com/questions/1355355/how-to-avoid-a-loop-in-r-selecting-items-from-a-listand
http://tolstoy.newcastle.edu.au/R/help/05/05/4678.html), but I can't figure
out how to *set* a new variable for each element in a list. Does anyone
know how to do this?

Thank you,
Steve Polizer-Ahles

-- 
Stephen Politzer-Ahles
University of Kansas
Linguistics Department
http://people.ku.edu/~sjpa/

    [[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] IMPORTANT!!!! PLEASE HELP ME

2012-11-24 Thread Pete Brecknock
jholtman wrote
 What do you want to do with the samples after you generate them?  What
 are the parameters for the normal distribution?  You left a lot of
 information out.  You can generate 500,000 numbers and then store them
 in a 1x50 matrix quite easily.
 
 On Sat, Nov 24, 2012 at 5:03 PM, Jasmin lt;

 yasemin_deniz89@

 gt; wrote:
 Hi,
 I want to generate 1 samples from normal distribution with 
 replacement
 case and every sample size is 50. What should I do ?



 --
 View this message in context:
 http://r.789695.n4.nabble.com/IMPORTANT-PLEASE-HELP-ME-tp4650676.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 

 R-help@

  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.
 
 
 
 -- 
 Jim Holtman
 Data Munger Guru
 
 What is the problem that you are trying to solve?
 Tell me what you want to do, not how you want to do it.
 
 __

 R-help@

  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.


maybe ...

replicate(1, rnorm(50))

could work for you

HTH

Pete



--
View this message in context: 
http://r.789695.n4.nabble.com/IMPORTANT-PLEASE-HELP-ME-tp4650676p4650686.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.


Re: [R] Comparing the Means of Two Normal Distributions

2012-11-24 Thread Greg Snow
You have all the information that you need to do the pooled t-test using
the formula in many intro stats textbooks and probably on wikipedia as
well, just plug your numbers into the formulas in the book (R can act as
the calculator to make this easier).

Or sometimes simpler (for the human, the computer does more work, but that
is what it is for) is to do like chuck.01 suggests and simulate the data,
however chuck.01 left out a step, you should make sure that the simulated
data has the exact same mean and standard deviation as you provide, then
the results will be the same as if you used the formula (other than
possible slight rounding errors).  Generate the 2 samples from normals with
mean 0 and standard deviation 1, then use the scale function to make sure
that the means are exactly 0 and standard deviations exactly 1.  Now
multiply by the proper standard deviation then add the appropriate mean,
then use the t.test function to analyze.


On Sat, Nov 24, 2012 at 11:28 AM, Lorenzo Isella
lorenzo.ise...@gmail.comwrote:

 Dear All,
 A problem almost taken from a textbook: I have two independent samples
 (which are both assumed to come from a normal distribution).
 The sample sizes are N1 and N2, the sample means are x1 and x2 and the
 sample standard deviations are s1 and s2 (the standard deviations are
 close).
 I would like to conduct a two sample t-test with equal variances at
 alpha=0.05 (and then remove the assumption of equal variances).
 I have come across several resources

 http://bit.ly/WKGuHV
 http://bit.ly/WKGwzG

 but the difference here is that I have access only to the N,x and s for
 the two samples, NOT to the results of every observation (i.e I know for
 instance N1 x1 and s1, but I do not have the corresponding list of N1
 values).
 Many thanks for any suggestions.
 Best Regards

 Lorenzo

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[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.


Re: [R] Summary statistics for matrix columns

2012-11-24 Thread David Winsemius


On Nov 24, 2012, at 4:58 AM, frespider wrote:




HI A.k,

I need one more question, if you can answer it please

M - matrix(sample(1:8000),nrow=100)
colnames(M)- paste(Col,1:ncol(M),sep=)
apply(M,2,function(x) c(Min=min(x),1st Qu =quantile(x,  
0.25,names=FALSE),

   Range = range(x),
   Median = quantile(x, 0.5, names=FALSE),
   Mean= mean(x),Std=sd(x),
   3rd Qu = quantile(x,0.75,names=FALSE),
   IQR=IQR(x),Max = max(x)))

why I get two range . isn't range mean the different between the max  
and min


If you want the span (what you are calling the range) of the range  
(min and max) you can do this:


myRange = diff(range(x))

--
David






David Winsemius, MD
Alameda, CA, USA

__
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] IMPORTANT!!!! PLEASE HELP ME

2012-11-24 Thread Pete Brecknock
Jasmin wrote
 I try to use hansen-hurwitz and horvitz-thompson estimator.So I should
 generate samples which come from normal distribution (mu=50,sigma=3).

I have taken the liberty of scaling the problem down to something more
digestible and have changed lines 5 and 7 in your code

nsamples=10
sampsize=5 
i=0 
y=matrix(rnorm(nsamples*sampsize,50,3),nrow=nsamples) 
s=matrix(NA,10,5) 
for(i in 1:10){ 
s[i,]=sample(y,5,replace=T) 
}

HTH

Pete



--
View this message in context: 
http://r.789695.n4.nabble.com/IMPORTANT-PLEASE-HELP-ME-tp4650676p4650692.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] Comparing linear regression coefficients to a slope of 1

2012-11-24 Thread Catriona Hendry
Hi!

I have a question that is probably very basic, but I cannot figure out how
to do it. I simply need to compare the significance of a regression slope
against a slope of 1, instead of the default of zero.

I know this topic has been posted before, and I have tried to use the
advice given to others to fix my problem. I tried the offset command based
on one of these advice threads as follows:

Regression - lm(y~x+offset(1*x))

but this resulted in a regression line that was plotted perpendicular to
the data when added with the abline function.

I would be extremely grateful for your help!!

Thanks!!

Cat

[[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] Iterate by Factor - Newbie Question

2012-11-24 Thread Thomas Ottaway
I have end of semester teaching evaluation data of the following form:

 head(evaluations)
   Course Prefix Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14
1 2330301  2  4  3  3  3  4  4  1  2  5   4   1   1   1   1
2 2330301  2  3  3  3  3  3  5  1  2  5   8   1   1   1   1
3 2330301  2  4  4  3  3  4  4  2  2  5   9   1   1   1   1
4 2330301  2  2  1  1  3  4  5  1  2  5   8   1   1   1   1
5 2330301  2  4  3  4  4  4  3  1  3  5   8   1   3   1   1
6 2330301  2  3  4  2  2  4  2  2  2  5   9   1   1   1   1

There are 90 levels, representing each of the courses taught in my
college.  I have figured out how to process by level using:

# Read in raw data files
setwd(College\\Evals)
evaluations - read.csv(file=spring2012.csv,head=TRUE,sep=,)

# Determine and display factors
courses = factor(evaluations$Course)
table(courses)

# Get summary statistics by factor
by(evaluations, courses, summary)

What I would like to do is create a separate printed page for each
course so that I can hand them out to the faculty.  I would like each
page to contain a title, the number of respondents, some summary
statistics, and a histogram.  I need to be able to use a second
dataframe containing the course (id), course title, and faculty member
name.  Despite a few hours of searching on Google and pecking away at
the keyboard, I have been unable to figure out how to replace
summary in the above by statement with a function that will accept
and process the necessary data.  Am I even on the right track?  Any
pointers will be greatly appreciated, this is my first foray into R.

Tom
--
Thomas A. Ottaway, Ph.D.
Interim Dean
Professor of Computer Information Systems
College of Business
Idaho State University
921 South 8th Street
Pocatello, ID  83209-8020
(208) 282-2601

__
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] Comparing linear regression coefficients to a slope of 1

2012-11-24 Thread Albyn Jones
Is this homework?  
 
PLEASE do read the posting guide 
   http://www.R-project.org/posting-guide.html

albyn

On Sat, Nov 24, 2012 at 07:27:25PM -0500, Catriona Hendry wrote:
 Hi!
 
 I have a question that is probably very basic, but I cannot figure out how
 to do it. I simply need to compare the significance of a regression slope
 against a slope of 1, instead of the default of zero.
 
 I know this topic has been posted before, and I have tried to use the
 advice given to others to fix my problem. I tried the offset command based
 on one of these advice threads as follows:
 
 Regression - lm(y~x+offset(1*x))
 
 but this resulted in a regression line that was plotted perpendicular to
 the data when added with the abline function.
 
 I would be extremely grateful for your help!!
 
 Thanks!!
 
 Cat
 
   [[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.
 

-- 
Albyn Jones
Reed College
jo...@reed.edu

__
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] Comparing linear regression coefficients to a slope of 1

2012-11-24 Thread Bert Gunter
1. The model is correct :  lm( y~ x + offset(x))
( AFAICS)

2. Read the posting guide, please: Code? I do not know what you mean by:
 this resulted in a regression line that was plotted perpendicular to
the data when added with the abline function.

Of course, maybe someone else will groc this.

3. I wonder if you really want to do what you are doing, anyway. For
example, in comparing two assays to see whether they give similar
results, you would **not** do what you are doing. If you care to follow up
on this, I suggest you post complete context to a statistical mailing list,
not here, like stats.stackexchange .com.  Also, feel free to ignore me, of
course. I'm just guessing.

Cheers,
Bert

Cheers,
Bert


On Sat, Nov 24, 2012 at 4:27 PM, Catriona Hendry hen...@gwmail.gwu.eduwrote:

 Hi!

 I have a question that is probably very basic, but I cannot figure out how
 to do it. I simply need to compare the significance of a regression slope
 against a slope of 1, instead of the default of zero.

 I know this topic has been posted before, and I have tried to use the
 advice given to others to fix my problem. I tried the offset command based
 on one of these advice threads as follows:

 Regression - lm(y~x+offset(1*x))

 but this resulted in a regression line that was plotted perpendicular to
 the data when added with the abline function.

 I would be extremely grateful for your help!!

 Thanks!!

 Cat

 [[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.




-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

[[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.


Re: [R] Designating a new year (Sept-Aug) in R

2012-11-24 Thread arun
HI,
If you need to order the dates.

dat1-read.table(text=
site,date,precipitation,temp_max,temp_min
Castle Peak,January-70,0,32,18
Castle Peak,January-70,0,39,9
Castle Peak,September-70,0,34,5
Castle Peak,September-70,0,30,7
Castle Peak,October-70,0,40,6
Castle Peak,November-70,0,45,10
Castle Peak,December-70,0,43,8
Castle Peak,January-71,0,42,6
Castle Peak,February-71,0,38,5
CastlePeak,March-71,0,46,10
Castle Peak,October-71,0,42,7
Castle Peak,November-71,0,46,11
Castle Peak,December-71,0,41,9
,sep=,,stringsAsFactors=FALSE,header=TRUE)
Month1-c(September,October,November,December)

 dat1$date[gsub((.*)\\-.*,\\1,dat1$date)%in%Month1]-paste0(gsub((.*\\-).*,\\1,dat1$date[gsub((.*)\\-.*,\\1,dat1$date)%in%Month1]),as.numeric(gsub(.*\\-(.*),\\1,dat1$date[gsub((.*)\\-.*,\\1,dat1$date)%in%Month1]))+1)

library(zoo)
dat1$date-as.Date(as.yearmon(dat1$date,%B-%y),format=%b %Y)
dat2-dat1[order(dat1$date),]
dat2$date-as.yearmon(dat2$date,format=%Y-%m-%d)
row.names(dat2)-1:nrow(dat2)
 dat2
#  site date precipitation temp_max temp_min
#1  Castle Peak Jan 1970 0   32   18
#2  Castle Peak Jan 1970 0   39    9
#3  Castle Peak Jan 1971 0   42    6
#4  Castle Peak Feb 1971 0   38    5
#5   CastlePeak Mar 1971 0   46   10
#6  Castle Peak Sep 1971 0   34    5
#7  Castle Peak Sep 1971 0   30    7
#8  Castle Peak Oct 1971 0   40    6
#9  Castle Peak Nov 1971 0   45   10
#10 Castle Peak Dec 1971 0   43    8
#11 Castle Peak Oct 1972 0   42    7
#12 Castle Peak Nov 1972 0   46   11
#13 Castle Peak Dec 1972 0   41    9

A.K.

- Original Message -
From: nick pardikes npardi...@hotmail.com
To: r-help@R-project.org r-help@r-project.org
Cc: 
Sent: Saturday, November 24, 2012 4:01 PM
Subject: [R] Designating a new year (Sept-Aug) in R

If I have data (below) and need some help in figuring out how I can change the 
values of my date column, so that a year will be from September-August? So the 
year 
1990 = September 89-August 90; 1991
= September 90-August 91, etc... 

I was trying to use the if() function, but am unable to figure it out. I 
basically need to change the years associated with September-December to the 
following year. Any 
help would be greatly appreciated. Otherwise I will have to power through
it and do it all manually in excel. I am sorry that I do not have the original 
data associated with this posting, nor any R code with it. I really do not have 
a clue how to even start designating the new year. 

head(mydata)
class(mydata)
data.frame
         site            date                precipitation temp_max temp_min
1 Castle Peak January-70             0       32       18
2 Castle Peak January-70             0       39        9
3 Castle Peak January-70             0       34        5
4 Castle Peak January-70             0       30        7
5 Castle Peak January-70             0       40        6
6 Castle Peak January-70             0       45       10

Thank you in advance and please let me know what else I can include to help 
solve this issue. this is my first posting on R-help. 



Nick Pardikes
PhD Student
Program in Ecology, Evolution and Conservation Biology
University of Nevada, Reno
303-550-1072
http://wolfweb.unr.edu/homepage/npardikes/MySite/Welcome.html
                          
    [[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] Comparing linear regression coefficients to a slope of 1

2012-11-24 Thread David Winsemius


On Nov 24, 2012, at 4:27 PM, Catriona Hendry wrote:


Hi!

I have a question that is probably very basic, but I cannot figure  
out how
to do it. I simply need to compare the significance of a regression  
slope

against a slope of 1, instead of the default of zero.

I know this topic has been posted before, and I have tried to use the
advice given to others to fix my problem. I tried the offset command  
based

on one of these advice threads as follows:

Regression - lm(y~x+offset(1*x))

but this resulted in a regression line that was plotted  
perpendicular to

the data when added with the abline function.



If the slope were in fact == 1 then what would the offset need to be  
to correct it so that it were == 0?


Failing this effort at clapping one hand, then please produce the  
requested dataset and other bits of window dressing requested in the  
Posting Guide, including whether this is a homework problem and what  
your academic institution's expectations are for soliciting help over  
the Internet.


--

David Winsemius, MD
Alameda, CA, USA

__
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] Comparing linear regression coefficients to a slope of 1

2012-11-24 Thread Catriona Hendry
Hi,

@ Albyn, David.. No, its not homework. Its basic groundwork for testing
allometric relationships for a graduate project I am working on. I read the
guide before posting, I spent half the day trying to understand how I am
going wrong based on the advice given to others.

@Bert, David... I apologise for the lack of code, I wasn't sure how to
explain my problem and I guess I went about it the wrong way.

I do think this is what I need to be doing, I am testing allometric
relationships of body size against a predicted isometric (1:1)
relationship. So I would like to know if the relationship between my
variables deviates from that.

Hopefully the information below will be what is needed.

Here is the part of the code relevant to the regression and plot:


plot(Contrast_log_MTL_ALL, Contrast_log_FTL_ALL)

Regression_PhyloContrasts_ALL - lm(Contrast_log_FTL_ALL ~
Contrast_log_MTL_ALL, offset=1*Contrast_log_MTL_ALL)
abline(Regression_PhyloContrasts_ALL)

the plot that resulted is attached as an image file.


Below are the vectors of my variables. The are converted from other values
imported and indexed from a csv file, so unfortunately I don't have matrix
set up for them.

  Contrast_log_FTL_ALL Contrast_Log_MTL_ALL  83 0.226593 0.284521  84
0.165517 0.084462  85 -0.1902 -0.0055  86 0.585176 0.639916  87 -0.01078
0.118011  88 0.161142 0.073762  89 -0.08566 -0.04788  90 -0.13818 -0.0524
91 -0.02504 -0.21099  92 -0.05027 -0.07594  93 -0.11399 -0.07251  94
-0.07299 -0.08247  95 -0.09507 -0.04817  96 0.207591 0.151695  97 -0.14224
-0.05097  98 0.06375 -0.0229  99 0.04607 0.06246  100 0.257389 0.190531  101
-0.0612 -0.10902  102 -0.1981 -0.24698  103 -0.12328 -0.36942  104 0.269877
0.341989  105 0.125377 0.227183  106 0.087038 -0.05962  107 0.114929
0.096112  108 0.252807 0.305583  109 -0.0895 -0.08586  110 -0.38483 -0.20671
111 -0.72506 -0.63785  112 -0.37212 -0.21458  113 0.010348 0.117577  114
-0.09625 -0.0059  115 -0.26291 -0.25986  116 0.056922 0.064041  117 0.051472
-0.09747  118 -0.05691 0.075005  119 0.117095 -0.15497  120 -0.01329
-0.12473  121 0.098725 0.020522  122 -0.0019 -0.01998  123 -0.12446 -0.02312
124 0.019234 0.031391  125 0.385366 0.391766  126 0.495518 0.468946  127
-0.09251 -0.08045  128 0.147965 0.139117  129 -0.03143 -0.02319  130
-0.19801 -0.14924  131 0.014104 -0.01917  132 0.031872 -0.01381  133
-0.01412 -0.04381  134 -0.12864 -0.08527  135 -0.07179 -0.03525  136 0.31003
0.29553  137 -0.09347 -0.11903  138 -0.10706 -0.16654  139 0.078655 0.065509
140 0.08279 -0.00766  141 0.181885 0.001414  142 0.345818 0.496323  143
0.235044 0.095073  144 -0.03022 0.039918  145 0.042577 0.136586  146
0.064208 0.001379  147 -0.02237 -0.03009  148 -3.55E-05 0.040197  149
0.011168 0.087116  150 0.019964 0.071822  151 -0.04602 -0.06616  152
0.083087 0.038592  153 0.032078 0.107237  154 -0.21108 -0.22347  155
0.122959 0.297917  156 -0.05898 0.012547  157 -0.07584 -0.21588  158
-0.00929 -0.06864  159 -0.01211 -0.04559  160 0.090948 0.136582  161
0.016974 0.018259  162 -0.04083 0.016245  163 -0.20328 -0.31678






On Sat, Nov 24, 2012 at 8:22 PM, Bert Gunter gunter.ber...@gene.com wrote:

 1. The model is correct :  lm( y~ x + offset(x))
 ( AFAICS)

 2. Read the posting guide, please: Code? I do not know what you mean by:

  this resulted in a regression line that was plotted perpendicular to
 the data when added with the abline function.

 Of course, maybe someone else will groc this.

 3. I wonder if you really want to do what you are doing, anyway. For
 example, in comparing two assays to see whether they give similar
 results, you would **not** do what you are doing. If you care to follow up
 on this, I suggest you post complete context to a statistical mailing list,
 not here, like stats.stackexchange .com.  Also, feel free to ignore me, of
 course. I'm just guessing.

 Cheers,
 Bert

 Cheers,
 Bert


 On Sat, Nov 24, 2012 at 4:27 PM, Catriona Hendry hen...@gwmail.gwu.eduwrote:

 Hi!

 I have a question that is probably very basic, but I cannot figure out how
 to do it. I simply need to compare the significance of a regression slope
 against a slope of 1, instead of the default of zero.

 I know this topic has been posted before, and I have tried to use the
 advice given to others to fix my problem. I tried the offset command based
 on one of these advice threads as follows:

 Regression - lm(y~x+offset(1*x))

 but this resulted in a regression line that was plotted perpendicular to
 the data when added with the abline function.

 I would be extremely grateful for your help!!

 Thanks!!

 Cat

 [[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.




 --

 Bert Gunter
 Genentech Nonclinical Biostatistics

 Internal Contact Info:
 Phone: 

Re: [R] Comparing linear regression coefficients to a slope of 1

2012-11-24 Thread David Winsemius


On Nov 24, 2012, at 6:05 PM, Catriona Hendry wrote:


Hi,

@ Albyn, David.. No, its not homework. Its basic groundwork for  
testing
allometric relationships for a graduate project I am working on. I  
read the
guide before posting, I spent half the day trying to understand how  
I am

going wrong based on the advice given to others.

@Bert, David... I apologise for the lack of code, I wasn't sure how to
explain my problem and I guess I went about it the wrong way.

I do think this is what I need to be doing, I am testing allometric
relationships of body size against a predicted isometric (1:1)
relationship. So I would like to know if the relationship between my
variables deviates from that.

Hopefully the information below will be what is needed.

Here is the part of the code relevant to the regression and plot:



plot(Contrast_log_MTL_ALL, Contrast_log_FTL_ALL)


It's kind of a pain that you spell these different than they are named  
below.





Regression_PhyloContrasts_ALL - lm(Contrast_log_FTL_ALL ~

Contrast_log_MTL_ALL, offset=1*Contrast_log_MTL_ALL)


That looks fine. What's the problem? (Now you need to be examining the  
lm-object with the usual R tools. )



abline(Regression_PhyloContrasts_ALL)


abline should be given an argument of 0 for a and 1 for b if the  
goal were to plot a line for a predicted regression result of unity  
slope. If that's not the goal then you need to be more forthcoming.




the plot that resulted is attached as an image file.


No, it's not. Somewhere (not very prominently displayed) on either the  
Posting Guide or on the information page for Rhelp is it stated that  
most attachements are thrown away. They need to be .txt, .png, .pdf,  
or .ps.  They cannot be .csv, .xls, .dat, .sas7dat or anything else.





Below are the vectors of my variables. The are converted from other  
values
imported and indexed from a csv file, so unfortunately I don't have  
matrix

set up for them.

 Contrast_log_FTL_ALL Contrast_Log_MTL_ALL  83 0.226593 0.284521  84
0.165517 0.084462  85 -0.1902 -0.0055  86 0.585176 0.639916  87  
-0.01078
0.118011  88 0.161142 0.073762  89 -0.08566 -0.04788  90 -0.13818  
-0.0524

91 -0.02504 -0.21099  92 -0.05027 -0.07594  93 -0.11399 -0.07251  94
-0.07299 -0.08247  95 -0.09507 -0.04817  96 0.207591 0.151695  97  
-0.14224
-0.05097  98 0.06375 -0.0229  99 0.04607 0.06246  100 0.257389  
0.190531  101
-0.0612 -0.10902  102 -0.1981 -0.24698  103 -0.12328 -0.36942  104  
0.269877

0.341989  105 0.125377 0.227183  106 0.087038 -0.05962  107 0.114929
0.096112  108 0.252807 0.305583  109 -0.0895 -0.08586  110 -0.38483  
-0.20671
111 -0.72506 -0.63785  112 -0.37212 -0.21458  113 0.010348 0.117577   
114
-0.09625 -0.0059  115 -0.26291 -0.25986  116 0.056922 0.064041  117  
0.051472

-0.09747  118 -0.05691 0.075005  119 0.117095 -0.15497  120 -0.01329
-0.12473  121 0.098725 0.020522  122 -0.0019 -0.01998  123 -0.12446  
-0.02312
124 0.019234 0.031391  125 0.385366 0.391766  126 0.495518 0.468946   
127

-0.09251 -0.08045  128 0.147965 0.139117  129 -0.03143 -0.02319  130
-0.19801 -0.14924  131 0.014104 -0.01917  132 0.031872 -0.01381  133
-0.01412 -0.04381  134 -0.12864 -0.08527  135 -0.07179 -0.03525  136  
0.31003
0.29553  137 -0.09347 -0.11903  138 -0.10706 -0.16654  139 0.078655  
0.065509
140 0.08279 -0.00766  141 0.181885 0.001414  142 0.345818 0.496323   
143

0.235044 0.095073  144 -0.03022 0.039918  145 0.042577 0.136586  146
0.064208 0.001379  147 -0.02237 -0.03009  148 -3.55E-05 0.040197  149
0.011168 0.087116  150 0.019964 0.071822  151 -0.04602 -0.06616  152
0.083087 0.038592  153 0.032078 0.107237  154 -0.21108 -0.22347  155
0.122959 0.297917  156 -0.05898 0.012547  157 -0.07584 -0.21588  158
-0.00929 -0.06864  159 -0.01211 -0.04559  160 0.090948 0.136582  161
0.016974 0.018259  162 -0.04083 0.016245  163 -0.20328 -0.31678



Lean to use dput()

I needed to use these commands to read this irregularly dispaly list  
of numbers:

:

dat - scan()
mat - matrix(dat, ncol=3, byrow=TRUE)
datf - as.data.frame(mat)
names(datf) - c(index, Contrast_log_FTL,Contrast_Log_MTL)

--
David.





On Sat, Nov 24, 2012 at 8:22 PM, Bert Gunter  
gunter.ber...@gene.com wrote:



1. The model is correct :  lm( y~ x + offset(x))
( AFAICS)

2. Read the posting guide, please: Code? I do not know what you  
mean by:


 this resulted in a regression line that was plotted perpendicular  
to

the data when added with the abline function.

Of course, maybe someone else will groc this.

3. I wonder if you really want to do what you are doing, anyway. For
example, in comparing two assays to see whether they give similar
results, you would **not** do what you are doing. If you care to  
follow up
on this, I suggest you post complete context to a statistical  
mailing list,
not here, like stats.stackexchange .com.  Also, feel free to ignore  
me, of

course. I'm just guessing.

Cheers,
Bert

Cheers,
Bert


On Sat, Nov 24, 2012 at 4:27 PM, Catriona Hendry 

Re: [R] Iterate by Factor - Newbie Question

2012-11-24 Thread jim holtman
Hard to tell without the rest of the data.  You can probably use
'merge' to add the data from the second file to the first.  If you
want printed pages, then you can just have a 'for' loop that goes
through the dataframe creating the lines of output you want on the
report and then insert a 'form feed' character between the pages and
then you just route the text file to a printer.

SO if this does not solve your problem, more information/detail would
be required.

On Sat, Nov 24, 2012 at 7:55 PM, Thomas Ottaway ottat...@isu.edu wrote:
 I have end of semester teaching evaluation data of the following form:

 head(evaluations)
Course Prefix Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14
 1 2330301  2  4  3  3  3  4  4  1  2  5   4   1   1   1   1
 2 2330301  2  3  3  3  3  3  5  1  2  5   8   1   1   1   1
 3 2330301  2  4  4  3  3  4  4  2  2  5   9   1   1   1   1
 4 2330301  2  2  1  1  3  4  5  1  2  5   8   1   1   1   1
 5 2330301  2  4  3  4  4  4  3  1  3  5   8   1   3   1   1
 6 2330301  2  3  4  2  2  4  2  2  2  5   9   1   1   1   1

 There are 90 levels, representing each of the courses taught in my
 college.  I have figured out how to process by level using:

 # Read in raw data files
 setwd(College\\Evals)
 evaluations - read.csv(file=spring2012.csv,head=TRUE,sep=,)

 # Determine and display factors
 courses = factor(evaluations$Course)
 table(courses)

 # Get summary statistics by factor
 by(evaluations, courses, summary)

 What I would like to do is create a separate printed page for each
 course so that I can hand them out to the faculty.  I would like each
 page to contain a title, the number of respondents, some summary
 statistics, and a histogram.  I need to be able to use a second
 dataframe containing the course (id), course title, and faculty member
 name.  Despite a few hours of searching on Google and pecking away at
 the keyboard, I have been unable to figure out how to replace
 summary in the above by statement with a function that will accept
 and process the necessary data.  Am I even on the right track?  Any
 pointers will be greatly appreciated, this is my first foray into R.

 Tom
 --
 Thomas A. Ottaway, Ph.D.
 Interim Dean
 Professor of Computer Information Systems
 College of Business
 Idaho State University
 921 South 8th Street
 Pocatello, ID  83209-8020
 (208) 282-2601

 __
 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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
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] printing difftime summary

2012-11-24 Thread Sam Steingold
 * David Winsemius qjvafrz...@pbzpnfg.arg [2012-11-23 13:14:17 -0800]:

 See 
 http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-should-I-write-summary-methods_003f

--8---cut here---start-8---
summary.difftime - function (v) {
  s - summary(as.numeric(v))
  r - as.data.frame(sapply(s,difftime2string),stringsAsFactors=FALSE)
  names(r) - c(string)
  r[[units(v)]] - s
  class(r) - c(data.frame,summary.difftime)
  r
}
print.summary.difftime - function (sd) print.data.frame(sd)
--8---cut here---end---8---

it appears to work for a single vector:

--8---cut here---start-8---
 r1 - summary(infl$delay)
 r1
   string secs
Min.492.00 ms  0.5
1st Qu. 18.08 min   1085.0
Median   1.77 hrs   6370.0
Mean 8.20 hrs  29530.0
3rd Qu.  8.12 hrs  29250.0
Max.6.98 days 602900.0
 str(r1)
Classes 'summary.difftime' and 'data.frame':6 obs. of  2 variables:
 $ string: chr  492.00 ms 18.08 min 1.77 hrs 8.20 hrs ...
 $ secs  :Classes 'summaryDefault', 'table'  num [1:6] 4.92e-01 1.08e+03 
6.37e+03 2.95e+04 2.92e+04 ...
--8---cut here---end---8---

but not as a part of data frame:

--8---cut here---start-8---
 a - summary(infl)
Error in summary.difftime(X[[22L]], ...) : 
  unused argument(s) (maxsum = 7, digits = 12)
--8---cut here---end---8---

I guess I should somehow accept a list of options in summary.difftime()
and pass them on to the inner call to summary() (or should it be
explicitly summary.numeric()?)

how do I do that?

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://camera.org http://jihadwatch.org
http://americancensorship.org http://truepeace.org http://memri.org
Why do you never call me back after I scream that I will never talk to you 
again?!

__
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] Bayes Logit

2012-11-24 Thread Tjun Kiat Teo
I tried to use mlogit.R in the package Bayes Logit and got this error
message

Error in .C(rpg_devroye, x, as.integer(n), z, as.integer(num), PACKAGE =
BayesLogit) :
  C symbol name rpg_devroye not in DLL for package BayesLogit)

Can anyone help?

Thanks

Tjun Kiat

[[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.


Re: [R] How to Label Cases in Scatterplots?

2012-11-24 Thread Jim Lemon

On 11/25/2012 03:04 AM, john55 wrote:

Hi everyone,

i´m trying to graphically display distributions with r and i´m working with
makrodata from the WVS.

the command i´m using is


plot (Makrodata$v11, Makrodata$v12, xlab=Democracy Score Economist,
ylab= share religious people)



i´m having an additional variable that identifies respectively labels the
cases with its country name.
how can i implement that variable, so it identifies the various cases in the
scatterplot and looks like the spss screenshot i posted below?

http://r.789695.n4.nabble.com/file/n4650650/Unbenannt.gif


Hi john55,
This looks like thigmophobe.labels (plotrix), although it would be hard 
to avoid label overlapping with points that crowded.


Jim

__
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] Comparing linear regression coefficients to a slope of 1

2012-11-24 Thread Albyn Jones

Dear Cat

My apologies for presuming...

Here's a primitive solution:  compute a t-statistic or CI.

t = (beta-hat - 1)/SE(beta-hat), compare to qt(.975, res.df)

Or Better, compute the 95% confidence interval

  beta-hat + c(-1,1)*qt(.975, res.df)*SE(beta-hat)

albyn

On 2012-11-24 18:05, Catriona Hendry wrote:

Hi,

@ Albyn, David.. No, its not homework. Its basic groundwork for 
testing
allometric relationships for a graduate project I am working on. I 
read the
guide before posting, I spent half the day trying to understand how I 
am

going wrong based on the advice given to others.

@Bert, David... I apologise for the lack of code, I wasn't sure how 
to

explain my problem and I guess I went about it the wrong way.

I do think this is what I need to be doing, I am testing allometric
relationships of body size against a predicted isometric (1:1)
relationship. So I would like to know if the relationship between my
variables deviates from that.

Hopefully the information below will be what is needed.

Here is the part of the code relevant to the regression and plot:



plot(Contrast_log_MTL_ALL, Contrast_log_FTL_ALL)



Regression_PhyloContrasts_ALL - lm(Contrast_log_FTL_ALL ~

Contrast_log_MTL_ALL, offset=1*Contrast_log_MTL_ALL)
abline(Regression_PhyloContrasts_ALL)

the plot that resulted is attached as an image file.


Below are the vectors of my variables. The are converted from other 
values
imported and indexed from a csv file, so unfortunately I don't have 
matrix

set up for them.

  Contrast_log_FTL_ALL Contrast_Log_MTL_ALL  83 0.226593 0.284521  84
0.165517 0.084462  85 -0.1902 -0.0055  86 0.585176 0.639916  87 
-0.01078
0.118011  88 0.161142 0.073762  89 -0.08566 -0.04788  90 -0.13818 
-0.0524

91 -0.02504 -0.21099  92 -0.05027 -0.07594  93 -0.11399 -0.07251  94
-0.07299 -0.08247  95 -0.09507 -0.04817  96 0.207591 0.151695  97 
-0.14224
-0.05097  98 0.06375 -0.0229  99 0.04607 0.06246  100 0.257389 
0.190531  101
-0.0612 -0.10902  102 -0.1981 -0.24698  103 -0.12328 -0.36942  104 
0.269877

0.341989  105 0.125377 0.227183  106 0.087038 -0.05962  107 0.114929
0.096112  108 0.252807 0.305583  109 -0.0895 -0.08586  110 -0.38483 
-0.20671
111 -0.72506 -0.63785  112 -0.37212 -0.21458  113 0.010348 0.117577  
114
-0.09625 -0.0059  115 -0.26291 -0.25986  116 0.056922 0.064041  117 
0.051472

-0.09747  118 -0.05691 0.075005  119 0.117095 -0.15497  120 -0.01329
-0.12473  121 0.098725 0.020522  122 -0.0019 -0.01998  123 -0.12446 
-0.02312
124 0.019234 0.031391  125 0.385366 0.391766  126 0.495518 0.468946  
127

-0.09251 -0.08045  128 0.147965 0.139117  129 -0.03143 -0.02319  130
-0.19801 -0.14924  131 0.014104 -0.01917  132 0.031872 -0.01381  133
-0.01412 -0.04381  134 -0.12864 -0.08527  135 -0.07179 -0.03525  136 
0.31003
0.29553  137 -0.09347 -0.11903  138 -0.10706 -0.16654  139 0.078655 
0.065509
140 0.08279 -0.00766  141 0.181885 0.001414  142 0.345818 0.496323  
143

0.235044 0.095073  144 -0.03022 0.039918  145 0.042577 0.136586  146
0.064208 0.001379  147 -0.02237 -0.03009  148 -3.55E-05 0.040197  149
0.011168 0.087116  150 0.019964 0.071822  151 -0.04602 -0.06616  152
0.083087 0.038592  153 0.032078 0.107237  154 -0.21108 -0.22347  155
0.122959 0.297917  156 -0.05898 0.012547  157 -0.07584 -0.21588  158
-0.00929 -0.06864  159 -0.01211 -0.04559  160 0.090948 0.136582  161
0.016974 0.018259  162 -0.04083 0.016245  163 -0.20328 -0.31678






On Sat, Nov 24, 2012 at 8:22 PM, Bert Gunter gunter.ber...@gene.com 
wrote:



1. The model is correct :  lm( y~ x + offset(x))
( AFAICS)

2. Read the posting guide, please: Code? I do not know what you mean 
by:


 this resulted in a regression line that was plotted perpendicular 
to

the data when added with the abline function.

Of course, maybe someone else will groc this.

3. I wonder if you really want to do what you are doing, anyway. For
example, in comparing two assays to see whether they give similar
results, you would **not** do what you are doing. If you care to 
follow up
on this, I suggest you post complete context to a statistical 
mailing list,
not here, like stats.stackexchange .com.  Also, feel free to ignore 
me, of

course. I'm just guessing.

Cheers,
Bert

Cheers,
Bert


On Sat, Nov 24, 2012 at 4:27 PM, Catriona Hendry 
hen...@gwmail.gwu.eduwrote:



Hi!

I have a question that is probably very basic, but I cannot figure 
out how
to do it. I simply need to compare the significance of a regression 
slope

against a slope of 1, instead of the default of zero.

I know this topic has been posted before, and I have tried to use 
the
advice given to others to fix my problem. I tried the offset 
command based

on one of these advice threads as follows:

Regression - lm(y~x+offset(1*x))

but this resulted in a regression line that was plotted 
perpendicular to

the data when added with the abline function.

I would be extremely grateful for your help!!

Thanks!!

Cat

[[alternative HTML version deleted]]


Re: [R] Help!!!!!

2012-11-24 Thread anoumou
Hello,
Thank you very much for your help.
I appreciate.
:-)
I want the count of INCUBATION and CONTAGIEUX  to be  by country.
the count for example of mexique must not be the same as for USA.
Have  u an idea?
Thanks you in advance.
anoumou



--
View this message in context: 
http://r.789695.n4.nabble.com/Help-tp4650647p4650705.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] How to map new data to the existing cluster assignments in R mclust?

2012-11-24 Thread Zoe
I need to map new data to the existing cluster assignments in R. For
clustering was used mclust. I need to find which cluster the new data belong
to.

Asking for a help :)



--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-map-new-data-to-the-existing-cluster-assignments-in-R-mclust-tp4650702.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.


Re: [R] Comparing linear regression coefficients to a slope of 1

2012-11-24 Thread Catriona Hendry
Hi Albyn,

Not a problem :)

I had calculated the CI using

confint(Regression_PhyloContrasts, level=0.95)

Is that adequate? I had been using this as my indicator of significance,
but ultimately I need a P-value for the deviation from a slope of 1. Which
is where I ran into trouble trying to use offset( ) to change the default
assumption of the linear model.

Cat




On Sat, Nov 24, 2012 at 11:52 PM, Albyn Jones jo...@reed.edu wrote:

 Dear Cat

 My apologies for presuming...

 Here's a primitive solution:  compute a t-statistic or CI.

 t = (beta-hat - 1)/SE(beta-hat), compare to qt(.975, res.df)

 Or Better, compute the 95% confidence interval

   beta-hat + c(-1,1)*qt(.975, res.df)*SE(beta-hat)

 albyn


 On 2012-11-24 18:05, Catriona Hendry wrote:

 Hi,

 @ Albyn, David.. No, its not homework. Its basic groundwork for testing
 allometric relationships for a graduate project I am working on. I read
 the
 guide before posting, I spent half the day trying to understand how I am
 going wrong based on the advice given to others.

 @Bert, David... I apologise for the lack of code, I wasn't sure how to
 explain my problem and I guess I went about it the wrong way.

 I do think this is what I need to be doing, I am testing allometric
 relationships of body size against a predicted isometric (1:1)
 relationship. So I would like to know if the relationship between my
 variables deviates from that.

 Hopefully the information below will be what is needed.

 Here is the part of the code relevant to the regression and plot:


  plot(Contrast_log_MTL_ALL, Contrast_log_FTL_ALL)


  Regression_PhyloContrasts_ALL - lm(Contrast_log_FTL_ALL ~

 Contrast_log_MTL_ALL, offset=1*Contrast_log_MTL_ALL)
 abline(Regression_**PhyloContrasts_ALL)

 the plot that resulted is attached as an image file.


 Below are the vectors of my variables. The are converted from other values
 imported and indexed from a csv file, so unfortunately I don't have matrix
 set up for them.

   Contrast_log_FTL_ALL Contrast_Log_MTL_ALL  83 0.226593 0.284521  84
 0.165517 0.084462  85 -0.1902 -0.0055  86 0.585176 0.639916  87 -0.01078
 0.118011  88 0.161142 0.073762  89 -0.08566 -0.04788  90 -0.13818 -0.0524
 91 -0.02504 -0.21099  92 -0.05027 -0.07594  93 -0.11399 -0.07251  94
 -0.07299 -0.08247  95 -0.09507 -0.04817  96 0.207591 0.151695  97 -0.14224
 -0.05097  98 0.06375 -0.0229  99 0.04607 0.06246  100 0.257389 0.190531
  101
 -0.0612 -0.10902  102 -0.1981 -0.24698  103 -0.12328 -0.36942  104
 0.269877
 0.341989  105 0.125377 0.227183  106 0.087038 -0.05962  107 0.114929
 0.096112  108 0.252807 0.305583  109 -0.0895 -0.08586  110 -0.38483
 -0.20671
 111 -0.72506 -0.63785  112 -0.37212 -0.21458  113 0.010348 0.117577  114
 -0.09625 -0.0059  115 -0.26291 -0.25986  116 0.056922 0.064041  117
 0.051472
 -0.09747  118 -0.05691 0.075005  119 0.117095 -0.15497  120 -0.01329
 -0.12473  121 0.098725 0.020522  122 -0.0019 -0.01998  123 -0.12446
 -0.02312
 124 0.019234 0.031391  125 0.385366 0.391766  126 0.495518 0.468946  127
 -0.09251 -0.08045  128 0.147965 0.139117  129 -0.03143 -0.02319  130
 -0.19801 -0.14924  131 0.014104 -0.01917  132 0.031872 -0.01381  133
 -0.01412 -0.04381  134 -0.12864 -0.08527  135 -0.07179 -0.03525  136
 0.31003
 0.29553  137 -0.09347 -0.11903  138 -0.10706 -0.16654  139 0.078655
 0.065509
 140 0.08279 -0.00766  141 0.181885 0.001414  142 0.345818 0.496323  143
 0.235044 0.095073  144 -0.03022 0.039918  145 0.042577 0.136586  146
 0.064208 0.001379  147 -0.02237 -0.03009  148 -3.55E-05 0.040197  149
 0.011168 0.087116  150 0.019964 0.071822  151 -0.04602 -0.06616  152
 0.083087 0.038592  153 0.032078 0.107237  154 -0.21108 -0.22347  155
 0.122959 0.297917  156 -0.05898 0.012547  157 -0.07584 -0.21588  158
 -0.00929 -0.06864  159 -0.01211 -0.04559  160 0.090948 0.136582  161
 0.016974 0.018259  162 -0.04083 0.016245  163 -0.20328 -0.31678






 On Sat, Nov 24, 2012 at 8:22 PM, Bert Gunter gunter.ber...@gene.com
 wrote:

  1. The model is correct :  lm( y~ x + offset(x))
 ( AFAICS)

 2. Read the posting guide, please: Code? I do not know what you mean by:

  this resulted in a regression line that was plotted perpendicular to
 the data when added with the abline function.

 Of course, maybe someone else will groc this.

 3. I wonder if you really want to do what you are doing, anyway. For
 example, in comparing two assays to see whether they give similar
 results, you would **not** do what you are doing. If you care to follow
 up
 on this, I suggest you post complete context to a statistical mailing
 list,
 not here, like stats.stackexchange .com.  Also, feel free to ignore me,
 of
 course. I'm just guessing.

 Cheers,
 Bert

 Cheers,
 Bert


 On Sat, Nov 24, 2012 at 4:27 PM, Catriona Hendry hen...@gwmail.gwu.edu
 wrote:

  Hi!

 I have a question that is probably very basic, but I cannot figure out
 how
 to do it. I simply need to compare the significance of a regression
 slope
 against a slope of 1, instead of the default of 

Re: [R] Comparing linear regression coefficients to a slope of 1

2012-11-24 Thread David Winsemius
BTW that plot is ridiculous. You should be plotting using the  
coefficients from the non-offset model, since that is the real data  
model.



On Nov 24, 2012, at 6:05 PM, Catriona Hendry wrote:


Hi,

@ Albyn, David.. No, its not homework. Its basic groundwork for  
testing
allometric relationships for a graduate project I am working on. I  
read the
guide before posting, I spent half the day trying to understand how  
I am

going wrong based on the advice given to others.

@Bert, David... I apologise for the lack of code, I wasn't sure how to
explain my problem and I guess I went about it the wrong way.

I do think this is what I need to be doing, I am testing allometric
relationships of body size against a predicted isometric (1:1)
relationship. So I would like to know if the relationship between my
variables deviates from that.

Hopefully the information below will be what is needed.

Here is the part of the code relevant to the regression and plot:



plot(Contrast_log_MTL_ALL, Contrast_log_FTL_ALL)



Regression_PhyloContrasts_ALL - lm(Contrast_log_FTL_ALL ~

Contrast_log_MTL_ALL, offset=1*Contrast_log_MTL_ALL)
abline(Regression_PhyloContrasts_ALL)

the plot that resulted is attached as an image file.


Below are the vectors of my variables. The are converted from other  
values
imported and indexed from a csv file, so unfortunately I don't have  
matrix

set up for them.

 Contrast_log_FTL_ALL Contrast_Log_MTL_ALL  83 0.226593 0.284521  84
0.165517 0.084462  85 -0.1902 -0.0055  86 0.585176 0.639916  87  
-0.01078
0.118011  88 0.161142 0.073762  89 -0.08566 -0.04788  90 -0.13818  
-0.0524

91 -0.02504 -0.21099  92 -0.05027 -0.07594  93 -0.11399 -0.07251  94
-0.07299 -0.08247  95 -0.09507 -0.04817  96 0.207591 0.151695  97  
-0.14224
-0.05097  98 0.06375 -0.0229  99 0.04607 0.06246  100 0.257389  
0.190531  101
-0.0612 -0.10902  102 -0.1981 -0.24698  103 -0.12328 -0.36942  104  
0.269877

0.341989  105 0.125377 0.227183  106 0.087038 -0.05962  107 0.114929
0.096112  108 0.252807 0.305583  109 -0.0895 -0.08586  110 -0.38483  
-0.20671
111 -0.72506 -0.63785  112 -0.37212 -0.21458  113 0.010348 0.117577   
114
-0.09625 -0.0059  115 -0.26291 -0.25986  116 0.056922 0.064041  117  
0.051472

-0.09747  118 -0.05691 0.075005  119 0.117095 -0.15497  120 -0.01329
-0.12473  121 0.098725 0.020522  122 -0.0019 -0.01998  123 -0.12446  
-0.02312
124 0.019234 0.031391  125 0.385366 0.391766  126 0.495518 0.468946   
127

-0.09251 -0.08045  128 0.147965 0.139117  129 -0.03143 -0.02319  130
-0.19801 -0.14924  131 0.014104 -0.01917  132 0.031872 -0.01381  133
-0.01412 -0.04381  134 -0.12864 -0.08527  135 -0.07179 -0.03525  136  
0.31003
0.29553  137 -0.09347 -0.11903  138 -0.10706 -0.16654  139 0.078655  
0.065509
140 0.08279 -0.00766  141 0.181885 0.001414  142 0.345818 0.496323   
143

0.235044 0.095073  144 -0.03022 0.039918  145 0.042577 0.136586  146
0.064208 0.001379  147 -0.02237 -0.03009  148 -3.55E-05 0.040197  149
0.011168 0.087116  150 0.019964 0.071822  151 -0.04602 -0.06616  152
0.083087 0.038592  153 0.032078 0.107237  154 -0.21108 -0.22347  155
0.122959 0.297917  156 -0.05898 0.012547  157 -0.07584 -0.21588  158
-0.00929 -0.06864  159 -0.01211 -0.04559  160 0.090948 0.136582  161
0.016974 0.018259  162 -0.04083 0.016245  163 -0.20328 -0.31678






On Sat, Nov 24, 2012 at 8:22 PM, Bert Gunter  
gunter.ber...@gene.com wrote:



1. The model is correct :  lm( y~ x + offset(x))
( AFAICS)

2. Read the posting guide, please: Code? I do not know what you  
mean by:


 this resulted in a regression line that was plotted perpendicular  
to

the data when added with the abline function.

Of course, maybe someone else will groc this.

3. I wonder if you really want to do what you are doing, anyway. For
example, in comparing two assays to see whether they give similar
results, you would **not** do what you are doing. If you care to  
follow up
on this, I suggest you post complete context to a statistical  
mailing list,
not here, like stats.stackexchange .com.  Also, feel free to ignore  
me, of

course. I'm just guessing.

Cheers,
Bert

Cheers,
Bert


On Sat, Nov 24, 2012 at 4:27 PM, Catriona Hendry hen...@gwmail.gwu.edu 
wrote:



Hi!

I have a question that is probably very basic, but I cannot figure  
out how
to do it. I simply need to compare the significance of a  
regression slope

against a slope of 1, instead of the default of zero.

I know this topic has been posted before, and I have tried to use  
the
advice given to others to fix my problem. I tried the offset  
command based

on one of these advice threads as follows:

Regression - lm(y~x+offset(1*x))

but this resulted in a regression line that was plotted  
perpendicular to

the data when added with the abline function.

I would be extremely grateful for your help!!

Thanks!!

Cat

   [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list

Re: [R] Comparing linear regression coefficients to a slope of 1

2012-11-24 Thread Bert Gunter
Catriona:

You have already been roundly (and appropriately) chastised for your sins.
So I need not join the chorus.

Instead, let me just  briefly focus on the substance of what you are trying
to do, because I continue to believe it's wrong. Here's the leading
question:

Could you just as logically reversed your x and y allometric variables and
done things as:

lm(Contrast_log_MTL_ALL ~ Contrast_log_FTL_ALL) ## ignoring the offset
business

and expected the slope to be 1 for this, too. If the answer to this
question is yes, then your whole approach is wrong and you need to consult
a local statistician or post on a statistical list, as I suggested earlier.
If the answer is no, it can only be done the way you showed us, then you're
fine.

Cheers,
Bert


On Sat, Nov 24, 2012 at 6:05 PM, Catriona Hendry hen...@gwmail.gwu.eduwrote:

 Hi,

 @ Albyn, David.. No, its not homework. Its basic groundwork for testing
 allometric relationships for a graduate project I am working on. I read the
 guide before posting, I spent half the day trying to understand how I am
 going wrong based on the advice given to others.

 @Bert, David... I apologise for the lack of code, I wasn't sure how to
 explain my problem and I guess I went about it the wrong way.

 I do think this is what I need to be doing, I am testing allometric
 relationships of body size against a predicted isometric (1:1)
 relationship. So I would like to know if the relationship between my
 variables deviates from that.

 Hopefully the information below will be what is needed.

 Here is the part of the code relevant to the regression and plot:


 plot(Contrast_log_MTL_ALL, Contrast_log_FTL_ALL)

 Regression_PhyloContrasts_ALL - lm(Contrast_log_FTL_ALL ~
 Contrast_log_MTL_ALL, offset=1*Contrast_log_MTL_ALL)
 abline(Regression_PhyloContrasts_ALL)

 the plot that resulted is attached as an image file.


 Below are the vectors of my variables. The are converted from other values
 imported and indexed from a csv file, so unfortunately I don't have matrix
 set up for them.

   Contrast_log_FTL_ALL Contrast_Log_MTL_ALL  83 0.226593 0.284521  84
 0.165517 0.084462  85 -0.1902 -0.0055  86 0.585176 0.639916  87 -0.01078
 0.118011  88 0.161142 0.073762  89 -0.08566 -0.04788  90 -0.13818 -0.0524
 91 -0.02504 -0.21099  92 -0.05027 -0.07594  93 -0.11399 -0.07251  94
 -0.07299 -0.08247  95 -0.09507 -0.04817  96 0.207591 0.151695  97 -0.14224
 -0.05097  98 0.06375 -0.0229  99 0.04607 0.06246  100 0.257389 0.190531
 101 -0.0612 -0.10902  102 -0.1981 -0.24698  103 -0.12328 -0.36942  104
 0.269877 0.341989  105 0.125377 0.227183  106 0.087038 -0.05962  107
 0.114929 0.096112  108 0.252807 0.305583  109 -0.0895 -0.08586  110
 -0.38483 -0.20671  111 -0.72506 -0.63785  112 -0.37212 -0.21458  113
 0.010348 0.117577  114 -0.09625 -0.0059  115 -0.26291 -0.25986  116
 0.056922 0.064041  117 0.051472 -0.09747  118 -0.05691 0.075005  119
 0.117095 -0.15497  120 -0.01329 -0.12473  121 0.098725 0.020522  122
 -0.0019 -0.01998  123 -0.12446 -0.02312  124 0.019234 0.031391  125
 0.385366 0.391766  126 0.495518 0.468946  127 -0.09251 -0.08045  128
 0.147965 0.139117  129 -0.03143 -0.02319  130 -0.19801 -0.14924  131
 0.014104 -0.01917  132 0.031872 -0.01381  133 -0.01412 -0.04381  134
 -0.12864 -0.08527  135 -0.07179 -0.03525  136 0.31003 0.29553  137
 -0.09347 -0.11903  138 -0.10706 -0.16654  139 0.078655 0.065509  140
 0.08279 -0.00766  141 0.181885 0.001414  142 0.345818 0.496323  143
 0.235044 0.095073  144 -0.03022 0.039918  145 0.042577 0.136586  146
 0.064208 0.001379  147 -0.02237 -0.03009  148 -3.55E-05 0.040197  149
 0.011168 0.087116  150 0.019964 0.071822  151 -0.04602 -0.06616  152
 0.083087 0.038592  153 0.032078 0.107237  154 -0.21108 -0.22347  155
 0.122959 0.297917  156 -0.05898 0.012547  157 -0.07584 -0.21588  158
 -0.00929 -0.06864  159 -0.01211 -0.04559  160 0.090948 0.136582  161
 0.016974 0.018259  162 -0.04083 0.016245  163 -0.20328 -0.31678






 On Sat, Nov 24, 2012 at 8:22 PM, Bert Gunter gunter.ber...@gene.comwrote:

 1. The model is correct :  lm( y~ x + offset(x))
 ( AFAICS)

 2. Read the posting guide, please: Code? I do not know what you mean by:

  this resulted in a regression line that was plotted perpendicular to
 the data when added with the abline function.

 Of course, maybe someone else will groc this.

 3. I wonder if you really want to do what you are doing, anyway. For
 example, in comparing two assays to see whether they give similar
 results, you would **not** do what you are doing. If you care to follow up
 on this, I suggest you post complete context to a statistical mailing list,
 not here, like stats.stackexchange .com.  Also, feel free to ignore me, of
 course. I'm just guessing.

 Cheers,
 Bert

 Cheers,
 Bert


 On Sat, Nov 24, 2012 at 4:27 PM, Catriona Hendry 
 hen...@gwmail.gwu.eduwrote:

 Hi!

 I have a question that is probably very basic, but I cannot figure out
 how
 to do it. I simply need to compare the significance of a regression 

[R] Multiple Range Means Test

2012-11-24 Thread Amanda Jones
Hello,

My boss wants me to do a Duncan's test, which is under the agricolae
package. Unfortunately I am not versed enough in R to run my data. I
have 7 subspecies of deer mouse for which I have 23 measurements which
are my variables of interest. I have run an ANOVA for each of the set
of subspecies and variables, my data look like this:

subspecies  WMF
1  rowleyi 2.50
2  rowleyi 2.30
3  rowleyi 2.35
49  beatae 2.20
50  beatae 2.35
51  beatae 2.45
91 levipes 2.45
92 levipes 2.35
93 levipes 2.50
122 carletoniA 2.20
123 carletoniA 2.10
124 carletoniA 2.30
135 carletoniB 2.60
136 carletoniB 2.40
137 carletoniB 2.60
145  schmidlyi 2.50
146  schmidlyi 2.70
147  schmidlyi 2.70
161simulus 2.40
162simulus 2.20
163simulus 2.30

This is condensed. My data is called dat. The help for duncan.test
shows the argument like this:   duncan.test(y, trt, DFerror, MSerror,
alpha = 0.05, group=TRUE, main = NULL)

When I try to run it as duncan.test(aov, dat, 6, .297, alpha=.05,
group=TRUE, main=NULL) it gives me an error message that I have
differing rows, 0 and 163. 163 is the correct number, where is it
getting the 0 from?

Thank you,
Amanda Jones

__
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] Error : Error in if (antipodal(p1, p2))

2012-11-24 Thread shabsae
Hey,

I'm trying to build something like this
http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/
but with my own data in csv files.
The code runs well if I use the same csv files as the author, but with mine
, this is what I get

*Code*

 library(maps)
library(geosphere)


map(world)

xlim - c(-180.00, 180.00)

ylim - c(-90.00, 90.00) 

map(world, col = #f2f2f2, fill = TRUE, bg = white, lwd = 0.05,xlim =
xlim, ylim = ylim)

airports - read.csv(/Users/shabnam/Desktop/airports.csv, as.is=TRUE,
header=TRUE)
flights - read.csv(/Users/shabnam/Desktop/flights.csv, as.is=TRUE,
header=TRUE)

 pal - colorRampPalette(c(#545454, white))colors - pal(100)
map(world, col=#303030, fill=TRUE, bg=black, lwd=0.05, xlim=xlim,
ylim=ylim)


fsub - flights[flights$airline == AA,]


fsub - fsub[order(fsub$cnt),]

maxcnt - max(fsub$cnt)

for (j in 1:length(fsub$airline)) 
{
air1 - airports[airports$iata == fsub[j,]$airport1,]

air2 - airports[airports$iata == fsub[j,]$airport2,]

inter - gcIntermediate(c(air1[1,]$long, air1[1,]$lat), c(air2[1,]$long,
air2[1,]$lat), n=100, addStartEnd=TRUE)

colindex - round( (fsub[j,]$cnt / maxcnt) * length(colors) )

lines(inter, col=colors[colindex], lwd=0.8)
}






--
View this message in context: 
http://r.789695.n4.nabble.com/Error-Error-in-if-antipodal-p1-p2-tp4650712.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.