Re: [R] R-help, please

2015-09-21 Thread MCGUIRE, Rhydwyn
Hi Kim, this sounds like a homework question which is not meant for this list, 
I don't believe you need a package for this, but you may find the ifelse 
function along with the sum()function useful. You can get more information by 
typing ?ifelse and ?sum into R.

Regards,
Rhydwyn


Rhydwyn McGuire
Senior Biostatistician | Health Statistics NSW
Level 7, 73 Miller St, North Sydney 2060
Tel 02 9391 9781 | rm...@doh.health.nsw.gov.au
www.health.nsw.gov.au




-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of 
le4...@mweb.co.za
Sent: Tuesday, 22 September 2015 12:15 AM
To: r-help@R-project.org
Subject: Re: [R] R-help, please

Good day,
My name is Kim Nguyen and please I need your help with: How to calculate the 
PASS rate of the data in the table below, with PASS in a single subject if 
value>=50 and PASS will be given if PASS 3 out of 4 subjectsWhich package will 
I need to use in this analysis




ID

Literacy

Maths

Physics

Chemistry


A

65

70

79

80


B

65

45

38

50


C

50

62

48

49


D

70

85

82

84


E

45

69

65

62

I appreciate your consultant very much
With kind regardsKim Nguyen
Sent from MWEB Message Centre - CONNECT AND YOU CAN

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
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.
__
This email has been scanned for the NSW Ministry of Health by the Websense 
Hosted Email Security System.
Emails and attachments are monitored to ensure compliance with the NSW Ministry 
of health's Electronic Messaging Policy.
__
___
Disclaimer: This message is intended for the addressee named and may contain 
confidential information.
If you are not the intended recipient, please delete it and notify the sender.
Views expressed in this message are those of the individual sender, and are not 
necessarily the views of the NSW Ministry of Health.
___
This email has been scanned for the NSW Ministry of Health by the Websense 
Hosted Email Security System.
Emails and attachments are monitored to ensure compliance with the NSW Ministry 
of Health's Electronic Messaging Policy.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Running GCV Optimization under Ridge Regression

2015-09-21 Thread Preetam Pal
Hi John/R-users,

   - I have attached the data set in the mail in .txt format, can be read
   using read.table(). Kindly let me know please if this is not sufficient.
   - Also, to specify the modeling scheme I am stuck at:


   1. Have numerical regressors GDP, HPA and FX to predict the variable Y
   -- all these are quarterly time series.
   2. Am looking to implement *Weighted Ridge regression* where the
   observation weights (in SSE computation) are decreasing into the past at 5%
   rate each quarter
   3. Need to optimize wrt GCV criterion (leave K out scheme, K = 10% of
   data size) to get the best lambda (Ridge parameter)
   4. Then, for this optimum lambda, compute beta over the whole data as
   [X'W'WX + Lambda * I]^-1 * X'W'WY (W'W is a diagonal matrix with entries
   decreasing at 5% from the last entry to the first, and preferably summing
   upto 1 ]

Please let me know if anything is unclear, would be happy to elaborate. The
problem is I am very new to coding and although I know of some functions
that may be relevant (like lm.ridge), I am not being able to implement the
entire code myself.Appreciate your help.

Regards,
Preetam


On Tue, Sep 22, 2015 at 6:09 AM, John Kane  wrote:

>
> No data.
>
> Please have a look at
> http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
> and http://adv-r.had.co.nz/Reproducibility.html
> John Kane
> Kingston ON Canada
>
>
> > -Original Message-
> > From: lordpree...@gmail.com
> > Sent: Tue, 22 Sep 2015 01:19:38 +0530
> > To: r-help@r-project.org
> > Subject: [R] Running GCV Optimization under Ridge Regression
> >
> > Hi guys,
> >
> > I am running Ridge regression on a dataset (predicted variable = y; GDP,
> > HPA and FX are regressors). I found that lm.ridge() can perform the ridge
> > regression given any value of lambda (i.e. the ridge parameter). However,
> > in order to choose the best results, I need to select the model output
> > corresponding to that lambda which optimizes some logically defined GCV
> > criteria. I thought there would be some in-built funcion in R Studio for
> > this, but could not find one. Also, I am not being able to write the
> > required code for this. Any help here will be appreciated. I have
> > attached
> > the data in case it is required.
> >
> > Thanks,
> > Preetam
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>
> 
> FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on
> your desktop!
> Check it out at http://www.inbox.com/marineaquarium
>
>
>


-- 
Preetam Pal
(+91)-9432212774
M-Stat 2nd Year, Room No. N-114
Statistics Division,   C.V.Raman
Hall
Indian Statistical Institute, B.H.O.S.
Kolkata.
T   GDP RateHPA FX  Y
1   0.806660537 2.177803167 1.14980573  2.733594304
2   0.997724655 1.585686087 0.814496976 3.193948056
3   0.99032353  0.569843997 0.46442 3.065751781
4   0.606121306 3.037648988 0.565322084 4.537399052
5   0.858131141 4.816423605 1.924534222 7.871730873
6   0.052909178 2.048591352 1.470221953 2.580646078
7   0.081400487 1.152495559 1.128828557 7.200336313
8   0.840972911 3.848225962 1.004272646 1.211124673
9   0.965868218 1.039679934 0.231408747 7.566968
10  0.952626722 4.455565591 0.483541015 9.412639513
11  0.067691757 0.038417569 0.69744243  8.055369029
12  0.985658841 1.143481763 1.65850909  6.962599601
13  0.177186946 3.762691635 0.44379572  9.904367023
14  0.490066697 0.655629739 1.281478696 1.796422139
15  0.223740666 1.393201062 1.235291827 5.237943945
16  0.782873809 1.485727273 0.224511215 6.399036418
17  0.947492758 0.318485005 1.158911495 8.183470692
18  0.49692711  2.169601457 1.777618832 8.830805294
19  0.956704273 1.546827505 0.241838792 7.554654431
20  0.404624372 3.041530693 1.66039172  6.709330773
21  0.98557461  2.45656369  1.695179666 8.638707974
22  0.494102398 4.527230971 0.993352283 7.958872374
23  0.893182943 3.429112971 0.675541115 5.665249801
24  0.669680459 0.459919029 1.011872328 8.883120607
25  0.017296599 2.184045646 1.575891106 2.585709635
__
R-help@r-project.org mailing list -- To 

Re: [R] ERROR - non-conformable arguments

2015-09-21 Thread PIKAL Petr
Hi

Do not use attachment, copy result of dput(object) to your mail instead. This 
enables us to see how your data really look like.

I get different error.
> widesII(used, available, avknown = TRUE, alpha = 0.05)
Error in widesII(used, available, avknown = TRUE, alpha = 0.05) :
  used and available matrices should have the same number of habitats

The error is due to fact that row names were read as column of data frame. 
After correcting this I got the same error as you.

> widesII(used, available, avknown = TRUE, alpha = 0.05)
Error in as.vector(X) %*% t(as.vector(Y)) : non-conformable arguments

I checked the help page and I noticed that

a
for widesI and widesII, a vector with named elements describing the sample or 
the proportion of available resource units. For widesIII a matrix or a data 
frame giving the number or the proportion of available resource units for each 
animal (in rows) in each resource category (in columns)

but your "available" is a data frame.


When I change it to named vector (as required)

> dput(avail)
structure(c(0.06, 0.13, 0.16, 0.15, 0.06, 0.17, 0.12, 0.04, 0.09,
0.02), .Names = c("Riparian", "Conifer", "MtShrub1", "Aspen",
"RockOutcrop", "Bitterbrush", "Windblown", "MtShrub2", "PresBurn",
"Clearcut"))

widesII came with result without complain.

> widesII(used, avail, avknown = TRUE, alpha = 0.05)


** Manly's Selection ratios for design II 

1. Test of identical use of habitat by all animals
   (Classical Khi-2 performed on the used matrix):
  Khi2L1   df   pvalue

So the lesson is:

1. Read the help page.
2. Look to your data by ?str
3. When your data are as expected by the function, check if there is no syntax 
problem.
4. Try to simplify the example and send it to help list preferably by ?dput.

Cheers
Petr

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of
> Alexander Moßbrucker
> Sent: Monday, September 21, 2015 8:58 AM
> To: r-help@r-project.org; jdnew...@dcn.davis.ca.us
> Subject: Re: [R] ERROR - non-conformable arguments
>
> Hi all,
>
> I am sorry I forgot to attach the excel file and txt files with the
> test data I used for this example.
>
> I am almost sure the problem was caused by the way R is reading this
> data,
>
> Hope to get some help, best, Alex
>
> 2015-09-20 14:03 GMT+07:00 Alexander Moßbrucker
> :
>
> >
> > Hi,
> >
> > I am using adehabitatHS for habitat selection analysis using
> > widesII(), when running the script I get the error message: Error in
> > as.vector(X) %*%
> > t(as.vector(Y)) : non-conformable arguments
> >
> > Here the script I am using including the data
> >
> > > #dataset (read from tab deliminated text file)
> > >
> > > available
> >   Riparian Conifer MtShrub1 Aspen RockOutcrop Bitterbrush Windblown
> > MtShrub2
> > PresBurn
> > 1 0.060.13 0.16  0.150.060.17  0.12
> >  0.04
> > 0.09
> >   Clearcut
> > 1 0.02
> > > used
> >  Riparian Conifer MtShrub1 Aspen RockOutcrop Bitterbrush
> Windblown
> > MtShrub2 PresBurn
> > Ani10   00 2   0  16
> 5
> > 14   28
> > Ani20   21 2   2   5
> 10
> > 10   35
> > Ani30   12 1   0  14
> 9
> > 8   40
> > Ani40   13 7   5   3
> 6
> > 9   31
> > Ani50   02 2   5  18
> 10
> > 6   25
> > Ani60   21 4   2   7
> 6
> > 15   19
> >  Clearcut
> > Ani18
> > Ani29
> > Ani34
> > Ani49
> > Ani50
> > Ani6   19
> > >
> > > #analysis
> > >
> > > widesII(used, available, avknown = TRUE, alpha = 0.05)
> > Error in as.vector(X) %*% t(as.vector(Y)) : non-conformable arguments
> >
> > Note: I am using an example dataset to test out a script I want to
> use
> > to analyse my own dataset, for this I exported the example dataset to
> > excel, converted it to tab deliminated text file, then imported it.
> >
> > All worked well when using the example dataset provided by
> > adehabitatHS, thus I suspect that somhow my test dataset is not
> > correctly read in or something similar.
> >
> > I am quite new to R, thus apologize for any shortcomings in reporting
> etc..
> >
> > Many thanks, best, Alex
> >
> >
> >
> > --
> > View this message in context:
> > http://r.789695.n4.nabble.com/ERROR-non-conformable-arguments-
> tp471251
> > 6.html Sent from the R help mailing list archive at Nabble.com.
> >
> >
> >
> >


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni 

Re: [R] How to coerce a parameter in nls?

2015-09-21 Thread ProfJCNash
I posted a suggestion to use nlmrt package (function nlxb to be 
precise), which has masked (fixed) parameters. Examples in my 2014 book 
on Nonlinear parameter optimization with R tools. However, I'm 
travelling just now, or would consider giving this a try.


JN

On 15-09-20 01:19 PM, Jianling Fan wrote:

no, I am doing a regression with 6 group data with 2 shared parameters
and 1 different parameter for each group data. the parameter I want to
coerce is for one group. I don't know how to do it. Any suggestion?

Thanks!

On 19 September 2015 at 13:33, Jeff Newmiller  wrote:

Why not rewrite the function so that value is not a parameter?
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  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.

On September 18, 2015 9:54:54 PM PDT, Jianling Fan  
wrote:

Hello, everyone,

I am using a nls regression with 6 groups data. I am trying to coerce
a parameter to 1 by using a upper and lower statement. but I always
get an error like below:

Error in ifelse(internalPars < upper, 1, -1) :
  (list) object cannot be coerced to type 'double'

does anyone know how to fix it?

thanks in advance!

My code is below:




dproot

   depth   den ref
1 20 0.573   1
2 40 0.780   1
3 60 0.947   1
4 80 0.990   1
5100 1.000   1
6 10 0.600   2
7 20 0.820   2
8 30 0.930   2
9 40 1.000   2
1020 0.480   3
1140 0.734   3
1260 0.961   3
1380 0.998   3
14   100 1.000   3
1520 3.2083491   4
1640 4.9683383   4
1760 6.2381133   4
1880 6.5322348   4
19   100 6.5780660   4
20   120 6.6032064   4
2120 0.614   5
2240 0.827   5
2360 0.950   5
2480 0.995   5
25   100 1.000   5
2620 0.4345774   6
2740 0.6654726   6
2860 0.8480684   6
2980 0.9268951   6
30   100 0.9723207   6
31   120 0.9939966   6
32   140 0.9992400   6


fitdp<-nls(den~Rm[ref]/(1+(depth/d50)^c),data=dproot,

+ start = list(Rm=c(1.01, 1.01, 1.01, 6.65,1.01,1), d50=20, c=-1))

summary(fitdp)


Formula: den ~ Rm[ref]/(1 + (depth/d50)^c)

Parameters:
Estimate Std. Error t value Pr(>|t|)
Rm1  1.125600.07156   15.73 3.84e-14 ***
Rm2  1.576430.11722   13.45 1.14e-12 ***
Rm3  1.106970.07130   15.53 5.11e-14 ***
Rm4  7.239250.20788   34.83  < 2e-16 ***
Rm5  1.145160.07184   15.94 2.87e-14 ***
Rm6  1.036580.05664   18.30 1.33e-15 ***
d50 22.694261.03855   21.85  < 2e-16 ***
c   -1.597960.15589  -10.25 3.02e-10 ***
---
Signif. codes:  0 ?**?0.001 ?*?0.01 ??0.05 ??0.1 ??1

Residual standard error: 0.1094 on 24 degrees of freedom

Number of iterations to convergence: 8
Achieved convergence tolerance: 9.374e-06


fitdp1<-nls(den~Rm[ref]/(1+(depth/d50)^c),data=dproot,

algorithm="port",
+ start = list(Rm=c(1.01, 1.01, 1.01, 6.65, 1.01, 1), d50=20, c=-1),
+ lower = list(Rm=c(1.01, 1.01, 1.01, 6.65, 1.01, 1), d50=20, c=-1),
+ upper = list(Rm=c(2.1, 2.2, 2.12, 12.5, 2.3, 1), d50=50, c=1))

Error in ifelse(internalPars < upper, 1, -1) :
  (list) object cannot be coerced to type 'double'

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 -- To UNSUBSCRIBE and more, see
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-es] Resumen de R-help-es, Vol 79, Envío 16

2015-09-21 Thread morales
 

Hola,si añades 

header-includes:
- usepackage[utf8]{inputenc} 

debajo del output en la cabecera(yaml) no debes tener problemas con las
tildes. También debes usar codificación utf8 dentro de RStudio. 

Saludos, 

El 21/09/2015 12:00, r-help-es-requ...@r-project.org escribió: 

> Envíe los mensajes para la lista R-help-es a
> r-help-es@r-project.org
> 
> Para subscribirse o anular su subscripción a través de la WEB
> https://stat.ethz.ch/mailman/listinfo/r-help-es [2]
> 
> O por correo electrónico, enviando un mensaje con el texto "help" en
> el asunto (subject) o en el cuerpo a:
> r-help-es-requ...@r-project.org
> 
> Puede contactar con el responsable de la lista escribiendo a:
> r-help-es-ow...@r-project.org
> 
> Si responde a algún contenido de este mensaje, por favor, edite la
> linea del asunto (subject) para que el texto sea mas especifico que:
> "Re: Contents of R-help-es digest...". Además, por favor, incluya en
> la respuesta sólo aquellas partes del mensaje a las que está
> respondiendo.
> 
> Asuntos del día:
> 
> 1. Re: Problemas con rmarkdown (Carlos J. Gil Bellosta )
> 2. Re: Problemas con rmarkdown (Conney Marulanda)
> 3. Re: Problemas con rmarkdown (Carlos J. Gil Bellosta )
> 4. Re: Problemas con rmarkdown (Conney Marulanda)
> 
> --
> 
> Message: 1
> Date: Sun, 20 Sep 2015 17:23:10 +0200
> From: "Carlos J. Gil Bellosta " 
> To: Conney Marulanda 
> Cc: "r-help-es@r-project.org" 
> Subject: Re: [R-es] Problemas con rmarkdown
> Message-ID:
> 
> Content-Type: text/plain; charset="UTF-8"
> 
> Hola, ¿qué tal?
> 
> Yo creo que el problema no está en R. Aparentemente, ya has generado el
> fichero .md que pandoc "traduce" a pdf.
> 
> ¿Puedes ver el fichero .md correctamente? ¿Lo has generado a partir de un
> Rmd? ¿Puedes generar el pdf directamente desde RStudio a partir del Rmd (si
> es que lo hay)?
> 
> Un saludo,
> 
> Carlos J. Gil Bellosta
> http://www.datanalytics.com [3]
> 
> El 19 de septiembre de 2015, 22:41, Conney Marulanda 
> escribió:
> 
>> Buenas noches, Escribo este mail porque tengo un problema con rmarkdown, 
>> estoy creando un informe y me iba bien al generarlo como pdf, de repente me 
>> sale el siguiente error y no sé como solucionarlo: pandoc.exe: Error 
>> producing PDF from TeX sourceError: pandoc document conversion failed with 
>> error 43Además: Warning message:comando ejecutado '"C:/Program 
>> Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS 
>> Evolución_de_los_Mercados_.utf8.md --to latex --from 
>> markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures
>>  --output Evolución_de_los_Mercados_.pdf --template 
>> "C:UsersCONNYDocumentsRwin-library3.2rmarkdownrmdlatexdefault.tex" 
>> --highlight-style tango --latex-engine pdflatex --variable 
>> "geometry:margin=1in"' tiene estatus 43 Ejecución interrumpida Asimismo, si 
>> lo quiero generar como html sería para publicarlo en mi sitio web, le dí en 
>> la opción publicar y salió que requería instalar ciertos paquetes...pero 
>> luego me salió el siguiente error:
"Error occurred while executing method" Agradezco su colaboración, pues la idea 
de mi informe es publicarlo en mi sitio web ya sea como pdf o directamente en 
formato html. Muchas gracias! Conney Paola Marulanda López Profesional en 
Finanzas y Relaciones Internacionales www.finanzaszone.com [1] [[alternative 
HTML version deleted]] ___ 
R-help-es mailing list R-help-es@r-project.org 
https://stat.ethz.ch/mailman/listinfo/r-help-es [2]
> 
> [[alternative HTML version deleted]]
> 
> --
> 
> Message: 2
> Date: Sun, 20 Sep 2015 21:46:14 +0200
> From: Conney Marulanda 
> To: "Carlos J. Gil Bellosta" ,
> "r-help-es@r-project.org" 
> Subject: Re: [R-es] Problemas con rmarkdown
> Message-ID: 
> Content-Type: text/plain; charset="UTF-8"
> 
> Hola, 
> Muchas gracias por tu ayuda... tengo el fichero Rmd pero no me deja 
> visualizarlo como pdf, cuando lo intento me genera ese error. 
> Gracias.
> Saludos, 
> 
> Conney Paola Marulanda L? 
> Profesional en Finanzas y Relaciones Internacionales
> www.finanzaszone.com [1] 
> 
> Date: Sun, 20 Sep 2015 17:23:10 +0200
> Subject: Re: [R-es] Problemas con rmarkdown
> From: c...@datanalytics.com
> To: cpm...@hotmail.com
> CC: r-help-es@r-project.org
> 
> Hola, ?qu?al?
> Yo creo que el problema no est?n R. Aparentemente, ya has generado el fichero 
> .md que pandoc "traduce" a pdf. 
> ?Puedes ver el fichero .md correctamente? ?Lo has generado a partir de un 
> Rmd? ?Puedes generar el pdf directamente desde RStudio a partir del Rmd (si 
> es que lo hay)?
> Un saludo,
> Carlos J. Gil 

[R] Fwd: gdal_translate and gdalwarp question

2015-09-21 Thread Antonio Silva
Hello,

I have some doubts on the usage of some gdal tools.

After converting a hdf file to tif I want to reproject to SIRGAS2000 and
clip between lats of 22 to 29 S and lats of 40 to 50 W.

HDF file can be downloaded at
https://app.box.com/s/16cf7qv6af6gsz1v66staori2mtneu0r

Basically I'm following
https://scottishsnow.wordpress.com/2014/08/24/many-rastered-beast/

Well to convert HDF file I'm using:

gdal_translate("A20080012008031.L3m_MO_SST_4","georef.tif",sd_index=1,a_ullr=c(0,4320,8640,0),
a_srs="+proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +a=6371007
+b=6371007 +units=m +no_defs")

Without a_ullr and a_srs options I was getting an error message when using
gdalwarp: "ERROR 1: Unable to compute a transformation between pixel/line
and georeferenced coordinates"

a_ullr and a_srs values I got with GDALinfo("georef.tif"). I also tryed
a_ullr=c(-180,90,180,-90).

map <- raster("georef.tif")
plot(map)

My problem now is reproject to SIRGAS2000 and clip the image georef.tif:

gdalwarp("georef.tif", "georef2.tif",
s_srs="+proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +a=6371007
+b=6371007 +units=m +no_defs",
t_srs="+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs")

map2 <- raster("georef2.tif")
plot(map2)

Map2 is not in SIRGAS2000 projection and clipping option
te=c(-50,-29,-40,-22) does not work.

Where is my mistake? I hope someone can tell me.

Thanks for any help.

Antonio Olinto



















-- 
Antônio Olinto Ávila da Silva
Biólogo / Oceanógrafo
Instituto de Pesca (Fisheries Institute)
São Paulo, Brasil



-- 
Antônio Olinto Ávila da Silva
Biólogo / Oceanógrafo
Instituto de Pesca (Fisheries Institute)
São Paulo, Brasil

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Running GCV Optimization under Ridge Regression

2015-09-21 Thread John Kane

No data. 

Please have a look at 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
 and http://adv-r.had.co.nz/Reproducibility.html
John Kane
Kingston ON Canada


> -Original Message-
> From: lordpree...@gmail.com
> Sent: Tue, 22 Sep 2015 01:19:38 +0530
> To: r-help@r-project.org
> Subject: [R] Running GCV Optimization under Ridge Regression
> 
> Hi guys,
> 
> I am running Ridge regression on a dataset (predicted variable = y; GDP,
> HPA and FX are regressors). I found that lm.ridge() can perform the ridge
> regression given any value of lambda (i.e. the ridge parameter). However,
> in order to choose the best results, I need to select the model output
> corresponding to that lambda which optimizes some logically defined GCV
> criteria. I thought there would be some in-built funcion in R Studio for
> this, but could not find one. Also, I am not being able to write the
> required code for this. Any help here will be appreciated. I have
> attached
> the data in case it is required.
> 
> Thanks,
> Preetam
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.


FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your 
desktop!

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] vector manipulations -- differences

2015-09-21 Thread Bert Gunter
Use ?mappy and ?rep.int

> x[unlist(mapply(":",2:4,4))] - x[rep.int(1:3,3:1)]
[1]  3  7 20  4 17 13

Cheers,

Bert


Bert Gunter

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
   -- Clifford Stoll


On Mon, Sep 21, 2015 at 2:17 PM, Dan D  wrote:
> I need an efficient way to build a new n x (n-1)/2 vector from an n-vector x
> as:
>
> c(x[-1]-x[1], x[-(1:2)]-x[2], ... , x[-(1:(n-1)] - x[n-1])
>
> x is increasing with x[1] = 0.
>
> The following works but is not the greatest:
> junk<-outer(x, x, '-')
> junk[junk>0]
>
> e.g.,
> given
> x<-c(0, 3, 7, 20)
> junk<-outer(x, x, '-')
> junk[junk>0] # yields: c(3, 7, 20, 4, 17, 13) as needed, but it has to go
> through
> junk
> # [,1] [,2] [,3] [,4]
> #[1,]0   -3   -7  -20
> #[2,]30   -4  -17
> #[3,]740  -13
> #[4,]   20   17   130
>
> Anyone have a better idea?
>
> -Dan
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/vector-manipulations-differences-tp4712575.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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] R-help, please

2015-09-21 Thread John Kane
It looks like you sent the e-mail in HTML. 

It is unreadable.

You must sent e-mail to R-help in plain text not HTML

John Kane
Kingston ON Canada


> -Original Message-
> From: le4...@mweb.co.za
> Sent: Mon, 21 Sep 2015 16:14:41 +0200
> To: r-help@r-project.org
> Subject: Re: [R] R-help, please
> 
> Good day,
> My name is Kim Nguyen and please I need your help with: How to calculate
> the PASS rate of the data in the table below, with PASS in a single
> subject if value>=50 and PASS will be given if PASS 3 out of 4
> subjectsWhich package will I need to use in this analysis
> 
> 
> 
> 
> ID
> 
> Literacy
> 
> Maths
> 
> Physics
> 
> Chemistry
> 
> 
> A
> 
> 65
> 
> 70
> 
> 79
> 
> 80
> 
> 
> B
> 
> 65
> 
> 45
> 
> 38
> 
> 50
> 
> 
> C
> 
> 50
> 
> 62
> 
> 48
> 
> 49
> 
> 
> D
> 
> 70
> 
> 85
> 
> 82
> 
> 84
> 
> 
> E
> 
> 45
> 
> 69
> 
> 65
> 
> 62
> 
> I appreciate your consultant very much
> With kind regardsKim Nguyen
> Sent from MWEB Message Centre - CONNECT AND YOU CAN
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.


FREE ONLINE PHOTOSHARING - Share your photos online with your friends and 
family!
Visit http://www.inbox.com/photosharing to find out more!

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] R-help, please

2015-09-21 Thread Rolf Turner



Your question looks very much like homework and this list does not do 
homework for people.  Talk to your instructor.


cheers,

Rolf Turner

On 22/09/15 02:14, le4...@mweb.co.za wrote:

Good day,
My name is Kim Nguyen and please I need your help with: How to calculate the PASS 
rate of the data in the table below, with PASS in a single subject if value>=50 
and PASS will be given if PASS 3 out of 4 subjectsWhich package will I need to use 
in this analysis




ID

Literacy

Maths

Physics

Chemistry


A

65

70

79

80


B

65

45

38

50


C

50

62

48

49


D

70

85

82

84


E

45

69

65

62

I appreciate your consultant very much
With kind regardsKim Nguyen


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 coerce a parameter in nls?

2015-09-21 Thread Jianling Fan
Hello, Gabor,

Thanks again for your suggestion. And now I am trying to improve the
code by adding a function to replace the express "Rm1 * ref.1 + Rm2 *
ref.2 + Rm3 * ref.3 + Rm4 * ref.4 + Rm5 * ref.5 + Rm6 * ref.6" because
I have some other dataset need to fitted to the same model but with
more groups (>20).

I tried to add the function as:

denfun<-function(i){
   for(i in 1:6){
 Rm<-sum(Rm[i]*ref.i)
 return(Rm)}
}

but I got another error when I incorporate this function into my regression:

>fitdp1<-nlxb(den ~ denfun(6)/(1+(depth/d50)^c),
   data = dproot2,
 start = c(Rm1=1.01, Rm2=1.01, Rm3=1.01, Rm4=6.65,
Rm5=1.01, Rm6=1, d50=20, c=-1),
masked = "Rm6")

Error in deriv.default(parse(text = resexp), names(start)) :
  Function 'denfun' is not in the derivatives table

I think there must be something wrong with my function. I tried some
times but am not sure how to improve it because I am quite new to R.

Could anyone please give me some suggestion.

Thanks a lot!


Jianling


On 22 September 2015 at 00:43, Gabor Grothendieck
 wrote:
> Express the formula in terms of simple operations like this:
>
> # add 0/1 columns ref.1, ref.2, ..., ref.6
> dproot2 <- do.call(data.frame, transform(dproot, ref = outer(dproot$ref,
> seq(6), "==") + 0))
>
> # now express the formula in terms of the new columns
> library(nlmrt)
> fitdp1<-nlxb(den ~ (Rm1 * ref.1 + Rm2 * ref.2 + Rm3 * ref.3 + Rm4 * ref.4 +
> Rm5 * ref.5 + Rm6 * ref.6)/(1+(depth/d50)^c),
>  data = dproot2,
>  start = c(Rm1=1.01, Rm2=1.01, Rm3=1.01, Rm4=6.65, Rm5=1.01, Rm6=1,
> d50=20, c=-1),
>  masked = "Rm6")
>
> where we used this input:
>
> Lines <- "   depth   den ref
> 1 20 0.573   1
> 2 40 0.780   1
> 3 60 0.947   1
> 4 80 0.990   1
> 5100 1.000   1
> 6 10 0.600   2
> 7 20 0.820   2
> 8 30 0.930   2
> 9 40 1.000   2
> 1020 0.480   3
> 1140 0.734   3
> 1260 0.961   3
> 1380 0.998   3
> 14   100 1.000   3
> 1520 3.2083491   4
> 1640 4.9683383   4
> 1760 6.2381133   4
> 1880 6.5322348   4
> 19   100 6.5780660   4
> 20   120 6.6032064   4
> 2120 0.614   5
> 2240 0.827   5
> 2360 0.950   5
> 2480 0.995   5
> 25   100 1.000   5
> 2620 0.4345774   6
> 2740 0.6654726   6
> 2860 0.8480684   6
> 2980 0.9268951   6
> 30   100 0.9723207   6
> 31   120 0.9939966   6
> 32   140 0.9992400   6"
>
> dproot <- read.table(text = Lines, header = TRUE)
>
>
>
> On Mon, Sep 21, 2015 at 12:22 PM, Jianling Fan 
> wrote:
>>
>> Thanks Prof. Nash,
>>
>> Sorry for late reply. I am learning and trying to use your nlmrt
>> package since I got your email. It works good to mask a parameter in
>> regression but seems does work for my equation. I think the problem is
>> that the parameter I want to mask is a group-specific parameter and I
>> have a "[]" syntax in my equation. However, I don't have your 2014
>> book on hand and couldn't find it in our library. So I am wondering if
>> nlxb works for group data?
>> Thanks a lot!
>>
>> following is my code and I got a error form it.
>>
>> > fitdp1<-nlxb(den~Rm[ref]/(1+(depth/d50)^c),data=dproot,
>> + start =c(Rm1=1.01, Rm2=1.01, Rm3=1.01, Rm4=6.65,
>> Rm5=1.01, Rm6=1, d50=20, c=-1),
>> + masked=c("Rm6"))
>>
>> Error in deriv.default(parse(text = resexp), names(start)) :
>>   Function '`[`' is not in the derivatives table
>>
>>
>> Best regards,
>>
>> Jianling
>>
>>
>> On 20 September 2015 at 12:56, ProfJCNash  wrote:
>> > I posted a suggestion to use nlmrt package (function nlxb to be
>> > precise),
>> > which has masked (fixed) parameters. Examples in my 2014 book on
>> > Nonlinear
>> > parameter optimization with R tools. However, I'm travelling just now,
>> > or
>> > would consider giving this a try.
>> >
>> > JN
>> >
>> >
>> > On 15-09-20 01:19 PM, Jianling Fan wrote:
>> >>
>> >> no, I am doing a regression with 6 group data with 2 shared parameters
>> >> and 1 different parameter for each group data. the parameter I want to
>> >> coerce is for one group. I don't know how to do it. Any suggestion?
>> >>
>> >> Thanks!
>> >>
>> >> On 19 September 2015 at 13:33, Jeff Newmiller
>> >> 
>> >> wrote:
>> >>>
>> >>> Why not rewrite the function so that value is not a parameter?
>> >>>
>> >>>
>> >>> ---
>> >>> Jeff NewmillerThe .   .  Go
>> >>> Live...
>> >>> DCN:Basics: ##.#.   ##.#.  Live
>> >>> Go...
>> >>>Live:   OO#.. Dead: OO#..
>> >>> Playing
>> >>> Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
>> >>> 

Re: [R] extract from data.frame (indexing)

2015-09-21 Thread John Kane
And the action is?

John Kane
Kingston ON Canada


> -Original Message-
> From: nico.gutierr...@gmail.com
> Sent: Mon, 21 Sep 2015 16:48:45 +0200
> To: r-help@r-project.org
> Subject: [R] extract from data.frame (indexing)
> 
> Hi All,
> 
> I need to do the following operation:
> 
> 
>   Year Amount Amount.1
> 1 2001150  150
> 2 2002120  120
> 3 2003175  175
> 4 2004160  160
> 5 2005120  120
> 6 2006105  105
> 7 2007135  135
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.


FREE ONLINE PHOTOSHARING - Share your photos online with your friends and 
family!
Visit http://www.inbox.com/photosharing to find out more!

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 coerce a parameter in nls?

2015-09-21 Thread Jianling Fan
Thanks Prof. Nash,

Sorry for late reply. I am learning and trying to use your nlmrt
package since I got your email. It works good to mask a parameter in
regression but seems does work for my equation. I think the problem is
that the parameter I want to mask is a group-specific parameter and I
have a "[]" syntax in my equation. However, I don't have your 2014
book on hand and couldn't find it in our library. So I am wondering if
nlxb works for group data?
Thanks a lot!

following is my code and I got a error form it.

> fitdp1<-nlxb(den~Rm[ref]/(1+(depth/d50)^c),data=dproot,
+ start =c(Rm1=1.01, Rm2=1.01, Rm3=1.01, Rm4=6.65,
Rm5=1.01, Rm6=1, d50=20, c=-1),
+ masked=c("Rm6"))

Error in deriv.default(parse(text = resexp), names(start)) :
  Function '`[`' is not in the derivatives table


Best regards,

Jianling


On 20 September 2015 at 12:56, ProfJCNash  wrote:
> I posted a suggestion to use nlmrt package (function nlxb to be precise),
> which has masked (fixed) parameters. Examples in my 2014 book on Nonlinear
> parameter optimization with R tools. However, I'm travelling just now, or
> would consider giving this a try.
>
> JN
>
>
> On 15-09-20 01:19 PM, Jianling Fan wrote:
>>
>> no, I am doing a regression with 6 group data with 2 shared parameters
>> and 1 different parameter for each group data. the parameter I want to
>> coerce is for one group. I don't know how to do it. Any suggestion?
>>
>> Thanks!
>>
>> On 19 September 2015 at 13:33, Jeff Newmiller 
>> wrote:
>>>
>>> Why not rewrite the function so that value is not a parameter?
>>>
>>> ---
>>> Jeff NewmillerThe .   .  Go
>>> Live...
>>> DCN:Basics: ##.#.   ##.#.  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.
>>>
>>> On September 18, 2015 9:54:54 PM PDT, Jianling Fan
>>>  wrote:

 Hello, everyone,

 I am using a nls regression with 6 groups data. I am trying to coerce
 a parameter to 1 by using a upper and lower statement. but I always
 get an error like below:

 Error in ifelse(internalPars < upper, 1, -1) :
   (list) object cannot be coerced to type 'double'

 does anyone know how to fix it?

 thanks in advance!

 My code is below:



> dproot

depth   den ref
 1 20 0.573   1
 2 40 0.780   1
 3 60 0.947   1
 4 80 0.990   1
 5100 1.000   1
 6 10 0.600   2
 7 20 0.820   2
 8 30 0.930   2
 9 40 1.000   2
 1020 0.480   3
 1140 0.734   3
 1260 0.961   3
 1380 0.998   3
 14   100 1.000   3
 1520 3.2083491   4
 1640 4.9683383   4
 1760 6.2381133   4
 1880 6.5322348   4
 19   100 6.5780660   4
 20   120 6.6032064   4
 2120 0.614   5
 2240 0.827   5
 2360 0.950   5
 2480 0.995   5
 25   100 1.000   5
 2620 0.4345774   6
 2740 0.6654726   6
 2860 0.8480684   6
 2980 0.9268951   6
 30   100 0.9723207   6
 31   120 0.9939966   6
 32   140 0.9992400   6

> fitdp<-nls(den~Rm[ref]/(1+(depth/d50)^c),data=dproot,

 + start = list(Rm=c(1.01, 1.01, 1.01, 6.65,1.01,1), d50=20, c=-1))
>
> summary(fitdp)


 Formula: den ~ Rm[ref]/(1 + (depth/d50)^c)

 Parameters:
 Estimate Std. Error t value Pr(>|t|)
 Rm1  1.125600.07156   15.73 3.84e-14 ***
 Rm2  1.576430.11722   13.45 1.14e-12 ***
 Rm3  1.106970.07130   15.53 5.11e-14 ***
 Rm4  7.239250.20788   34.83  < 2e-16 ***
 Rm5  1.145160.07184   15.94 2.87e-14 ***
 Rm6  1.036580.05664   18.30 1.33e-15 ***
 d50 22.694261.03855   21.85  < 2e-16 ***
 c   -1.597960.15589  -10.25 3.02e-10 ***
 ---
 Signif. codes:  0 ?**?0.001 ?*?0.01 ??0.05 ??0.1 ??1

 Residual standard error: 0.1094 on 24 degrees of freedom

 Number of iterations to convergence: 8
 Achieved convergence tolerance: 9.374e-06

> fitdp1<-nls(den~Rm[ref]/(1+(depth/d50)^c),data=dproot,

 algorithm="port",
 + start = list(Rm=c(1.01, 1.01, 1.01, 6.65, 1.01, 1), d50=20, c=-1),
 + lower = list(Rm=c(1.01, 1.01, 1.01, 6.65, 1.01, 1), d50=20, c=-1),
 + upper = list(Rm=c(2.1, 2.2, 2.12, 12.5, 2.3, 1), d50=50, c=1))

 Error in 

Re: [R] How to coerce a parameter in nls?

2015-09-21 Thread Gabor Grothendieck
Express the formula in terms of simple operations like this:

# add 0/1 columns ref.1, ref.2, ..., ref.6
dproot2 <- do.call(data.frame, transform(dproot, ref = outer(dproot$ref,
seq(6), "==") + 0))

# now express the formula in terms of the new columns
library(nlmrt)
fitdp1<-nlxb(den ~ (Rm1 * ref.1 + Rm2 * ref.2 + Rm3 * ref.3 + Rm4 * ref.4 +
Rm5 * ref.5 + Rm6 * ref.6)/(1+(depth/d50)^c),
 data = dproot2,
 start = c(Rm1=1.01, Rm2=1.01, Rm3=1.01, Rm4=6.65, Rm5=1.01, Rm6=1,
d50=20, c=-1),
 masked = "Rm6")

where we used this input:

Lines <- "   depth   den ref
1 20 0.573   1
2 40 0.780   1
3 60 0.947   1
4 80 0.990   1
5100 1.000   1
6 10 0.600   2
7 20 0.820   2
8 30 0.930   2
9 40 1.000   2
1020 0.480   3
1140 0.734   3
1260 0.961   3
1380 0.998   3
14   100 1.000   3
1520 3.2083491   4
1640 4.9683383   4
1760 6.2381133   4
1880 6.5322348   4
19   100 6.5780660   4
20   120 6.6032064   4
2120 0.614   5
2240 0.827   5
2360 0.950   5
2480 0.995   5
25   100 1.000   5
2620 0.4345774   6
2740 0.6654726   6
2860 0.8480684   6
2980 0.9268951   6
30   100 0.9723207   6
31   120 0.9939966   6
32   140 0.9992400   6"

dproot <- read.table(text = Lines, header = TRUE)



On Mon, Sep 21, 2015 at 12:22 PM, Jianling Fan 
wrote:

> Thanks Prof. Nash,
>
> Sorry for late reply. I am learning and trying to use your nlmrt
> package since I got your email. It works good to mask a parameter in
> regression but seems does work for my equation. I think the problem is
> that the parameter I want to mask is a group-specific parameter and I
> have a "[]" syntax in my equation. However, I don't have your 2014
> book on hand and couldn't find it in our library. So I am wondering if
> nlxb works for group data?
> Thanks a lot!
>
> following is my code and I got a error form it.
>
> > fitdp1<-nlxb(den~Rm[ref]/(1+(depth/d50)^c),data=dproot,
> + start =c(Rm1=1.01, Rm2=1.01, Rm3=1.01, Rm4=6.65,
> Rm5=1.01, Rm6=1, d50=20, c=-1),
> + masked=c("Rm6"))
>
> Error in deriv.default(parse(text = resexp), names(start)) :
>   Function '`[`' is not in the derivatives table
>
>
> Best regards,
>
> Jianling
>
>
> On 20 September 2015 at 12:56, ProfJCNash  wrote:
> > I posted a suggestion to use nlmrt package (function nlxb to be precise),
> > which has masked (fixed) parameters. Examples in my 2014 book on
> Nonlinear
> > parameter optimization with R tools. However, I'm travelling just now, or
> > would consider giving this a try.
> >
> > JN
> >
> >
> > On 15-09-20 01:19 PM, Jianling Fan wrote:
> >>
> >> no, I am doing a regression with 6 group data with 2 shared parameters
> >> and 1 different parameter for each group data. the parameter I want to
> >> coerce is for one group. I don't know how to do it. Any suggestion?
> >>
> >> Thanks!
> >>
> >> On 19 September 2015 at 13:33, Jeff Newmiller  >
> >> wrote:
> >>>
> >>> Why not rewrite the function so that value is not a parameter?
> >>>
> >>>
> ---
> >>> Jeff NewmillerThe .   .  Go
> >>> Live...
> >>> DCN:Basics: ##.#.   ##.#.  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.
> >>>
> >>> On September 18, 2015 9:54:54 PM PDT, Jianling Fan
> >>>  wrote:
> 
>  Hello, everyone,
> 
>  I am using a nls regression with 6 groups data. I am trying to coerce
>  a parameter to 1 by using a upper and lower statement. but I always
>  get an error like below:
> 
>  Error in ifelse(internalPars < upper, 1, -1) :
>    (list) object cannot be coerced to type 'double'
> 
>  does anyone know how to fix it?
> 
>  thanks in advance!
> 
>  My code is below:
> 
> 
> 
> > dproot
> 
> depth   den ref
>  1 20 0.573   1
>  2 40 0.780   1
>  3 60 0.947   1
>  4 80 0.990   1
>  5100 1.000   1
>  6 10 0.600   2
>  7 20 0.820   2
>  8 30 0.930   2
>  9 40 1.000   2
>  1020 0.480   3
>  1140 0.734   3
>  1260 0.961   3
>  1380 0.998   3
>  14   100 1.000   3
>  1520 3.2083491   4
>  1640 4.9683383   4
>  1760 6.2381133   4
>  18

Re: [R] Extract from data.frame

2015-09-21 Thread Mark Sharp
Nico, 

I expect there are many better ways to do this, but this does work:
max_row <- (1:nrow(df))[which.max(df$Amount)]
mean(df$Amount[max_row + c(-1, 0, 1)])

> max_row <- (1:nrow(df))[which.max(df$Amount)]
> mean(df$Amount[max_row + c(-1, 0, 1)])
[1] 151.6667

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org




> On Sep 21, 2015, at 9:52 AM, Nico Gutierrez  wrote:
> 
> Hi All,
> 
> I need to do the following operation from data.frame:
> 
> df <- data.frame(Year = c("2001", "2002", "2003", "2004", "2005", "2006",
> "2007"), Amount = c(150, 120, 175, 160, 120, 105, 135))
> df[which.max(df$Amount),]  #to extract row with max Amount.
> 
> Now I need to do 3 years average around the max Amount value (ie:
> mean(120,175,160))
> 
> Thanks!
> N
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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 add 1 + 1 with the interface between R and C

2015-09-21 Thread Cleber Borges

I think is time to learning Rcpp! :-)

thank you   (Peter Dalgaard and Dirk Eddelbuettel )  by the examples!

the more simples are often more informatives...

cleber

Em 21/09/2015 12:36, Dirk Eddelbuettel escreveu:

peter dalgaard  gmail.com> writes:

C is call by value and k and res are pointers. You need a dereferencing

step or nothing with happen. Try

*res = *k + 1;

Or you use Rcpp which writes the glue code. Save the following into a file:


#include 

// [[Rcpp::export]]
int adder(int x, int y) {
   return x + y;
}

/*** R
adder(40, 2)
*/




Running this is as simple as sourcing it:

   R> Rcpp::sourceCpp("/tmp/adder.cpp")

   R> adder(40, 2)
   [1] 42
   R>

and it even runs the R snippet at the bottom.

Dirk

__



---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Extract from data.frame

2015-09-21 Thread Bert Gunter
Note the following problems:

1. " max_row <- (1:nrow(df))[which.max(df$Amount)]"

This is a bit silly.

max_row <- which.max(df$Amount)


will do. See ?which.max


2. What happens if the max is the first or last row? e.g.

> dat <- data.frame(a=runif(5),b=1:5)
> max_row<- which.max(dat$b)
> mean(dat[max_row+c(-1,0,1),"b"]) ## 2-d indexing
[1] NA


Cheers,
Bert Gunter

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
   -- Clifford Stoll


On Mon, Sep 21, 2015 at 10:51 AM, Mark Sharp  wrote:
> Nico,
>
> I expect there are many better ways to do this, but this does work:
> max_row <- (1:nrow(df))[which.max(df$Amount)]
> mean(df$Amount[max_row + c(-1, 0, 1)])
>
>> max_row <- (1:nrow(df))[which.max(df$Amount)]
>> mean(df$Amount[max_row + c(-1, 0, 1)])
> [1] 151.6667
>
> R. Mark Sharp, Ph.D.
> Director of Primate Records Database
> Southwest National Primate Research Center
> Texas Biomedical Research Institute
> P.O. Box 760549
> San Antonio, TX 78245-0549
> Telephone: (210)258-9476
> e-mail: msh...@txbiomed.org
>
>
>
>
>> On Sep 21, 2015, at 9:52 AM, Nico Gutierrez  
>> wrote:
>>
>> Hi All,
>>
>> I need to do the following operation from data.frame:
>>
>> df <- data.frame(Year = c("2001", "2002", "2003", "2004", "2005", "2006",
>> "2007"), Amount = c(150, 120, 175, 160, 120, 105, 135))
>> df[which.max(df$Amount),]  #to extract row with max Amount.
>>
>> Now I need to do 3 years average around the max Amount value (ie:
>> mean(120,175,160))
>>
>> Thanks!
>> N
>>
>>   [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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 -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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] Download showing as exploit

2015-09-21 Thread Duncan Murdoch
On 21/09/2015 10:30 AM, Tim Kingston wrote:
> 
> Hi , 
> 
> I work for the NHS, and our IT service has been unable to download as its 
> anti-virus software says it contains an exploit.
> 
> Is this normal? Is there a way around this?
> 
> Kind regards,
> 
> Tim Kingston
> 

You don't say what you're trying to download, or from where.

In the past there have been false positive reports from various
anti-virus packages about R.  I don't recall any cases of real malware
being distributed, but eventually it will probably happen.

What you should do is ask your IT service for details of what the
problem is, and ask them to confirm it's real.  If so, please let us
know the details.  If not, then I can't see how we can help.

Duncan Murdoch

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Extract from data.frame

2015-09-21 Thread John McKown
On Mon, Sep 21, 2015 at 9:52 AM, Nico Gutierrez 
wrote:

> Hi All,
>
> I need to do the following operation from data.frame:
>
> df <- data.frame(Year = c("2001", "2002", "2003", "2004", "2005", "2006",
> "2007"), Amount = c(150, 120, 175, 160, 120, 105, 135))
> df[which.max(df$Amount),]  #to extract row with max Amount.
>
> Now I need to do 3 years average around the max Amount value (ie:
> mean(120,175,160))
>
> Thanks!
> N
>
>
​The simplistic answer is something like:

df <- structure(list(Year = structure(1:7, .Label = c("2001", "2002",
"2003", "2004", "2005", "2006", "2007"), class = "factor"), Amount = c(150,
120, 175, 160, 120, 105, 135)), .Names = c("Year", "Amount"), row.names =
c(NA,
-7L), class = "data.frame");
wdf <- which.max(df$Amount);
adf3 <- mean(df$Amount[adf-1:adr+1]);

But that ignores the boundry condition where the maximum is at either end.
What do you want to do in that case?​


-- 

Schrodinger's backup: The condition of any backup is unknown until a
restore is attempted.

Yoda of Borg, we are. Futile, resistance is, yes. Assimilated, you will be.

He's about as useful as a wax frying pan.

10 to the 12th power microphones = 1 Megaphone

Maranatha! <><
John McKown

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] ggplot2 will not install after system upgrade

2015-09-21 Thread Jeff Trefftzs
On Thu, 2015-09-03 at 16:47 -0400, Ista Zahn wrote:
> Hi Jeff,
> Your chances of getting a useful response will increase if you
> provide
> some additional information. For example, which version of R? Which
> version of ggplot2? What sequence of commands produces the error?
> What
> _exactly_ does the error message say?
> 
> Does
> 
> update.packages(ask=FALSE, checkBuilt=TRUE)
> install.packages("ggplot2")
> 
> help?

Thank you, Ista!  This did, indeed, fix the problem.  ggplot2 now works
fine on both the laptop and the desktop computers.

-- 
Jeff Trefftzs
http://www.trefftzs.org

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 coerce a parameter in nls?

2015-09-21 Thread Jianling Fan
Thanks Gabor,

 That works good to rewrite the express the formula!

Thanks a lot!

Regards,

Jianling

On 21 September 2015 at 10:43, Gabor Grothendieck
 wrote:
> Express the formula in terms of simple operations like this:
>
> # add 0/1 columns ref.1, ref.2, ..., ref.6
> dproot2 <- do.call(data.frame, transform(dproot, ref = outer(dproot$ref,
> seq(6), "==") + 0))
>
> # now express the formula in terms of the new columns
> library(nlmrt)
> fitdp1<-nlxb(den ~ (Rm1 * ref.1 + Rm2 * ref.2 + Rm3 * ref.3 + Rm4 * ref.4 +
> Rm5 * ref.5 + Rm6 * ref.6)/(1+(depth/d50)^c),
>  data = dproot2,
>  start = c(Rm1=1.01, Rm2=1.01, Rm3=1.01, Rm4=6.65, Rm5=1.01, Rm6=1,
> d50=20, c=-1),
>  masked = "Rm6")
>
> where we used this input:
>
> Lines <- "   depth   den ref
> 1 20 0.573   1
> 2 40 0.780   1
> 3 60 0.947   1
> 4 80 0.990   1
> 5100 1.000   1
> 6 10 0.600   2
> 7 20 0.820   2
> 8 30 0.930   2
> 9 40 1.000   2
> 1020 0.480   3
> 1140 0.734   3
> 1260 0.961   3
> 1380 0.998   3
> 14   100 1.000   3
> 1520 3.2083491   4
> 1640 4.9683383   4
> 1760 6.2381133   4
> 1880 6.5322348   4
> 19   100 6.5780660   4
> 20   120 6.6032064   4
> 2120 0.614   5
> 2240 0.827   5
> 2360 0.950   5
> 2480 0.995   5
> 25   100 1.000   5
> 2620 0.4345774   6
> 2740 0.6654726   6
> 2860 0.8480684   6
> 2980 0.9268951   6
> 30   100 0.9723207   6
> 31   120 0.9939966   6
> 32   140 0.9992400   6"
>
> dproot <- read.table(text = Lines, header = TRUE)
>
>
>
> On Mon, Sep 21, 2015 at 12:22 PM, Jianling Fan 
> wrote:
>>
>> Thanks Prof. Nash,
>>
>> Sorry for late reply. I am learning and trying to use your nlmrt
>> package since I got your email. It works good to mask a parameter in
>> regression but seems does work for my equation. I think the problem is
>> that the parameter I want to mask is a group-specific parameter and I
>> have a "[]" syntax in my equation. However, I don't have your 2014
>> book on hand and couldn't find it in our library. So I am wondering if
>> nlxb works for group data?
>> Thanks a lot!
>>
>> following is my code and I got a error form it.
>>
>> > fitdp1<-nlxb(den~Rm[ref]/(1+(depth/d50)^c),data=dproot,
>> + start =c(Rm1=1.01, Rm2=1.01, Rm3=1.01, Rm4=6.65,
>> Rm5=1.01, Rm6=1, d50=20, c=-1),
>> + masked=c("Rm6"))
>>
>> Error in deriv.default(parse(text = resexp), names(start)) :
>>   Function '`[`' is not in the derivatives table
>>
>>
>> Best regards,
>>
>> Jianling
>>
>>
>> On 20 September 2015 at 12:56, ProfJCNash  wrote:
>> > I posted a suggestion to use nlmrt package (function nlxb to be
>> > precise),
>> > which has masked (fixed) parameters. Examples in my 2014 book on
>> > Nonlinear
>> > parameter optimization with R tools. However, I'm travelling just now,
>> > or
>> > would consider giving this a try.
>> >
>> > JN
>> >
>> >
>> > On 15-09-20 01:19 PM, Jianling Fan wrote:
>> >>
>> >> no, I am doing a regression with 6 group data with 2 shared parameters
>> >> and 1 different parameter for each group data. the parameter I want to
>> >> coerce is for one group. I don't know how to do it. Any suggestion?
>> >>
>> >> Thanks!
>> >>
>> >> On 19 September 2015 at 13:33, Jeff Newmiller
>> >> 
>> >> wrote:
>> >>>
>> >>> Why not rewrite the function so that value is not a parameter?
>> >>>
>> >>>
>> >>> ---
>> >>> Jeff NewmillerThe .   .  Go
>> >>> Live...
>> >>> DCN:Basics: ##.#.   ##.#.  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.
>> >>>
>> >>> On September 18, 2015 9:54:54 PM PDT, Jianling Fan
>> >>>  wrote:
>> 
>>  Hello, everyone,
>> 
>>  I am using a nls regression with 6 groups data. I am trying to coerce
>>  a parameter to 1 by using a upper and lower statement. but I always
>>  get an error like below:
>> 
>>  Error in ifelse(internalPars < upper, 1, -1) :
>>    (list) object cannot be coerced to type 'double'
>> 
>>  does anyone know how to fix it?
>> 
>>  thanks in advance!
>> 
>>  My code is below:
>> 
>> 
>> 
>> > dproot
>> 
>> depth   den ref
>>  1 20 0.573   1
>>  2 40 0.780   1
>>  3 60 0.947   1
>>  4 80 

Re: [R] Trees (and Forests) with packages 'party' vs. 'partykit': Different results

2015-09-21 Thread apeshifter
Achim, 

thank you very much for your help, this really cleared up a number of
issues.

As for the differences in results between the party and partykit
implementations of ctree, I guess that the situation is indeed as you
assumed. Four out of five variables have p-values <2.2e-16. (However, it is
not the first of these variables that is selected but the one in the second
column.) I will just continue using the newer implementation. 

-- Christopher



--
View this message in context: 
http://r.789695.n4.nabble.com/Trees-and-Forests-with-packages-party-vs-partykit-Different-results-tp4712214p4712539.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] R-help, please

2015-09-21 Thread le4...@mweb.co.za
Good day,
My name is Kim Nguyen and please I need your help with: How to calculate the 
PASS rate of the data in the table below, with PASS in a single subject if 
value>=50 and PASS will be given if PASS 3 out of 4 subjectsWhich package will 
I need to use in this analysis




ID

Literacy

Maths

Physics

Chemistry


A

65

70

79

80


B

65

45

38

50


C

50

62

48

49


D

70

85

82

84


E

45

69

65

62

I appreciate your consultant very much
With kind regardsKim Nguyen
Sent from MWEB Message Centre - CONNECT AND YOU CAN

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 add 1 + 1 with the interface between R and C

2015-09-21 Thread Dirk Eddelbuettel
peter dalgaard  gmail.com> writes:
> C is call by value and k and res are pointers. You need a dereferencing 
step or nothing with happen. Try
> 
> *res = *k + 1;

Or you use Rcpp which writes the glue code. Save the following into a file:


#include 

// [[Rcpp::export]]
int adder(int x, int y) {
  return x + y;
}

/*** R
adder(40, 2)
*/




Running this is as simple as sourcing it:

  R> Rcpp::sourceCpp("/tmp/adder.cpp")

  R> adder(40, 2)
  [1] 42
  R> 

and it even runs the R snippet at the bottom.

Dirk

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Extract from data.frame

2015-09-21 Thread Nico Gutierrez
Hi All,

I need to do the following operation from data.frame:

df <- data.frame(Year = c("2001", "2002", "2003", "2004", "2005", "2006",
"2007"), Amount = c(150, 120, 175, 160, 120, 105, 135))
df[which.max(df$Amount),]  #to extract row with max Amount.

Now I need to do 3 years average around the max Amount value (ie:
mean(120,175,160))

Thanks!
N

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Download showing as exploit

2015-09-21 Thread Tim Kingston

Hi , 

I work for the NHS, and our IT service has been unable to download as its 
anti-virus software says it contains an exploit.

Is this normal? Is there a way around this?

Kind regards,

Tim Kingston

Sent from my HTC



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 IN GRAPHS - slip screen (URGENT)

2015-09-21 Thread Jim Lemon
Hi Rosa,
I think I understand more or less what you want, but the example below uses
made up data as I do not have access to your files. The following code
should produce a block of eight plots with the y axes on the leftmost plots
only and the x axes on the bottom row only. I think I have what you wanted
for the titles. You can get a gap between the two rows of plots if you add
a 0.5 bottom margin to the top row and a 0.5 top margin to the bottom row.
All you have to do is use your data instead of the made up data. I used a
device with width=12 and height=5.

# do the first split, to get the rightmost screen for the legend
split.screen(figs=matrix(c(0,0.84,0,1,0.84,1,0,1),nrow=2,byrow=TRUE))
# now split the first screen to get your eight screens
# (numbered 3 to 10) for the plots
split.screen(figs=matrix(c(0,0.31,0.5,1,
   0.31,0.54,0.5,1,
   0.54,0.77,0.5,1,
   0.77,1,0.5,1,
   0,0.31,0,0.5,
   0.31,0.54,0,0.5,
   0.54,0.77,0,0.5,
   0.77,1,0,0.5),
 ncol=4,byrow=TRUE),screen=1)

# now make up some data so that I can try out the plot
lambda<-seq(0.7,0.95,by=0.05)
ols_bias_alpha1_250<-c(0.6,0.5,0.4,0.3,0.2,0.1)
ols_bias_alpha1_1000<-c(0.62,0.53,0.44,0.35,0.26,0.17)
gls_bias_alpha1_250<-c(-0.05,0,0.01,0.02,0,-0.01)
gls_bias_alpha1_1000<-c(0.09,0.08,0.07,0.05,0.04,0.045)

screen(3)
par(mar=c(0,4,3,0))
# plot bias for alpha1 250
matplot(lambda,matrix(c(ols_bias_alpha1_250,gls_bias_alpha1_250),ncol=2),
 type="l",col=c(4,2),xaxt="n",ylim=c(-.1, .6),
 ylab="", cex.main=1)
abline(h = 0, col = "gray60")
mtext("nsample=250",side=3,line=0.6)
mtext(expression(paste("Bias av. for  ",alpha[1])),side=2,line=2,
cex.main=1)

screen(4)
par(mar=c(0,0,3,0))
# plot bias for alpha1 1000
matplot(lambda,matrix(c(ols_bias_alpha1_1000,gls_bias_alpha1_1000),ncol=2),
 type="l",col=c(4,2),xaxt="n",yaxt="n",ylim=c(-.1, .6),
 ylab="", cex.main=1)
abline(h = 0, col = "gray60")
mtext("nsample=1000",side=3,line=0.6)
# now the centered title
par(xpd=TRUE)
mtext("alpha1",side=3,line=1.7,at=0.69)
par(xpd=FALSE)

# make up more data
ols_bias_alpha2_250<-c(-0.04,-0.05,-0.06,-0.05,-0.04,-0.03)
ols_bias_alpha2_1000<-c(-0.04,-0.05,-0.06,-0.05,-0.04,-0.035)
gls_bias_alpha2_250<-c(0.1,0.08,0.06,0.04,0.03,0.01)
gls_bias_alpha2_1000<-c(0.1,0.08,0.06,0.04,0.03,0.01)

screen(5)
par(mar=c(0,0,3,0))
# plot bias for alpha2 250
matplot(lambda,matrix(c(ols_bias_alpha2_250,gls_bias_alpha2_250),ncol=2),
 type="l",col=c(4,2),xaxt="n",yaxt="n",ylim=c(-.1, .6),
 ylab="", cex.main=1)
abline(h = 0, col = "gray60")
mtext("nsample=250",side=3,line=0.6)

screen(6)
par(mar=c(0,0,3,0))
# plot bias for alpha2 1000
matplot(lambda,matrix(c(ols_bias_alpha2_1000,gls_bias_alpha2_1000),ncol=2),
 type="l",col=c(4,2),xaxt="n",yaxt="n",ylim=c(-.1, .6),
 ylab="", cex.main=1)
abline(h = 0, col = "gray60")
mtext("nsample=1000",side=3,line=0.6)
# now the centered title
par(xpd=TRUE)
mtext("alpha2",side=3,line=1.7,at=0.69)
par(xpd=FALSE)

# more data!
ols_se_alpha1_250<-c(0.45,0.46,0.47,0.48,0.49,0.51)
gls_se_alpha1_250<-c(0.7,0.62,0.58,0.56,0.54,0.52)
ols_se_alpha1_1000<-c(0.2,0.21,0.22,0.23,0.24,0.251)
gls_se_alpha1_1000<-c(0.3,0.29,0.28,0.27,0.26,0.252)

screen(7)
par(mar=c(3,4,0,0))
# plot SE for alpha1 250
matplot(lambda,matrix(c(ols_se_alpha1_250,gls_se_alpha1_250),ncol=2),
 type="l",col=c(4,2),ylim=c(0,1.1),
 ylab="", cex.main=1)
mtext(expression(paste("SE av. for  ",alpha[1])),side=2,line=2, cex.main=1)
mtext(expression(paste(lambda)),side=1,line=2, cex.main=1.5)

screen(8)
par(mar=c(3,0,0,0))
# plot SE for alpha1 1000
matplot(lambda,matrix(c(ols_se_alpha1_1000,gls_se_alpha1_1000),ncol=2),
 type="l",col=c(4,2),ylim=c(0,1.1),yaxt="n",
 ylab="", cex.main=1)
mtext(expression(paste(lambda)),side=1,line=2, cex.main=1.5)

# even more data!
ols_se_alpha2_250<-c(0.12,0.13,0.14,0.16,0.18,0.2)
gls_se_alpha2_250<-c(0.3,0.26,0.24,0.22,0.21,0.2)
ols_se_alpha2_1000<-c(0.1,0.11,0.12,0.13,0.14,0.15)
gls_se_alpha2_1000<-c(0.2,0.19,0.18,0.17,0.16,0.15)

screen(9)
par(mar=c(3,0,0,0))
# plot SE for alpha1 250
matplot(lambda,matrix(c(ols_se_alpha2_250,gls_se_alpha2_250),ncol=2),
 type="l",col=c(4,2),ylim=c(0,1.1),
 yaxt="n",ylab="", cex.main=1)
mtext(expression(paste(lambda)),side=1,line=2, cex.main=1.5)

screen(10)
par(mar=c(3,0,0,0))
# plot SE for alpha1 1000
matplot(lambda,matrix(c(ols_se_alpha2_1000,gls_se_alpha2_1000),ncol=2),
 type="l",col=c(4,2),ylim=c(0,1.1),yaxt="n",
 ylab="", cex.main=1)
mtext(expression(paste(lambda)),side=1,line=2, cex.main=1.5)

# finally the legend
screen(2)
par(mar=c(0,0,0,0))
# plot an empty plot to get the coordinates
plot(0:1,0:1,type="n",axes=FALSE)
legend(0,0.6,c("OLS", "GLS", "Reg. Cal.", "0"),bty = "n",
lty=1:3,col=c(4,2,3,"gray60"),xpd=TRUE)

close.screen(all=TRUE)

Jim


On Mon, Sep 21, 2015 at 2:14 AM, Rosa Oliveira  wrote:

> Dear Jim,
>
>
> 

[R] Accounting for correlated random effects in coxme with matrix from a phylogeny rather than pedigree

2015-09-21 Thread Oyomoare Osazuwa-Peters
Hello All,

I have a problem with running the mixed effects Cox regression model using
a distance matrix from a phylogeny rather than a pedigree. I searched
previous posts and didn't find any directly relevant previous posts.

I am interested in using a mixed effects Cox regression model to determine
the best predictors of time to recruitment in 80 different reintroduced
plant populations representing a total of 31 species. I will like to
account for correlated random effects that result from phylogenetic
relationships amongst species. Dr. Therneau's 2015 article on Mixed Effects
Cox Models provide a very helpful template for me to do this with the coxme
function in R. In this article, the correlation structure due to genetic
relationships amongst individuals was defined using a kinship matrix
derived from a pedigree. Instead of a pedigree, I have a phylogeny for
these 31 species. Hence, I used the inverseA function in the MCMCglmm
package to generate an inverse additive genetic relatedness matrix from the
phylogeny for these 31 species. And then fed it in as input to the varlist
argument in my mixed effects cox regression model (using function coxme). I
got an error message (please see below). Based on the error, one thought I
had was to convert the inverseA matrix from a “dgCMatrix” to “bdsmatrix”
but this was not successful either. I have also unsuccessfully tried to use
a pairwise phylogenetic distance matrix.

Is there a better way to do this? I basically just want to account for the
correlated random effects due to phylogenetic relatedness amongst the 31
species represented in the dataset for the Cox regression model.  Please
see my code below and I welcome suggestions on how best to make this work.

Thank you.

#Load packages
library(MCMCglmm)
library(asremlPLUS)
library(ape)

source("read.newick.R")


mytree <- read.newick(file="Phylo_2015Sept15.txt")

mytree6 <- makeNodeLabel(mytree, method="number", prefix = "node")#Make
sure each node is uniquely labeled

IA <- inverseA(mytree6, scale=TRUE) #generate inverse of the additive
genetic relatedness matrix (A) from phylogeny

#Use IA as input in correlated random effects model. Doesn't work.

fit2 <- coxme(Surv(surv.time, recruitment) ~ pred1 + pred2 + sixcatD1 +
sixcatD2 + sixcatD3 + (1|species), data = traitcox, varlist=coxmeMlist(IA,
rescale=F))

Error in as(x, "bdsmatrix") :
  no method or default for coercing “dgCMatrix” to “bdsmatrix”

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] extract from data.frame (indexing)

2015-09-21 Thread Nico Gutierrez
Hi All,

I need to do the following operation:


  Year Amount Amount.1
1 2001150  150
2 2002120  120
3 2003175  175
4 2004160  160
5 2005120  120
6 2006105  105
7 2007135  135

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 add 1 + 1 with the interface between R and C

2015-09-21 Thread peter dalgaard

> On 21 Sep 2015, at 04:03 , Cleber N.Borges  wrote:
> 
> Dear useRs,
> 
> I would like some help on how to make the sum of 1 + 1
> but using the interface between A and C.
> 
> the function call does .call lock and close the R.
> 
> Thank you for any help it.

Either you need a basic course in C, or you need a refresher:


> 
> void testfun( double *k, double *res )
> {
>res = k + 1;
> }

C is call by value and k and res are pointers. You need a dereferencing step or 
nothing with happen. Try

*res = *k + 1;


-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] R code help!

2015-09-21 Thread SH
Hi Jean,

Thank you so much!

Steve

On Sat, Sep 19, 2015 at 1:02 PM, Adams, Jean  wrote:

> Here's one way to save your results, using a list of lists and a for()
> loop.
>
> nsim <- 100
> outputs <- vector("list", nsim)
> for(i in 1:nsim) {
>   outputs[[i]] <- sim.f(p.s=.05, N=1000, sample.size=69, n.sim=500)
> }
>
> Jean
>
> On Fri, Sep 18, 2015 at 2:27 PM, SH  wrote:
>
>> Dear R users,
>>
>> I am trying to simulate surveys and the survey result will be used to
>> determine the population to be "accepted" or "rejected".  With the
>> results,
>> I would like to calculate cumulative means and plot them to see if a
>> converged value is as expected.  Below is R-code I generated.  I need a
>> help to repeat this simulation code as many times (e.g., 100) and keep the
>> results as list format if possible.  Could you give me any insight?
>>
>> Thanks  a lot in advance,
>>
>> Steve
>>
>> sim.f <- function(p.s, N, sample.size, n.sim) {
>> pop = sampled.pop = decision = decisionB = cum.mn = as.list(NULL)
>> for(i in 1:n.sim) {
>>p <- c(rep(1, p.s*N), pop2 <- rep(0, N*(1-p.s))) # Generate sample
>> space
>>pop[[i]] <- sample(p) # Randomization sample space
>>sampled.pop[[i]] <- sample(pop[[i]], sample.size)# Random sampling
>>decision[i] <- ifelse(sum(sampled.pop[[i]])>=1, 'Reject','Pass') #
>> Decision for each group of n.sim
>>decisionB <- ifelse(decision == 'Reject', 1, 0) # Convert to binary
>>cum.mn <- cumsum(decisionB) / seq_along(decisionB) # Cummulative mean
>> of
>> n.sim group decisions
>>}
>> result = list(population=pop,
>>   pop_sub = sampled.pop,
>>   decision = decision,
>>   decisionB = decisionB,
>>   cum.mn = cum.mn)
>> }
>> sim.out <- sim.f(p.s=.05, N=1000, sample.size=69, n.sim=500)
>> # I want to repeat this simulation function for example 100 times or and
>> also #keep the data so that I can explore later.  If it is not possible to
>> keep all #outputs, at least I would like to have cum.mn outputs.
>>
>> summary(sim.out)
>> sim.out$population
>> sim.out$pop_sub
>> sim.out$decision
>> sim.out$decisionB
>> y1 <- sim.out$cum.mn
>> #plot(y1, type='l')
>> lines(y2, type='l')
>> ...
>> lines(y100, type='l')
>> abline(h=.95, col='red')
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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 -- To UNSUBSCRIBE and more, see
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] Extract from data.frame

2015-09-21 Thread Frank Schwidom

year <- df$Year[ which.max( df$Amount)]
df[ df$Year %in% (as.numeric( as.character( year)) + -1:1), ]
  Year Amount
2 2002120
3 2003175
4 2004160


On Mon, Sep 21, 2015 at 04:52:46PM +0200, Nico Gutierrez wrote:
> Hi All,
> 
> I need to do the following operation from data.frame:
> 
> df <- data.frame(Year = c("2001", "2002", "2003", "2004", "2005", "2006",
> "2007"), Amount = c(150, 120, 175, 160, 120, 105, 135))
> df[which.max(df$Amount),]  #to extract row with max Amount.
> 
> Now I need to do 3 years average around the max Amount value (ie:
> mean(120,175,160))
> 
> Thanks!
> N
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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] extracting a value from XML

2015-09-21 Thread Glenn Schultz

Hi Bob,

Thanks, can you help me undestand why it starts with //observation and how you 
know that it is a node?

Glenn

On Sep 21, 2015, at 01:56 PM, boB Rudis  wrote:

This is how (one way) in both the xml2 package and XML package:

library(xml2)
library(XML)

txt <- '


'

doc <- read_xml(txt)
xml_attr(xml_find_all(doc, "//observation"), "value")

doc1 <- xmlParse(txt)
xpathSApply(doc1, "//observation", xmlGetAttr, "value")



On Mon, Sep 21, 2015 at 2:01 PM, Glenn Schultz  wrote:




__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 coerce a parameter in nls?

2015-09-21 Thread ProfJCNash
I've not used it for group data, and suspect that the code to generate 
derivatives cannot cope with the bracket syntax. If you can rewrite the 
equation without the brackets, you could get the derivatives and solve 
that way. This will probably mean having a "translation" routine to glue 
things together.


JN

On 15-09-21 12:22 PM, Jianling Fan wrote:

Thanks Prof. Nash,

Sorry for late reply. I am learning and trying to use your nlmrt
package since I got your email. It works good to mask a parameter in
regression but seems does work for my equation. I think the problem is
that the parameter I want to mask is a group-specific parameter and I
have a "[]" syntax in my equation. However, I don't have your 2014
book on hand and couldn't find it in our library. So I am wondering if
nlxb works for group data?
Thanks a lot!

following is my code and I got a error form it.


fitdp1<-nlxb(den~Rm[ref]/(1+(depth/d50)^c),data=dproot,

 + start =c(Rm1=1.01, Rm2=1.01, Rm3=1.01, Rm4=6.65,
Rm5=1.01, Rm6=1, d50=20, c=-1),
 + masked=c("Rm6"))

Error in deriv.default(parse(text = resexp), names(start)) :
   Function '`[`' is not in the derivatives table


Best regards,

Jianling


On 20 September 2015 at 12:56, ProfJCNash  wrote:

I posted a suggestion to use nlmrt package (function nlxb to be precise),
which has masked (fixed) parameters. Examples in my 2014 book on Nonlinear
parameter optimization with R tools. However, I'm travelling just now, or
would consider giving this a try.

JN


On 15-09-20 01:19 PM, Jianling Fan wrote:


no, I am doing a regression with 6 group data with 2 shared parameters
and 1 different parameter for each group data. the parameter I want to
coerce is for one group. I don't know how to do it. Any suggestion?

Thanks!

On 19 September 2015 at 13:33, Jeff Newmiller 
wrote:


Why not rewrite the function so that value is not a parameter?

---
Jeff NewmillerThe .   .  Go
Live...
DCN:Basics: ##.#.   ##.#.  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.

On September 18, 2015 9:54:54 PM PDT, Jianling Fan
 wrote:


Hello, everyone,

I am using a nls regression with 6 groups data. I am trying to coerce
a parameter to 1 by using a upper and lower statement. but I always
get an error like below:

Error in ifelse(internalPars < upper, 1, -1) :
   (list) object cannot be coerced to type 'double'

does anyone know how to fix it?

thanks in advance!

My code is below:




dproot


depth   den ref
1 20 0.573   1
2 40 0.780   1
3 60 0.947   1
4 80 0.990   1
5100 1.000   1
6 10 0.600   2
7 20 0.820   2
8 30 0.930   2
9 40 1.000   2
1020 0.480   3
1140 0.734   3
1260 0.961   3
1380 0.998   3
14   100 1.000   3
1520 3.2083491   4
1640 4.9683383   4
1760 6.2381133   4
1880 6.5322348   4
19   100 6.5780660   4
20   120 6.6032064   4
2120 0.614   5
2240 0.827   5
2360 0.950   5
2480 0.995   5
25   100 1.000   5
2620 0.4345774   6
2740 0.6654726   6
2860 0.8480684   6
2980 0.9268951   6
30   100 0.9723207   6
31   120 0.9939966   6
32   140 0.9992400   6


fitdp<-nls(den~Rm[ref]/(1+(depth/d50)^c),data=dproot,


+ start = list(Rm=c(1.01, 1.01, 1.01, 6.65,1.01,1), d50=20, c=-1))


summary(fitdp)



Formula: den ~ Rm[ref]/(1 + (depth/d50)^c)

Parameters:
 Estimate Std. Error t value Pr(>|t|)
Rm1  1.125600.07156   15.73 3.84e-14 ***
Rm2  1.576430.11722   13.45 1.14e-12 ***
Rm3  1.106970.07130   15.53 5.11e-14 ***
Rm4  7.239250.20788   34.83  < 2e-16 ***
Rm5  1.145160.07184   15.94 2.87e-14 ***
Rm6  1.036580.05664   18.30 1.33e-15 ***
d50 22.694261.03855   21.85  < 2e-16 ***
c   -1.597960.15589  -10.25 3.02e-10 ***
---
Signif. codes:  0 ?**?0.001 ?*?0.01 ??0.05 ??0.1 ??1

Residual standard error: 0.1094 on 24 degrees of freedom

Number of iterations to convergence: 8
Achieved convergence tolerance: 9.374e-06


fitdp1<-nls(den~Rm[ref]/(1+(depth/d50)^c),data=dproot,


algorithm="port",
+ start = list(Rm=c(1.01, 1.01, 1.01, 6.65, 1.01, 1), d50=20, c=-1),
+ lower = list(Rm=c(1.01, 1.01, 1.01, 6.65, 1.01, 1), d50=20, c=-1),
+ upper = list(Rm=c(2.1, 2.2, 2.12, 12.5, 2.3, 1), d50=50, c=1))

Error in ifelse(internalPars < upper, 1, -1) :
   (list) object cannot be coerced to type 'double'

__
R-help@r-project.org 

Re: [R] How to coerce a parameter in nls?

2015-09-21 Thread ProfJCNash
Apologies for replying and overlapping Gabor's contribution, which 
actually did the work!


Best, JN

On 15-09-21 01:03 PM, Jianling Fan wrote:

Thanks Gabor,

  That works good to rewrite the express the formula!

Thanks a lot!

Regards,

Jianling

On 21 September 2015 at 10:43, Gabor Grothendieck
 wrote:

Express the formula in terms of simple operations like this:

# add 0/1 columns ref.1, ref.2, ..., ref.6
dproot2 <- do.call(data.frame, transform(dproot, ref = outer(dproot$ref,
seq(6), "==") + 0))

# now express the formula in terms of the new columns
library(nlmrt)
fitdp1<-nlxb(den ~ (Rm1 * ref.1 + Rm2 * ref.2 + Rm3 * ref.3 + Rm4 * ref.4 +
Rm5 * ref.5 + Rm6 * ref.6)/(1+(depth/d50)^c),
  data = dproot2,
  start = c(Rm1=1.01, Rm2=1.01, Rm3=1.01, Rm4=6.65, Rm5=1.01, Rm6=1,
d50=20, c=-1),
  masked = "Rm6")

where we used this input:

Lines <- "   depth   den ref
1 20 0.573   1
2 40 0.780   1
3 60 0.947   1
4 80 0.990   1
5100 1.000   1
6 10 0.600   2
7 20 0.820   2
8 30 0.930   2
9 40 1.000   2
1020 0.480   3
1140 0.734   3
1260 0.961   3
1380 0.998   3
14   100 1.000   3
1520 3.2083491   4
1640 4.9683383   4
1760 6.2381133   4
1880 6.5322348   4
19   100 6.5780660   4
20   120 6.6032064   4
2120 0.614   5
2240 0.827   5
2360 0.950   5
2480 0.995   5
25   100 1.000   5
2620 0.4345774   6
2740 0.6654726   6
2860 0.8480684   6
2980 0.9268951   6
30   100 0.9723207   6
31   120 0.9939966   6
32   140 0.9992400   6"

dproot <- read.table(text = Lines, header = TRUE)



On Mon, Sep 21, 2015 at 12:22 PM, Jianling Fan 
wrote:


Thanks Prof. Nash,

Sorry for late reply. I am learning and trying to use your nlmrt
package since I got your email. It works good to mask a parameter in
regression but seems does work for my equation. I think the problem is
that the parameter I want to mask is a group-specific parameter and I
have a "[]" syntax in my equation. However, I don't have your 2014
book on hand and couldn't find it in our library. So I am wondering if
nlxb works for group data?
Thanks a lot!

following is my code and I got a error form it.


fitdp1<-nlxb(den~Rm[ref]/(1+(depth/d50)^c),data=dproot,

 + start =c(Rm1=1.01, Rm2=1.01, Rm3=1.01, Rm4=6.65,
Rm5=1.01, Rm6=1, d50=20, c=-1),
 + masked=c("Rm6"))

Error in deriv.default(parse(text = resexp), names(start)) :
   Function '`[`' is not in the derivatives table


Best regards,

Jianling


On 20 September 2015 at 12:56, ProfJCNash  wrote:

I posted a suggestion to use nlmrt package (function nlxb to be
precise),
which has masked (fixed) parameters. Examples in my 2014 book on
Nonlinear
parameter optimization with R tools. However, I'm travelling just now,
or
would consider giving this a try.

JN


On 15-09-20 01:19 PM, Jianling Fan wrote:


no, I am doing a regression with 6 group data with 2 shared parameters
and 1 different parameter for each group data. the parameter I want to
coerce is for one group. I don't know how to do it. Any suggestion?

Thanks!

On 19 September 2015 at 13:33, Jeff Newmiller

wrote:


Why not rewrite the function so that value is not a parameter?


---
Jeff NewmillerThe .   .  Go
Live...
DCN:Basics: ##.#.   ##.#.  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.

On September 18, 2015 9:54:54 PM PDT, Jianling Fan
 wrote:


Hello, everyone,

I am using a nls regression with 6 groups data. I am trying to coerce
a parameter to 1 by using a upper and lower statement. but I always
get an error like below:

Error in ifelse(internalPars < upper, 1, -1) :
   (list) object cannot be coerced to type 'double'

does anyone know how to fix it?

thanks in advance!

My code is below:




dproot


depth   den ref
1 20 0.573   1
2 40 0.780   1
3 60 0.947   1
4 80 0.990   1
5100 1.000   1
6 10 0.600   2
7 20 0.820   2
8 30 0.930   2
9 40 1.000   2
1020 0.480   3
1140 0.734   3
1260 0.961   3
1380 0.998   3
14   100 1.000   3
1520 3.2083491   4
1640 4.9683383   4
1760 6.2381133   4
1880 6.5322348   4
19   100 6.5780660   4
20   120 6.6032064   4
2120 0.614   5
2240 0.827   5
2360 0.950   5
2480 

Re: [R] extracting a value from XML

2015-09-21 Thread boB Rudis
The "
>  observation_start="2015-09-01" observation_end="2015-09-01"
> units="lin" output_type="1" file_type="xml"
> order_by="observation_date" sort_order="asc" count="1" offset="0"
> limit="10">
>  date="2015-09-01" value="0.46"/>
> '
>
> doc <- read_xml(txt)
> xml_attr(xml_find_all(doc, "//observation"), "value")
>
> doc1 <- xmlParse(txt)
> xpathSApply(doc1, "//observation", xmlGetAttr, "value")
>
>
>
> On Mon, Sep 21, 2015 at 2:01 PM, Glenn Schultz  wrote:
>
> 
>
> 
> observation_start="2015-09-01" observation_end="2015-09-01" units="lin"
>
> output_type="1" file_type="xml" order_by="observation_date" sort_order="asc"
>
> count="1" offset="0" limit="10">
>
> 
> date="2015-09-01" value="0.46"/>
>
> 

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Running GCV Optimization under Ridge Regression

2015-09-21 Thread Preetam Pal
Hi guys,

I am running Ridge regression on a dataset (predicted variable = y; GDP,
HPA and FX are regressors). I found that lm.ridge() can perform the ridge
regression given any value of lambda (i.e. the ridge parameter). However,
in order to choose the best results, I need to select the model output
corresponding to that lambda which optimizes some logically defined GCV
criteria. I thought there would be some in-built funcion in R Studio for
this, but could not find one. Also, I am not being able to write the
required code for this. Any help here will be appreciated. I have attached
the data in case it is required.

Thanks,
Preetam
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Extract from data.frame

2015-09-21 Thread Bert Gunter
No.


On Mon, Sep 21, 2015 at 10:58 AM, John McKown
 wrote:
> On Mon, Sep 21, 2015 at 9:52 AM, Nico Gutierrez 
> wrote:
>
>> Hi All,
>>
>> I need to do the following operation from data.frame:
>>
>> df <- data.frame(Year = c("2001", "2002", "2003", "2004", "2005", "2006",
>> "2007"), Amount = c(150, 120, 175, 160, 120, 105, 135))
>> df[which.max(df$Amount),]  #to extract row with max Amount.
>>
>> Now I need to do 3 years average around the max Amount value (ie:
>> mean(120,175,160))
>>
>> Thanks!
>> N
>>
>>
> The simplistic answer is something like:
>
> df <- structure(list(Year = structure(1:7, .Label = c("2001", "2002",
> "2003", "2004", "2005", "2006", "2007"), class = "factor"), Amount = c(150,
> 120, 175, 160, 120, 105, 135)), .Names = c("Year", "Amount"), row.names =
> c(NA,
> -7L), class = "data.frame");
> wdf <- which.max(df$Amount);
> adf3 <- mean(df$Amount[adf-1:adr+1]);

Typos?!
But it won't work anyway. See ?Syntax for operator precedence and

Example:

> a <- 1:5
> mid <- 3
> a[mid-1:mid+1]
[1] 3 2 1
> a[(mid-1):(mid+1)]
[1] 2 3 4

Cheers,
Bert


>
> But that ignores the boundry condition where the maximum is at either end.
> What do you want to do in that case?
>
>
> --
>
> Schrodinger's backup: The condition of any backup is unknown until a
> restore is attempted.
>
> Yoda of Borg, we are. Futile, resistance is, yes. Assimilated, you will be.
>
> He's about as useful as a wax frying pan.
>
> 10 to the 12th power microphones = 1 Megaphone
>
> Maranatha! <><
> John McKown
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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 add 1 + 1 with the interface between R and C

2015-09-21 Thread Cleber N.Borges

Dear useRs,

I would like some help on how to make the sum of 1 + 1
but using the interface between A and C.

the function call does .call lock and close the R.

Thank you for any help it.

Cleber
###
  R code
text_code <-"
#include 
#include 
#include 
void testfun( double *k, double *res );
void testfun( double *k, double *res )
{
res = k + 1;
}
"
sink('test.c')
cat( text_code )
sink()
system("R CMD SHLIB test.c")
dyn.load( "test.dll" )
is.loaded( 'testfun' )
k=1
.C('testfun', k=as.double(k), res=as.double(0) )


###  Output

> text_code <-"
+ #include 
+ #include 
+ #include 
+ void testfun( double *k, double *res );
+ void testfun( double *k, double *res )
+ {
+ res = k + 1;
+ }
+ "
> sink('test.c')
> cat( text_code )
> sink()
> system("R CMD SHLIB test.c")
cygwin warning:
  MS-DOS style path detected: C:/R/etc/x64/Makeconf
  Preferred POSIX equivalent is: /cygdrive/c/R/etc/x64/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this 
warning.

  Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
gcc -m64 -I"C:/R/include" -DNDEBUG 
-I"d:/RCompile/r-compiling/local/local320/include" -O2 -Wall  
-std=gnu99 -mtune=core2 -c test.c -o test.o
gcc -m64 -shared -s -static-libgcc -o test.dll tmp.def test.o 
-Ld:/RCompile/r-compiling/local/local320/lib/x64 
-Ld:/RCompile/r-compiling/local/local320/lib -LC:/R/bin/x64 -lR

>
> dyn.load( "test.dll" )
>
> is.loaded( 'testfun' )
[1] TRUE
> k=1
> .C('testfun', k=as.double(k), res=as.double(0) )
$k
[1] 1

$res
[1] 0












---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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-es] Una preguntilla

2015-09-21 Thread Jorge I Velez
Heber,

Dale una mirada a

?cbind
?file.choose

"cbind" es el acronimo de "column binding" o "pegado por columnas".
Básicamente toma una columna (o varias) de una matrix o data.frame y las
pega con otra(s).

La función fle.choose() abre la ventana que necesitas.  Dentro de la
funcion puedes usar read.table() o similares para leer los datos que el
usuario necesita incluir en el script.

Espero haber podido ayudar.

Saludos,
Jorge.-


2015-09-22 4:12 GMT+10:00 heber sarmiento via R-help-es <
r-help-es@r-project.org>:

> Alguien me puede ilustrar en relación con la manera en como funciona la
> orden cbind y adicional a esto me gustaría saber existe alguna orden que me
> despliegue una ventana para leer datos de un usuario en un scrip.
> De antemano gracias.
> Heber
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] extracting a value from XML

2015-09-21 Thread boB Rudis
This is how (one way) in both the xml2 package and XML package:

library(xml2)
library(XML)

txt <- '

  
'

doc <- read_xml(txt)
xml_attr(xml_find_all(doc, "//observation"), "value")

doc1 <- xmlParse(txt)
xpathSApply(doc1, "//observation", xmlGetAttr, "value")



On Mon, Sep 21, 2015 at 2:01 PM, Glenn Schultz  wrote:
> 
>  observation_start="2015-09-01" observation_end="2015-09-01" units="lin"
> output_type="1" file_type="xml" order_by="observation_date" sort_order="asc"
> count="1" offset="0" limit="10">
>date="2015-09-01" value="0.46"/>
> 

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] extracting a value from XML

2015-09-21 Thread Glenn Schultz

Hi All,

I have been trying to extract a value from XML.  I have been at it for several 
days off and on and I can't seem to get my head around the problem.   I 
basically understand the examples in R help but I cannot replicate success with 
the below 

I tried to use xmlValue(doc, "//[[value]]") but no success.  All I need is the 
0.46 value.  Any suggestions to help me along are greatly appreciated.

Glenn



  

 
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Extract from data.frame

2015-09-21 Thread Frank Schwidom

better ( if year is an vector of more than 1 element):

df[ df$Year %in% outer(as.numeric( as.character( year)), -1:1, FUN='+'), ]
  Year Amount
2 2002120
3 2003175
4 2004160


On Mon, Sep 21, 2015 at 10:49:34PM +0200, Frank Schwidom wrote:
> 
> year <- df$Year[ which.max( df$Amount)]
> df[ df$Year %in% (as.numeric( as.character( year)) + -1:1), ]
>   Year Amount
> 2 2002120
> 3 2003175
> 4 2004160
> 
> 
> On Mon, Sep 21, 2015 at 04:52:46PM +0200, Nico Gutierrez wrote:
> > Hi All,
> > 
> > I need to do the following operation from data.frame:
> > 
> > df <- data.frame(Year = c("2001", "2002", "2003", "2004", "2005", "2006",
> > "2007"), Amount = c(150, 120, 175, 160, 120, 105, 135))
> > df[which.max(df$Amount),]  #to extract row with max Amount.
> > 
> > Now I need to do 3 years average around the max Amount value (ie:
> > mean(120,175,160))
> > 
> > Thanks!
> > N
> > 
> > [[alternative HTML version deleted]]
> > 
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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 -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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] vector manipulations -- differences

2015-09-21 Thread Dan D
I need an efficient way to build a new n x (n-1)/2 vector from an n-vector x
as:

c(x[-1]-x[1], x[-(1:2)]-x[2], ... , x[-(1:(n-1)] - x[n-1])

x is increasing with x[1] = 0. 

The following works but is not the greatest:
junk<-outer(x, x, '-')
junk[junk>0]

e.g., 
given
x<-c(0, 3, 7, 20)
junk<-outer(x, x, '-')
junk[junk>0] # yields: c(3, 7, 20, 4, 17, 13) as needed, but it has to go
through 
junk
# [,1] [,2] [,3] [,4]
#[1,]0   -3   -7  -20
#[2,]30   -4  -17
#[3,]740  -13
#[4,]   20   17   130

Anyone have a better idea?

-Dan



--
View this message in context: 
http://r.789695.n4.nabble.com/vector-manipulations-differences-tp4712575.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] ERROR - non-conformable arguments

2015-09-21 Thread Alexander Moßbrucker
Hi all,

I am sorry I forgot to attach the excel file and txt files with the test
data I used for this example.

I am almost sure the problem was caused by the way R is reading this data,

Hope to get some help, best, Alex

2015-09-20 14:03 GMT+07:00 Alexander Moßbrucker :

>
> Hi,
>
> I am using adehabitatHS for habitat selection analysis using widesII(),
> when
> running the script I get the error message: Error in as.vector(X) %*%
> t(as.vector(Y)) : non-conformable arguments
>
> Here the script I am using including the data
>
> > #dataset (read from tab deliminated text file)
> >
> > available
>   Riparian Conifer MtShrub1 Aspen RockOutcrop Bitterbrush Windblown
> MtShrub2
> PresBurn
> 1 0.060.13 0.16  0.150.060.17  0.12
>  0.04
> 0.09
>   Clearcut
> 1 0.02
> > used
>  Riparian Conifer MtShrub1 Aspen RockOutcrop Bitterbrush Windblown
> MtShrub2 PresBurn
> Ani10   00 2   0  16 5
> 14   28
> Ani20   21 2   2   510
> 10   35
> Ani30   12 1   0  14 9
> 8   40
> Ani40   13 7   5   3 6
> 9   31
> Ani50   02 2   5  1810
> 6   25
> Ani60   21 4   2   7 6
> 15   19
>  Clearcut
> Ani18
> Ani29
> Ani34
> Ani49
> Ani50
> Ani6   19
> >
> > #analysis
> >
> > widesII(used, available, avknown = TRUE, alpha = 0.05)
> Error in as.vector(X) %*% t(as.vector(Y)) : non-conformable arguments
>
> Note: I am using an example dataset to test out a script I want to use to
> analyse my own dataset, for this I exported the example dataset to excel,
> converted it to tab deliminated text file, then imported it.
>
> All worked well when using the example dataset provided by adehabitatHS,
> thus I suspect that somhow my test dataset is not correctly read in or
> something similar.
>
> I am quite new to R, thus apologize for any shortcomings in reporting etc..
>
> Many thanks, best, Alex
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/ERROR-non-conformable-arguments-tp4712516.html
> Sent from the R help mailing list archive at Nabble.com.
>
>
>
>
RiparianConifer MtShrub1Aspen   RockOutcrop Bitterbrush 
Windblown   MtShrub2PresBurnClearcut
0.060.130.160.150.060.170.120.040.090.02
RiparianConifer MtShrub1Aspen   RockOutcrop 
Bitterbrush Windblown   MtShrub2PresBurnClearcut
Ani10   0   0   2   0   16  5   14  28  
8
Ani20   2   1   2   2   5   10  10  35  
9
Ani30   1   2   1   0   14  9   8   40  
4
Ani40   1   3   7   5   3   6   9   31  
9
Ani50   0   2   2   5   18  10  6   25  0
Ani60   2   1   4   2   7   6   15  19  
19
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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-es] Problemas con rmarkdown

2015-09-21 Thread Conney Marulanda
Buenos días José Antonio, 
Efectivamente, le quité la tilde al fichero y ya funciona perfectamente.
Muchas gracias.
Saludos, 

Conney Paola Marulanda López 
Profesional en Finanzas y Relaciones Internacionales
www.finanzaszone.com 

 
 

Subject: Re: [R-es] Problemas con rmarkdown
To: cpm...@hotmail.com
From: pala...@um.es
Date: Mon, 21 Sep 2015 09:17:22 +0200


  

  
  
Hola:



Siempre que he encontrado un fichero con tildes 

en el nombre he tenido problemas.



En tu caso se cumple la condición.



Espero que la respuesta sea útil,  seguimos



El 19/09/15 a las 22:41, Conney
  Marulanda escribió:



  Buenas noches, 
Escribo este mail porque tengo un problema con rmarkdown, estoy creando un 
informe y me iba bien al generarlo como pdf, de repente me sale el siguiente 
error y no s� como solucionarlo:
pandoc.exe: Error producing PDF from TeX sourceError: pandoc document 
conversion failed with error 43Adem�s: Warning message:comando ejecutado 
'"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS 
Evolución_de_los_Mercados_.utf8.md --to latex --from 
markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures
 --output Evolución_de_los_Mercados_.pdf --template 
"C:\Users\CONNY\Documents\R\win-library\3.2\rmarkdown\rmd\latex\default.tex" 
--highlight-style tango --latex-engine pdflatex --variable 
"geometry:margin=1in"' tiene estatus 43 Ejecuci�n interrumpida
Asimismo, si lo quiero generar como html ser�a para publicarlo en mi sitio web, 
le d� en la opci�n publicar y sali� que requer�a instalar ciertos 
paquetes...pero luego me sali� el siguiente error:
"Error occurred while executing method"
Agradezco su colaboraci�n, pues la idea de mi informe es publicarlo en mi sitio 
web ya sea como pdf o directamente en formato html. 
Muchas gracias!
Conney Paola Marulanda L�pez 
Profesional en Finanzas y Relaciones Internacionales
www.finanzaszone.com 

 
 

  
[[alternative HTML version deleted]]


  

  
  

  ___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es




-- 


José Antonio Palazón Ferrando
Profesor Titular. Departamento de Ecología e Hidrología.
Facultad de Biología. Universidad de Murcia.
Campus Universitario de Espinardo
30100 MURCIA-SPAIN
Telf: +34 868 88 49 80
Fax : +34 868 88 39 63
Email: pala...@um.es
  
[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es