Re: [R] problem understanding grid coordinate systems
Paul Murrell p...@stat.auckland.ac.nz [Wed, Jul 15, 2015 at 11:12:33PM CEST]: ... downViewport(plot_01.panel.1.1.vp) ... This works like a charm. Thank you! Upon reading more of the documentation, I found that current.vpTree() shows all names of active viewports. -- Johannes Hüsing There is something fascinating about science. One gets such wholesale returns of conjecture mailto:johan...@huesing.name from such a trifling investment of fact. http://derwisch.wikidot.com (Mark Twain, Life on the Mississippi) __ 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] Speeding up code?
Hi R-Help! I'm hoping that some of you may give me some tips that could make my code more efficient. More precisely, I would like to make the answer to my stakoverflow http://stackoverflow.com/questions/31137940/randomly-assign-teachers-to-classrooms-imposing-restrictions question more efficient. This is the code: library(dplyr) library(randomNames) library(geosphere) set.seed(7142015)# Define Parameters n.Schools - 20 first.grade-3 last.grade-5 n.Grades -last.grade-first.grade+1 n.Classrooms - 20 # THIS IS WHAT I WANTED TO BE ABLE TO CHANGE n.Teachers - (n.Schools*n.Grades*n.Classrooms)/2 #Two classrooms per teacher # Define Random names function: gen.names - function(n, which.names = both, name.order = last.first){ names - unique(randomNames(n=n, which.names = which.names, name.order = name.order)) need - n - length(names) while(need0){ names - unique(c(randomNames(n=need, which.names = which.names, name.order = name.order), names)) need - n - length(names) } return(names)} # Generate n.Schools names gen.schools - function(n.schools) { School.ID - paste0(gen.names(n = n.schools, which.names = last), ' School') School.long - rnorm(n = n.schools, mean = 21.7672, sd = 0.025) School.lat - rnorm(n = n.schools, mean = 58.8471, sd = 0.025) School.RE - rnorm(n = n.schools, mean = 0, sd = 1) Schools - data.frame(School.ID, School.lat, School.long, School.RE) %% mutate(School.ID = as.character(School.ID)) %% rowwise() %% mutate (School.distance = distHaversine( p1 = c(School.long, School.lat), p2 = c(21.7672, 58.8471), r = 3961 )) return(Schools)} Schools - gen.schools(n.schools = n.Schools) # Generate Grades Grades - c(first.grade:last.grade) # Generate n.Classrooms Classrooms - LETTERS[1:n.Classrooms] # Group schools and grades SchGr - outer(paste0(Schools$School.ID, '-'), paste0(Grades, '-'), FUN=paste)#head(SchGr) # Group SchGr and Classrooms SchGrClss - outer(SchGr, paste0(Classrooms, '-'), FUN=paste)#head(SchGrClss) # These are the combination of School-Grades-Classroom SchGrClssTmp - as.matrix(SchGrClss, ncol=1, nrow=length(SchGrClss) ) SchGrClssEnd - as.data.frame(SchGrClssTmp) # Assign n.Teachers (2 classroom in a given school-grade) Allpairs - as.data.frame(t(combn(SchGrClssTmp, 2))) AllpairsTmp - paste(Allpairs$V1, Allpairs$V2, sep= ) library(stringr) separoPairs - as.data.frame(str_split(string = AllpairsTmp, pattern = -)) separoPairs - as.data.frame(t(separoPairs)) row.names(separoPairs) - NULL separoPairs - separoPairs %% select(-V7) %% #Drops empty column mutate(V1=as.character(V1), V4=as.character(V4), V2=as.numeric(V2), V5=as.numeric(V5)) %% mutate(V4 = trimws(V4, which = both)) separoPairs[120,]$V4#Only the rows with V1=V4 and V2=V5 are valid validPairs - separoPairs %% filter(V1==V4 V2==V5) %% select(V1, V2, V3, V6) # Generate n.Teachers gen.teachers - function(n.teachers){ Teacher.ID - gen.names(n = n.teachers, name.order = last.first) Teacher.exp - runif(n = n.teachers, min = 1, max = 30) Teacher.Other - sample(c(0,1), replace = T, prob = c(0.5, 0.5), size = n.teachers) Teacher.RE - rnorm(n = n.teachers, mean = 0, sd = 1) Teachers - data.frame(Teacher.ID, Teacher.exp, Teacher.Other, Teacher.RE) return(Teachers)} Teachers - gen.teachers(n.teachers = n.Teachers) %% mutate(Teacher.ID = as.character(Teacher.ID)) # Randomly assign n.Teachers teachers to the ValidPairs TmpAssignments - validPairs[sample(1:nrow(validPairs), n.Teachers), ] Assignments - cbind.data.frame(Teachers$Teacher.ID, TmpAssignments) names(Assignments) - c(Teacher.ID, School.ID, Grade, Class_1, Class_2) # Tidy Data library(tidyr) TeacherClassroom - Assignments %% gather(x, Classroom, Class_1,Class_2) %% select(-x) %% mutate(Teacher.ID = as.character(Teacher.ID)) # Merge DF_Classrooms - TeacherClassroom %% full_join(Teachers, by=Teacher.ID) %% full_join(Schools, by=School.ID) rm(list=setdiff(ls(), DF_Classrooms)) # Clean the work space! *I want to end up with the same* 'DF_Classrooms *data frame* but getting there in a more efficient way. In particular, when is use n.Classrooms -4 the code run fast, but *if I increase it to something like 20 it is painfully slow.* Thanks!!! [[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] Speeding up code?
Hi Ignacio, If I am reading your code correctly then the top while loop is essentially seeking to select a random set of names from the original set, then using unique to reduce it down, you then iterate until you have built your quota. Ultimately this results in a very inefficient attempt at sampling without replacement. Why not just sample without replacement rather than loop iteratively and use unique? Or if the set of possible names are short enough why not just randomize it and then pull the first n items off? Best, Collin. On Wed, Jul 15, 2015 at 11:15 PM, Ignacio Martinez ignaci...@gmail.com wrote: Hi R-Help! I'm hoping that some of you may give me some tips that could make my code more efficient. More precisely, I would like to make the answer to my stakoverflow http://stackoverflow.com/questions/31137940/randomly-assign-teachers-to-classrooms-imposing-restrictions question more efficient. This is the code: library(dplyr) library(randomNames) library(geosphere) set.seed(7142015)# Define Parameters n.Schools - 20 first.grade-3 last.grade-5 n.Grades -last.grade-first.grade+1 n.Classrooms - 20 # THIS IS WHAT I WANTED TO BE ABLE TO CHANGE n.Teachers - (n.Schools*n.Grades*n.Classrooms)/2 #Two classrooms per teacher # Define Random names function: gen.names - function(n, which.names = both, name.order = last.first){ names - unique(randomNames(n=n, which.names = which.names, name.order = name.order)) need - n - length(names) while(need0){ names - unique(c(randomNames(n=need, which.names = which.names, name.order = name.order), names)) need - n - length(names) } return(names)} # Generate n.Schools names gen.schools - function(n.schools) { School.ID - paste0(gen.names(n = n.schools, which.names = last), ' School') School.long - rnorm(n = n.schools, mean = 21.7672, sd = 0.025) School.lat - rnorm(n = n.schools, mean = 58.8471, sd = 0.025) School.RE - rnorm(n = n.schools, mean = 0, sd = 1) Schools - data.frame(School.ID, School.lat, School.long, School.RE) %% mutate(School.ID = as.character(School.ID)) %% rowwise() %% mutate (School.distance = distHaversine( p1 = c(School.long, School.lat), p2 = c(21.7672, 58.8471), r = 3961 )) return(Schools)} Schools - gen.schools(n.schools = n.Schools) # Generate Grades Grades - c(first.grade:last.grade) # Generate n.Classrooms Classrooms - LETTERS[1:n.Classrooms] # Group schools and grades SchGr - outer(paste0(Schools$School.ID, '-'), paste0(Grades, '-'), FUN=paste)#head(SchGr) # Group SchGr and Classrooms SchGrClss - outer(SchGr, paste0(Classrooms, '-'), FUN=paste)#head(SchGrClss) # These are the combination of School-Grades-Classroom SchGrClssTmp - as.matrix(SchGrClss, ncol=1, nrow=length(SchGrClss) ) SchGrClssEnd - as.data.frame(SchGrClssTmp) # Assign n.Teachers (2 classroom in a given school-grade) Allpairs - as.data.frame(t(combn(SchGrClssTmp, 2))) AllpairsTmp - paste(Allpairs$V1, Allpairs$V2, sep= ) library(stringr) separoPairs - as.data.frame(str_split(string = AllpairsTmp, pattern = -)) separoPairs - as.data.frame(t(separoPairs)) row.names(separoPairs) - NULL separoPairs - separoPairs %% select(-V7) %% #Drops empty column mutate(V1=as.character(V1), V4=as.character(V4), V2=as.numeric(V2), V5=as.numeric(V5)) %% mutate(V4 = trimws(V4, which = both)) separoPairs[120,]$V4#Only the rows with V1=V4 and V2=V5 are valid validPairs - separoPairs %% filter(V1==V4 V2==V5) %% select(V1, V2, V3, V6) # Generate n.Teachers gen.teachers - function(n.teachers){ Teacher.ID - gen.names(n = n.teachers, name.order = last.first) Teacher.exp - runif(n = n.teachers, min = 1, max = 30) Teacher.Other - sample(c(0,1), replace = T, prob = c(0.5, 0.5), size = n.teachers) Teacher.RE - rnorm(n = n.teachers, mean = 0, sd = 1) Teachers - data.frame(Teacher.ID, Teacher.exp, Teacher.Other, Teacher.RE) return(Teachers)} Teachers - gen.teachers(n.teachers = n.Teachers) %% mutate(Teacher.ID = as.character(Teacher.ID)) # Randomly assign n.Teachers teachers to the ValidPairs TmpAssignments - validPairs[sample(1:nrow(validPairs), n.Teachers), ] Assignments - cbind.data.frame(Teachers$Teacher.ID, TmpAssignments) names(Assignments) - c(Teacher.ID, School.ID, Grade, Class_1, Class_2) # Tidy Data library(tidyr) TeacherClassroom - Assignments %% gather(x, Classroom, Class_1,Class_2) %% select(-x) %% mutate(Teacher.ID = as.character(Teacher.ID)) # Merge DF_Classrooms - TeacherClassroom %% full_join(Teachers, by=Teacher.ID) %% full_join(Schools, by=School.ID) rm(list=setdiff(ls(), DF_Classrooms)) # Clean the work space! *I want to end up with the same* 'DF_Classrooms *data frame* but getting there in a more efficient way. In particular, when is use n.Classrooms -4 the code run fast, but *if I increase it to something like 20 it is painfully slow.* Thanks!!! [[alternative HTML
[R] R-package TDA- RipsDiag issues
Hi there, I was hoping you could help me out with the following: - I am trying to compute the diagram of a Rips filtration built on top of a point cloud. I've gone through several tutorials, and I always get the same answer as the tutorial. Let's say I am inputting an n by d matrix of coordinates, where n is the number of points in d dimensional space, I am able to get a persistence diagram with dimensions 0, 1, and 2-- when I specify maxdimension=2. HOWEVER-- I was wondering; if you input an N BY N matrix of distances of n points, say a 15 by 15 matrix, which is what I am working with, I can't ever see any 2 dimensional features, or 1 dimensional-- the diagram always shows dim0, no matter what matrix I input. The code I have been using is as follows: Diag-ripsDiag(XX, maxscale, dist=arbitrary, printProgress=TRUE), where XX is the name of my distance matrix. Is it not possible to ever extract dim 1 or dim 2 features from this? Even though I specified maxdimension=2. Could someone please help me out, as this is causing great grief. In the tutorial I found online by cran project, they input a distance matrix for a triangle with lengths 1,2, and 4; they specify maxdimension=1, maxscale=5, and input the same as I did above; they only get dim0 features on the diagram... wouldn't we expect the loop of the triangle to be a key feature? If not, either way, would we not expect to see dim1 and dim2 noise features at all? Thanks so much! -- View this message in context: http://r.789695.n4.nabble.com/R-package-TDA-RipsDiag-issues-tp4709925.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] Problem Regarding R Packages installation
Hi Everyone! I am trying to install R Package VariantAnnotation. I entered commands: source(http://bioconductor.org/biocLite.R;) biocLite(VariantAnnotation) But i am getting the following errors, ERROR: configuration failed for package �XML� * removing �/usr/lib64/R/library/XML� * installing *source* package �RCurl� ... ** package �RCurl� successfully unpacked and MD5 sums checked configure: loading site script /usr/share/site/x86_64-unknown-linux-gnu checking for curl-config... no Cannot find curl-config ERROR: configuration failed for package �RCurl� * removing �/usr/lib64/R/library/RCurl� * installing *source* package �Rsamtools� ... ** libs gcc -std=gnu99 -I/usr/lib64/R/include -DNDEBUG -I/usr/local/include -I/usr/lib64/R/library/S4Vectors/include -I/usr/lib64/R/library/IRanges/include -I/usr/lib64/R/library/XVector/include -I/usr/lib64/R/library/Biostrings/include -fopenmp -D_USE_KNETFILE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -DBGZF_CACHE -Dfprintf=_samtools_fprintf -Dexit=_samtools_exit -Dabort=_samtools_abort -I./samtools -I./samtools/bcftools -I./tabix -fpic -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -c Biostrings_stubs.c -o Biostrings_stubs.o gcc -std=gnu99 -I/usr/lib64/R/include -DNDEBUG -I/usr/local/include -I/usr/lib64/R/library/S4Vectors/include -I/usr/lib64/R/library/IRanges/include -I/usr/lib64/R/library/XVector/include -I/usr/lib64/R/library/Biostrings/include -fopenmp -D_USE_KNETFILE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -DBGZF_CACHE -Dfprintf=_samtools_fprintf -Dexit=_samtools_exit -Dabort=_samtools_abort -I./samtools -I./samtools/bcftools -I./tabix -fpic -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -c IRanges_stubs.c -o IRanges_stubs.o g++ -I/usr/lib64/R/include -DNDEBUG -I/usr/local/include -I/usr/lib64/R/library/S4Vectors/include -I/usr/lib64/R/library/IRanges/include -I/usr/lib64/R/library/XVector/include -I/usr/lib64/R/library/Biostrings/include -fpic -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -c PileupBuffer.cpp -o PileupBuffer.o /bin/sh: g++: command not found /usr/lib64/R/etc/Makeconf:143: recipe for target 'PileupBuffer.o' failed make: *** [PileupBuffer.o] Error 127 ERROR: compilation failed for package �Rsamtools� * removing �/usr/lib64/R/library/Rsamtools� * installing *source* package �futile.logger� ... ** package �futile.logger� successfully unpacked and MD5 sums checked ** R ** preparing package for lazy loading ** help *** installing help indices ** building package indices ** testing if installed package can be loaded * DONE (futile.logger) ERROR: dependencies �XML�, �RCurl� are not available for package �biomaRt� * removing �/usr/lib64/R/library/biomaRt� * installing *source* package �BiocParallel� ... ** R ** inst ** preparing package for lazy loading ** help *** installing help indices ** building package indices ** installing vignettes ** testing if installed package can be loaded * DONE (BiocParallel) ERROR: dependency �Rsamtools� is not available for package �GenomicAlignments� * removing �/usr/lib64/R/library/GenomicAlignments� ERROR: dependencies �XML�, �RCurl�, �Rsamtools�, �GenomicAlignments� are not available for package �rtracklayer� * removing �/usr/lib64/R/library/rtracklayer� ERROR: dependencies �rtracklayer�, �Rsamtools� are not available for package �BSgenome� * removing �/usr/lib64/R/library/BSgenome� ERROR: dependencies �rtracklayer�, �biomaRt�, �RCurl� are not available for package �GenomicFeatures� * removing �/usr/lib64/R/library/GenomicFeatures� ERROR: dependencies �Rsamtools�, �BSgenome�, �rtracklayer�, �GenomicFeatures� are not available for package �VariantAnnotation� * removing �/usr/lib64/R/library/VariantAnnotation� The downloaded source packages are in �/tmp/RtmpvpoYjO/downloaded_packages� Updating HTML index of packages in '.Library' Making 'packages.html' ... done Warning messages: 1: In install.packages(pkgs = doing, lib = lib, ...) : installation of package �XML� had non-zero exit status 2: In install.packages(pkgs = doing, lib = lib, ...) : installation of package �RCurl� had non-zero exit status 3: In install.packages(pkgs = doing, lib = lib, ...) : installation of package �Rsamtools� had non-zero exit status 4: In install.packages(pkgs = doing, lib = lib, ...) : installation of package �biomaRt� had non-zero exit status 5: In install.packages(pkgs = doing, lib = lib, ...) : installation of package �GenomicAlignments� had non-zero exit status 6: In install.packages(pkgs = doing, lib = lib, ...) : installation of package �rtracklayer� had non-zero exit status 7: In install.packages(pkgs = doing, lib = lib, ...) : installation of package �BSgenome� had non-zero exit status 8: In
Re: [R] Problem in installing simba package
Wait? Try a different server? Verify your internet settings? --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On July 14, 2015 11:22:08 PM PDT, sreenath sreenath.ra...@macfast.ac.in wrote: When installing simba package following error showing install.packages(simba) Installing package into ‘/home/cbl/R/x86_64-redhat-linux-gnu-library/3.1’ (as ‘lib’ is unspecified) --- Please select a CRAN mirror for use in this session --- also installing the dependency ‘vegan’ trying URL 'http://ftp.iitm.ac.in/cran/src/contrib/vegan_2.3-0.tar.gz' Error in download.file(url, destfile, method, mode = wb, ...) : cannot open URL 'http://ftp.iitm.ac.in/cran/src/contrib/vegan_2.3-0.tar.gz' In addition: Warning message: In download.file(url, destfile, method, mode = wb, ...) : cannot open: HTTP status was '0 (null)' Warning in download.packages(pkgs, destdir = tmpd, available = available, : download of package ‘vegan’ failed trying URL 'http://ftp.iitm.ac.in/cran/src/contrib/simba_0.3-5.tar.gz' Error in download.file(url, destfile, method, mode = wb, ...) : cannot open URL 'http://ftp.iitm.ac.in/cran/src/contrib/simba_0.3-5.tar.gz' In addition: Warning message: In download.file(url, destfile, method, mode = wb, ...) : cannot open: HTTP status was '0 (null)' Warning in download.packages(pkgs, destdir = tmpd, available = available, : download of package ‘simba’ failed -- View this message in context: http://r.789695.n4.nabble.com/Problem-in-installing-simba-package-tp4709882.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.
[R] Problem in installing simba package
When installing simba package following error showing install.packages(simba) Installing package into ‘/home/cbl/R/x86_64-redhat-linux-gnu-library/3.1’ (as ‘lib’ is unspecified) --- Please select a CRAN mirror for use in this session --- also installing the dependency ‘vegan’ trying URL 'http://ftp.iitm.ac.in/cran/src/contrib/vegan_2.3-0.tar.gz' Error in download.file(url, destfile, method, mode = wb, ...) : cannot open URL 'http://ftp.iitm.ac.in/cran/src/contrib/vegan_2.3-0.tar.gz' In addition: Warning message: In download.file(url, destfile, method, mode = wb, ...) : cannot open: HTTP status was '0 (null)' Warning in download.packages(pkgs, destdir = tmpd, available = available, : download of package ‘vegan’ failed trying URL 'http://ftp.iitm.ac.in/cran/src/contrib/simba_0.3-5.tar.gz' Error in download.file(url, destfile, method, mode = wb, ...) : cannot open URL 'http://ftp.iitm.ac.in/cran/src/contrib/simba_0.3-5.tar.gz' In addition: Warning message: In download.file(url, destfile, method, mode = wb, ...) : cannot open: HTTP status was '0 (null)' Warning in download.packages(pkgs, destdir = tmpd, available = available, : download of package ‘simba’ failed -- View this message in context: http://r.789695.n4.nabble.com/Problem-in-installing-simba-package-tp4709882.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-es] Conservar el nombre de la variable entre varias funciones: ejemplos de resultados
Hola: Ayer me olvidé de señalar que el problema mayor que tengo es que al ejecutar la función UNI_VDQVIQ, en los resultados aparece el nombre del argumento que le paso a la función (get(XVDT) y XVARNOM ), en lugar del nombre de la variable de la tabla de datos: library(MASS) data(birthwt, package=MASS) birthwt$low - factor(birthwt$low) birthwt$race - factor(birthwt$race) DESUNI(XDADES=birthwt, XVD=low) [borrado] Cell Contents |-| | Count | | Expected Values | | Row Percent | |-| Total Observations in Table: 189 | XVARNOM get(XVDT) |0 |1 | Row Total | -|---|---|---| 0 | 130 |0 | 130 | |89,42 |40,58 | | | 100,00% | 0,00% |68,78% | -|---|---|---| 1 |0 | 59 | 59 | |40,58 |18,42 | | | 0,00% | 100,00% |31,22% | -|---|---|---| Column Total | 130 | 59 | 189 | -|---|---|---| Es lo que pregunté inicialmente a la lista con el ejemplo reproducible: A - function (XVD, XVI, XDATOS) { attach(XDATOS) B(XVD, XVI) detach(XDATOS) } B - function (XVD, XVI) { TBL = xtabs(~get(XVD) + get(XVI)) print(TBL) print(summary(TBL)) } DATOS - data.frame(SE=c(M, H, M, M, H), EDAD=c(50, 60, 20, 18, 30), GRP=c(B, B, A, A, B)) A(GRP, SE, DATOS) La tabla que imprime és: get(XVI) get(XVD) H M A 0 2 B 2 1 Gracias y saludos! Beginning of forwarded message 14.07.2015, 22:49, Griera gri...@yandex.com: Hola Carlos: Te adjunto un ejemplo de aplicación: las funciones (he borrado los path de las funciones y las ordenes source() que las carga ) y un ejemplo para ejecutarlas para las opciones que tengo implementadas con la tabla de datos birthwt del paqueteMASS: - Descriptiva de todas las variables de una tabla. - Análisis univariado de todas las variables de una tabla cruzadas con una variable dependiente cualitativa. =Inicio funciones ##-- ## DESUNI ##-- DESUNI = function(XDADES, XDROP=NULL, XVD=NULL, XSPV=NULL # Si és una anàlisi de SPV # Pot tenir el valor TRUE ) { options(digits = 3, OutDec=,, scipen=999) ## No existeix VD: descriptiva if(is.null(XVD)) # No existeix VD: descriptiva { cat(\n*** Descriptiva (no existeix variable dependent)\n) DES(XDADES=XDADES, XDROP=XDROP, XCAMIF=XCAMIF) } ## Existeis VD: anàlisi univariat else # Existeis VD: anàlisi univariat { UNI(XDADES=XDADES, XDROP=XDROP, XVD=XVD, XSPV=XSPV, XCAMIF=XCAMIF) } } ##-- ## DES: Descriptiva de todas las variables ##-- DES = function(XDADES, XDROP=NULL, XCAMIF) { ifelse(is.null(XDROP), DADES_S - XDADES, DADES_S - XDADES[, setdiff(names(XDADES), XDROP) ]) # setdiff Selecciona les variables de XDADES que són diferents de XDROP attach(DADES_S, warn.conflicts = F) XVARLLI=names(DADES_S) for (XVARNOM in names(DADES_S)) { if(is.numeric(get(XVARNOM))) { DES_QUANTI (XVARNOM) } else if(is.factor(get(XVARNOM))) { DES_QUALI (XVARNOM) } else { cat(La variable , XVARNOM, no és de cap dels tipus coneguts, \n) } } # Fi de la funció detach(DADES_S) } ##-- ## DES_QUANTI: Descriptiva variables factor ##-- DES_QUANTI - function(X) { OP - par(no.readonly = TRUE); # save old parameters par(mfrow=c(1,3)) hist(get(X), main=c(Histograma de, X), xlab=X);rug(get(X)) boxplot(get(X), main=c(Diagrama de caixa de, X), ylab=X);rug(get(X),side=2) qqnorm(get(X), main=c(Diagrama Q-Q de, X));qqline(get(X)) cat(\n) par(OP) ESTA_1-data.frame(Variable = X, N_total = length(get(X)), N_valids = sum(!is.na(get(X))), N_desconeguts = sum(is.na(get(X))) ) ESTA_2-data.frame(Variable = X, N = sum(!is.na(get(X))), Mitjana = if (mean(get(X) 10)) {round(mean(get(X), na.rm = TRUE), 2)} else {round(mean(get(X), na.rm = TRUE), 3)},
Re: [R-es] Conservar el nombre de la variable entre varias funciones: ejemplos de resultados
Hola Carlos:[Entre líneas] 15.07.2015, 00:18, "Carlos Ortega" c...@qualityexcellence.es:Hola,Gracias por el código. Lo he ejecutado y he visto los resultados.Salvo la parte de los test como te dije, todo lo demás creo que se puede hacer más automático.Probaré a hacer alguna prueba de lo que te comento utilizando el conjunto de MASS.Sobre la duda de los nombres, si le pasas el data.frame tal cual, te debiera de conservar los nombres.Si no es así, pásale como argumento adicional a las funciones los nombres de las columnas/variables... Había escrito un nuevo mail aclaratorio sin haber leído este. Olvida el último mail y pruebo estas dos cosas que dices. Muchas gracias y saludos Saludos,Carlos. El 14 de julio de 2015, 22:49, Griera gri...@yandex.com escribió:Hola Carlos: Te adjunto un ejemplo de aplicación: las funciones (he borrado los path de las funciones y las ordenes "source()" que las carga ) y un ejemplo para ejecutarlas para las opciones que tengo implementadas con la tabla de datos birthwt del paquete"MASS": - Descriptiva de todas las variables de una tabla. - Análisis univariado de todas las variables de una tabla cruzadas con una variable dependiente cualitativa. =Inicio funciones ##-- ## DESUNI ##-- DESUNI = function(XDADES, XDROP=NULL, XVD=NULL, XSPV=NULL # Si és una anàlisi de SPV # Pot tenir el valor TRUE ) { options(digits = 3, OutDec=",", scipen=999) ## No existeix VD: descriptiva if(is.null(XVD)) # No existeix VD: descriptiva { cat("\n*** Descriptiva (no existeix variable dependent)\n") DES(XDADES=XDADES, XDROP=XDROP, XCAMIF=XCAMIF) } ## Existeis VD: anàlisi univariat else # Existeis VD: anàlisi univariat { UNI(XDADES=XDADES, XDROP=XDROP, XVD=XVD, XSPV=XSPV, XCAMIF=XCAMIF) } } ##-- ## DES: Descriptiva de todas las variables ##-- DES = function(XDADES, XDROP=NULL, XCAMIF) { ifelse(is.null(XDROP), DADES_S - XDADES, DADES_S - XDADES[, setdiff(names(XDADES), XDROP) ]) # setdiff Selecciona les variables de XDADES que són diferents de XDROP attach(DADES_S, warn.conflicts = F) XVARLLI=names(DADES_S) for (XVARNOM in names(DADES_S)) { if(is.numeric(get(XVARNOM))) { DES_QUANTI (XVARNOM) } else if(is.factor(get(XVARNOM))) { DES_QUALI (XVARNOM) } else { cat("La variable ", XVARNOM, "no és de cap dels tipus coneguts", "\n") } } # Fi de la funció detach(DADES_S) } ##-- ## DES_QUANTI: Descriptiva variables factor ##-- DES_QUANTI - function(X) { OP - par(no.readonly = TRUE); # save old parameters par(mfrow=c(1,3)) hist(get(X), main=c("Histograma de", X), xlab=X);rug(get(X)) boxplot(get(X), main=c("Diagrama de caixa de", X), ylab=X);rug(get(X),side=2) qqnorm(get(X), main=c("Diagrama Q-Q de", X));qqline(get(X)) cat("\n") par(OP) ESTA_1-data.frame(Variable = X, N_total = length(get(X)), N_valids = sum(!is.na(get(X))), N_desconeguts = sum(is.na(get(X))) ) ESTA_2-data.frame(Variable = X, N = sum(!is.na(get(X))), Mitjana = if (mean(get(X) 10)) {round(mean(get(X), na.rm = TRUE), 2)} else {round(mean(get(X), na.rm = TRUE), 3)}, Err_tipic = if (sd (get(X) 10)) {round(sd (get(X), na.rm = TRUE), 2)} else {round(sd (get(X), na.rm = TRUE), 3)}, Min = min(get(X), na.rm = TRUE), Perc_25 = quantile(get(X),.25), Mediana = median(get(X), na.rm = TRUE), Perc_75 = quantile(get(X),.75), Max = max(get(X), na.rm = TRUE), Interval = max(get(X), na.rm = TRUE) - min(get(X), na.rm = TRUE) ) cat("", "\n") cat("Valors valids i desconeguts", "\n") print(ESTA_1, row.names = FALSE) cat("", "\n") cat("Estadistics", "\n") print(ESTA_2, row.names = FALSE) cat("", "\n") return(summary(get(X))) } ##-- ## DES_QUALI: Descriptiva variables factor ##-- DES_QUALI - function(X) { cat("Var factor: ",X,"\n")
[R] multi core procesing
Hello, I am using a 8 core processor system. Is there a way to run different R scripts on different cores instead of all scripts running on the same core? If I open a new RStudio session for each script, can I somehow assign each Rstudio session to a particular core processor so as to make the process efficient? I have looked at the doParallel package and from my understanding including the package enables one script to be run using multiple cores but what I am looking for is being able to run different scripts on different cores. Thanks, Vyshnnavi [[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] rgl 3d surface
On 15/07/2015 7:16 AM, AURORA GONZALEZ VIDAL wrote: Hello. I am trying to plot a 3d surface given its equation. The R code is written in blue. So, let's say that I have the points x,y,z and I plot them. Also, I compute its regression surface doing polynomical regression (fit) library('rgl') x - c(-32.09652, -28.79491, -25.48977, -23.18746,-20.88934, -18.58220, -17.27919) y - c(-32.096, -28.794, -25.489, -23.187,-20.889, -18.582, -17.279) z - c(12.16344, 28.84962, 22.36605, 20.13733, 79.50248, 65.46150,44.52274) plot3d(x,y,z, type=s, col=red, size=1) fit - lm(z ~ poly(x,2) + poly(y,2)) In this way, I obtain the coefficients of the surface coef(fit) (Intercept) poly(x, 2)1 poly(x, 2)2 3.900045e+01 1.763363e+06 6.683531e+05 poly(y, 2)1 poly(y, 2)2 -1.763303e+06 -6.683944e+05 So I want to repressent the surface 3.900045e+01 +1.763363e+06*x + 6.683531e+05*x*x -1.763303e+06*y-6.683944e+05*y*y How could I do it? Any idea?? Thank you very much! You need to write a function f of x and y that produces the fitted values. I haven't checked, but I'd assume it needs to take vector inputs and produce a vector of responses. Then persp3d(f) will draw the surface. See ?persp3d.function for details on setting the x and y ranges, etc. 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.
[R] rgl 3d surface
Hello. I am trying to plot a 3d surface given its equation. The R code is written in blue. So, let's say that I have the points x,y,z and I plot them. Also, I compute its regression surface doing polynomical regression (fit) library('rgl') x - c(-32.09652, -28.79491, -25.48977, -23.18746,-20.88934, -18.58220, -17.27919) y - c(-32.096, -28.794, -25.489, -23.187,-20.889, -18.582, -17.279) z - c(12.16344, 28.84962, 22.36605, 20.13733, 79.50248, 65.46150,44.52274) plot3d(x,y,z, type=s, col=red, size=1) fit - lm(z ~ poly(x,2) + poly(y,2)) In this way, I obtain the coefficients of the surface coef(fit) (Intercept) poly(x, 2)1 poly(x, 2)2 3.900045e+01 1.763363e+06 6.683531e+05 poly(y, 2)1 poly(y, 2)2 -1.763303e+06 -6.683944e+05 So I want to repressent the surface 3.900045e+01 +1.763363e+06*x + 6.683531e+05*x*x -1.763303e+06*y-6.683944e+05*y*y How could I do it? Any idea?? Thank you very much! -- Aurora González Vidal Sección Apoyo Estadístico. Servicio de Apoyo a la Investigación (SAI). Vicerrectorado de Investigación. Universidad de Murcia Edif. SACE . Campus de Espinardo. 30100 Murcia @. aurora.gonzal...@um.es T. 868 88 7315 F. 868 88 7302 www.um.es/sai www.um.es/ae [[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] Jaccard index
On 15-07-2015, at 09:35, sreenath sreenath.ra...@macfast.ac.in wrote: How can i find jaccard index of two groups,which package is to be used? please help library(sos) findFn(“jaccard”) gives many links. Berend __ 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] convert character vector to decimal for numeric testing
Dear all, I have a vector that comes from some calculations I am making and this vectors turns out to be in character format rather than numerical. I can convert it in numerical format but then the calculations are not correct, as you can see in the following example. I was also expecting that rounding a number such as 5.43 to a three digits one would return 5.430 but that did not happen. Any tips on how to apply the calculation correctly? Thank you best regards luigi vec.ori - c(5.43, 6.63, -1.18593063116494e+36, 6.2, 5.61, 4.96842801255869e+30, 5.59, -Inf, Inf, 5.49, 18.35, -3.11, 6.07, NA) vec.num - as.numeric(vec.ori) vec.num 0 [1] FALSE FALSE TRUE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSENA vec.num 0 [1] TRUE TRUE FALSE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUENA for(i in 1:length(vec.num)) { cat(value at beginning: , vec.num[i], \n, sep=) if(vec.num[i] 0) { vec.num[i] - LO } else if(vec.num[i] 45) { vec.num[i] - HI } else if (is.na(vec.num[i])== TRUE) { vec.num[i] - na } else if (is.infinite(vec.num[i]) == TRUE) { vec.num[i] - INF } else { vec.num[i] - round(vec.num[i], 3) } cat(value at end: , vec.num[i], \n, sep=) } value at beginning: 5.43 value at end: 5.43 value at beginning: 6.63 value at end: 6.63 value at beginning: -1185930631164940020264024442864400022 value at end: LO # REM: error! value at beginning: 6.2 value at end: HI # REM: error! value at beginning: 5.61 value at end: HI # REM: error! value at beginning: 4968428012558689723622822000404 value at end: HI value at beginning: 5.59 value at end: HI # REM: error! value at beginning: -Inf value at end: LO # REM: error! value at beginning: Inf value at end: HI # REM: error! value at beginning: 5.49 value at end: HI # REM: error! value at beginning: 18.35 Error in round(vec.num[i], 3) : non-numeric argument to mathematical function # REM: cycle crashed __ 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] ‘ips’ had non-zero exit status
dear all, sorry for the naive question, I'm trying to install (in R version 3.2.1 (2015-06-18)) the ips package for phylogenetic analysis. However I get the following message: install.packages(ips,dependencies = T) Installing package into ‘/home/giovanni/R/x86_64-pc-linux-gnu-library/3.2’ (as ‘lib’ is unspecified) also installing the dependency ‘XML’ provo con l'URL 'https://cran.rstudio.com/src/contrib/XML_3.98-1.3.tar.gz' Content type 'application/x-gzip' length 1607725 bytes (1.5 MB) == downloaded 1.5 MB provo con l'URL 'https://cran.rstudio.com/src/contrib/ips_0.0-7.tar.gz' Content type 'application/x-gzip' length 62904 bytes (61 KB) == downloaded 61 KB * installing *source* package ‘XML’ ... ** package ‘XML’ successfully unpacked and MD5 sums checked checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking how to run the C preprocessor... gcc -E checking for sed... /bin/sed checking for pkg-config... /usr/bin/pkg-config checking for xml2-config... no Cannot find xml2-config ERROR: configuration failed for package ‘XML’ * removing ‘/home/giovanni/R/x86_64-pc-linux-gnu-library/3.2/XML’ Warning in install.packages : installation of package ‘XML’ had non-zero exit status ERROR: dependency ‘XML’ is not available for package ‘ips’ * removing ‘/home/giovanni/R/x86_64-pc-linux-gnu-library/3.2/ips’ Warning in install.packages : installation of package ‘ips’ had non-zero exit status The downloaded source packages are in ‘/tmp/RtmpbTmMtc/downloaded_packages’ can anybody help me? best regards Giovanni __ 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] cronbachs alpha and missing values
i want to calculate cronbachs alpha for my df. my df has some missing values so that there are only 23 out of 56 complete cases. if i run alpha on only the complete cases, i get a value of .79 and if i run it on the whole df, I get .82. My question is: what does alpha do with those missing values, if i include the incomplete cases? are they imputed in some way? -- View this message in context: http://r.789695.n4.nabble.com/cronbachs-alpha-and-missing-values-tp4709885.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] Jaccard index
How can i find jaccard index of two groups,which package is to be used? please help -- View this message in context: http://r.789695.n4.nabble.com/Jaccard-index-tp4709883.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] convert character vector to decimal for numeric testing
It does round to 3 digits, but since the last one is a zero, is only prints 5.43 and not 5.430. Why do you want the last zero? Is this going into a report or something? You can always use sprintf: x -round(5.43, 3) x [1] 5.43 sprintf(%.3f, x) [1] 5.430 BTW you are converting your numeric vector back to character with statements like: if(vec.num[i] 0) { vec.num[i] - LO What is the problem you are trying to solve? Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. On Wed, Jul 15, 2015 at 6:26 AM, Luigi Marongiu marongiu.lu...@gmail.com wrote: Dear all, I have a vector that comes from some calculations I am making and this vectors turns out to be in character format rather than numerical. I can convert it in numerical format but then the calculations are not correct, as you can see in the following example. I was also expecting that rounding a number such as 5.43 to a three digits one would return 5.430 but that did not happen. Any tips on how to apply the calculation correctly? Thank you best regards luigi vec.ori - c(5.43, 6.63, -1.18593063116494e+36, 6.2, 5.61, 4.96842801255869e+30, 5.59, -Inf, Inf, 5.49, 18.35, -3.11, 6.07, NA) vec.num - as.numeric(vec.ori) vec.num 0 [1] FALSE FALSE TRUE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSENA vec.num 0 [1] TRUE TRUE FALSE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUENA for(i in 1:length(vec.num)) { cat(value at beginning: , vec.num[i], \n, sep=) if(vec.num[i] 0) { vec.num[i] - LO } else if(vec.num[i] 45) { vec.num[i] - HI } else if (is.na(vec.num[i])== TRUE) { vec.num[i] - na } else if (is.infinite(vec.num[i]) == TRUE) { vec.num[i] - INF } else { vec.num[i] - round(vec.num[i], 3) } cat(value at end: , vec.num[i], \n, sep=) } value at beginning: 5.43 value at end: 5.43 value at beginning: 6.63 value at end: 6.63 value at beginning: -1185930631164940020264024442864400022 value at end: LO # REM: error! value at beginning: 6.2 value at end: HI # REM: error! value at beginning: 5.61 value at end: HI # REM: error! value at beginning: 4968428012558689723622822000404 value at end: HI value at beginning: 5.59 value at end: HI # REM: error! value at beginning: -Inf value at end: LO # REM: error! value at beginning: Inf value at end: HI # REM: error! value at beginning: 5.49 value at end: HI # REM: error! value at beginning: 18.35 Error in round(vec.num[i], 3) : non-numeric argument to mathematical function # REM: cycle crashed __ 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-es] Conservar el nombre de la variable entre varias funciones: ejemplos de resultados: solucionado
Hola: On Wed, 15 Jul 2015 00:18:32 +0200 Carlos Ortega c...@qualityexcellence.es wrote: [borro] Sobre la duda de los nombres, si le pasas el data.frame tal cual, te debiera de conservar los nombres. Tienes razón. Ahora le paso el nombre del data.frame, y ya muestra el nombre de la variable analizada. Muchas gracias por la sugerencia. Saludos! Si no es así, pásale como argumento adicional a las funciones los nombres de las columnas/variables... Saludos, Carlos. El 14 de julio de 2015, 22:49, Griera gri...@yandex.com escribió: Hola Carlos: Te adjunto un ejemplo de aplicación: las funciones (he borrado los path de las funciones y las ordenes source() que las carga ) y un ejemplo para ejecutarlas para las opciones que tengo implementadas con la tabla de datos birthwt del paqueteMASS: - Descriptiva de todas las variables de una tabla. - Análisis univariado de todas las variables de una tabla cruzadas con una variable dependiente cualitativa. =Inicio funciones ##-- ## DESUNI ##-- DESUNI = function(XDADES, XDROP=NULL, XVD=NULL, XSPV=NULL # Si és una anàlisi de SPV # Pot tenir el valor TRUE ) { options(digits = 3, OutDec=,, scipen=999) ## No existeix VD: descriptiva if(is.null(XVD)) # No existeix VD: descriptiva { cat(\n*** Descriptiva (no existeix variable dependent)\n) DES(XDADES=XDADES, XDROP=XDROP, XCAMIF=XCAMIF) } ## Existeis VD: anàlisi univariat else # Existeis VD: anàlisi univariat { UNI(XDADES=XDADES, XDROP=XDROP, XVD=XVD, XSPV=XSPV, XCAMIF=XCAMIF) } } ##-- ## DES: Descriptiva de todas las variables ##-- DES = function(XDADES, XDROP=NULL, XCAMIF) { ifelse(is.null(XDROP), DADES_S - XDADES, DADES_S - XDADES[, setdiff(names(XDADES), XDROP) ]) # setdiff Selecciona les variables de XDADES que són diferents de XDROP attach(DADES_S, warn.conflicts = F) XVARLLI=names(DADES_S) for (XVARNOM in names(DADES_S)) { if(is.numeric(get(XVARNOM))) { DES_QUANTI (XVARNOM) } else if(is.factor(get(XVARNOM))) { DES_QUALI (XVARNOM) } else { cat(La variable , XVARNOM, no és de cap dels tipus coneguts, \n) } } # Fi de la funció detach(DADES_S) } ##-- ## DES_QUANTI: Descriptiva variables factor ##-- DES_QUANTI - function(X) { OP - par(no.readonly = TRUE); # save old parameters par(mfrow=c(1,3)) hist(get(X),main=c(Histograma de, X), xlab=X);rug(get(X)) boxplot(get(X), main=c(Diagrama de caixa de, X), ylab=X);rug(get(X),side=2) qqnorm(get(X), main=c(Diagrama Q-Q de, X));qqline(get(X)) cat(\n) par(OP) ESTA_1-data.frame(Variable = X, N_total = length(get(X)), N_valids = sum(!is.na(get(X))), N_desconeguts = sum(is.na(get(X))) ) ESTA_2-data.frame(Variable = X, N = sum(!is.na(get(X))), Mitjana = if (mean(get(X) 10)) {round(mean(get(X), na.rm = TRUE), 2)} else {round(mean(get(X), na.rm = TRUE), 3)}, Err_tipic = if (sd (get(X) 10)) {round(sd (get(X), na.rm = TRUE), 2)} else {round(sd (get(X), na.rm = TRUE), 3)}, Min = min(get(X), na.rm = TRUE), Perc_25 = quantile(get(X),.25), Mediana = median(get(X), na.rm = TRUE), Perc_75 = quantile(get(X),.75), Max = max(get(X), na.rm = TRUE), Interval = max(get(X), na.rm = TRUE) - min(get(X), na.rm = TRUE) ) cat(, \n) cat(Valors valids i desconeguts, \n) print(ESTA_1, row.names = FALSE) cat(, \n) cat(Estadistics, \n) print(ESTA_2, row.names = FALSE) cat(, \n) return(summary(get(X))) } ##-- ## DES_QUALI: Descriptiva variables factor ##-- DES_QUALI - function(X) { cat(Var factor: ,X,\n) XOUT -
Re: [R] multi core procesing
On 15/07/2015 2:33 PM, Vyshnnavi Parthasarathy wrote: Hello, I am using a 8 core processor system. Is there a way to run different R scripts on different cores instead of all scripts running on the same core? If I open a new RStudio session for each script, can I somehow assign each Rstudio session to a particular core processor so as to make the process efficient? I have looked at the doParallel package and from my understanding including the package enables one script to be run using multiple cores but what I am looking for is being able to run different scripts on different cores. This is a question about your OS, isn't it? Does your OS allow you to run multiple processes on different cores? Or maybe this is a question about RStudio. Does it allow multiple instances to run on the same computer, so your OS can allocate them to different cores? If you run your scripts in R (not under RStudio) it's certainly possible to have multiple R processes running at the same time. Just do it. 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] Assigning fate percent to plots
On Jul 15, 2015, at 12:12 PM, Robin Gropp wrote: Hi. I have a big data set which could be represented something like this: *plot fate* 1 S 2 M 3 S 3 S 3 M 4 S 4 S 5 S 5 M 5 S 5 S 6 M 7 M where plot is a location, and fate is either survivorship or mortality ( a plant lives or dies.) Thus in plot 5 there are 4 plants. 3 of them survive, 1 dies. I want to figure out a way to make R calculate the fraction of individuals that survive in each plot for all of these. It is proving very challenging. Example: Plot 5 would return a survivorship value of 3/4 or 75%/ Plot 3 would return a survivorship value of 2/3 or 66% Divide the survivors by the number at risk. tdat - with( dat, table(plot, fate) ) # a matrix-like object tdat[,'S']/rowSums(tdat) 1 2 3 4 5 6 1.000 0.000 0.667 1.000 0.750 0.000 7 0.000 Any help would be much appreciated. Thank you [[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. David Winsemius Alameda, CA, USA __ 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 - Group Subsector Weighted Average
Hi, I am new to this forum and R in general. I have a database that I would like to analyze. My ultimate goal is to show the weighted average of each security in its sector to its predecessor Sector level. I want it to be as granular as possible. For example: Weighted average of Industrials (Sector Level 2) in Corporate (Sector Level 1). Weighted average of Automotive (Sector Level 3) in Industrials (Sector Level 2). Weighted average of each security in Auto Parts Equipment (Sector Level 4) in Automotive (Sector Level 3) and so on. I'd like to weight the securities and sector levels by the calculated ytw, ytm, dtw, ed, oas, and avglife. Preferably in a table format, sorted by sector level and composite ratings. I know it is possible, I just don't know how to tackle the code, what packages, if any, to add etc. Like I mentioned before, I am just now getting my feet wet with R and am enjoying it so far. It's a powerful tool and I'd like to know how to put its power to use. Any help is greatly appreciated, I am very open to suggestions and ideas. Here is the dropbox link to my database: Dropbox Database Link https://www.dropbox.com/s/yr8olrj0v5mp4nu/dmw_dataset.csv?dl=0 My code so far: - #Read file into R mkt - read.csv #Add librarys to work with data library(plyr) library(lubridate) #Split data frames by variables divisor - ddply(mkt,.(Sector.Level.2,Sector.Level.3,Sector.Level.4,year,Composite.Rating),summarize,amt=sum(Face.Value)) divisor$id - paste(divisor$Sector.Level.4,divisor$year,sep=) subind.year - divisor[,c(id,amt)] #Format output format of maturity and year mkt$Maturity - mdy(as.character(mkt$Maturity)) mkt$year - year(mkt$Maturity) #Format composite rating mkt$Composite.Rating - gsub(([A-Z]+)([0-9]+),\\1,mkt$Composite.Rating) #Test composite rating formating test - c(A1, AA2, BBB3) gsub(([A-Z]+)([0-9]+),\\1,test) #Show output format #head(mkt$Composite.Rating,50) #Split data frames by variables table - ddply(mkt,.(Sector.Level.2,Sector.Level.3,Sector.Level.4,year,Composite.Rating),summarize, m.ytw = round(mean(Yield.to.Worst),digits=2), m.ytm = round(mean(Effective.Yield),digits=2), m.dtw = round(mean(Duration.To.Worst),digits=2), m.ed = round(mean(Effective.Duration),digits=2), m.oas = round(mean(OAS.vs.Govt),digits=2), m.avglife = round(mean(year),digits=2), num = length(Sector.Level.3), amt=sum(Face.Value)) #Show output format head(table,100) - This post is also cross-listed in Talk Stats. Link to that post: Talk Stats Post http://www.talkstats.com/showthread.php/61584-Weighted-Average -- View this message in context: http://r.789695.n4.nabble.com/Help-Group-Subsector-Weighted-Average-tp4709901.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] Seeing Build Commands when running R CMD INSTALL pkg
Hello, I was trying to build a package from source (specifically the 'rzmq' package) on the following platform: Mac OS X 10.8.5 (Mountain Lion) R: version 3.2.1 rzmq: version 0.7.7 (obtained from the github repo for this package) The reason I want to build this from source is that there is no binary available from CRAN for this version of rzmq for Mountain Lion (it is only available for Maverick). I'm using R CMD INSTALL ... to build the package. However, I get some errors. For now, I would just like to be able to see the exact raw commands being sent to the compiler (gcc in my case), because I think the commands aren't being set up correctly. Is there a way to do this? Thank you! [[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] Assigning fate percent to plots
Hi. I have a big data set which could be represented something like this: *plot fate* 1 S 2 M 3 S 3 S 3 M 4 S 4 S 5 S 5 M 5 S 5 S 6 M 7 M where plot is a location, and fate is either survivorship or mortality ( a plant lives or dies.) Thus in plot 5 there are 4 plants. 3 of them survive, 1 dies. I want to figure out a way to make R calculate the fraction of individuals that survive in each plot for all of these. It is proving very challenging. Example: Plot 5 would return a survivorship value of 3/4 or 75%/ Plot 3 would return a survivorship value of 2/3 or 66% Any help would be much appreciated. Thank you [[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] Seeing Build Commands when running R CMD INSTALL pkg
On 15/07/2015 1:25 PM, Navraj Singh wrote: Hello, I was trying to build a package from source (specifically the 'rzmq' package) on the following platform: Mac OS X 10.8.5 (Mountain Lion) R: version 3.2.1 rzmq: version 0.7.7 (obtained from the github repo for this package) The reason I want to build this from source is that there is no binary available from CRAN for this version of rzmq for Mountain Lion (it is only available for Maverick). I'm using R CMD INSTALL ... to build the package. However, I get some errors. For now, I would just like to be able to see the exact raw commands being sent to the compiler (gcc in my case), because I think the commands aren't being set up correctly. Is there a way to do this? Normally you will see those commands. For example, if I try R CMD INSTALL rgl_0.95.1252.tar.gz on a Mac I see * installing to library ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library’ * installing *source* package ‘rgl’ ... checking for gcc... clang checking whether the C compiler works... yes ... many lines of configure code deleted ... config.status: creating src/Makevars ** libs clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/System/Library/Frameworks/OpenGL.framework/Headers -DHAVE_PNG_H -I/opt/X11/include/libpng15 -I/usr/X11/include -DDarwin -DNO_GL_PREFIX -I/usr/X11R6/include -DHAVE_FREETYPE -Iext/ftgl -I/opt/X11/include/freetype2 -Iext -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -Wall -mtune=core2 -g -O2 -fPIC -Wall -mtune=core2 -g -O2 -c ABCLineSet.cpp -o ABCLineSet.o and so on. 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.
[R-es] Operaciones entre conjuntos
Hola a todos...Estoy tratando de hacer un trabajo de comparacion de conjuntos y no entiendo que pasa con los resultados.Me explico. Tengo una columna donde se tiene el nombre de una persona, est� ordenado APELLIDOS - NOMBRESa continuaci�n tengo el el nombre de la misma persona, pero ordenado NOMBRES - APELLIDOS.El proceso debe identificar que las 2 columnas son iguales. Estoy usando operaciones entre conjuntos y estructuras data.tableNo entiendo, porque haciendo en data.table la comparacion me sale FALSA, es decir no son iguales, pero si hago la comparaci�n aparte, sale VERDADEROAdjunto el c�digo... gracias por su apoyo... require(data.table)a - data.table( x = 1:2, y = list(c(ANDRES,GERARDO,CABRERA,GUAMAN), c(MONTALVAN,VERA,JORGE,LEONARDO)), z = list(c(CABRERA,GUAMAN,GERARDO,ANDRES), c(JORGE,MONTALVAN,VERA))) a[,:=(vld=setequal(y,z)),by=x] setequal(c(ANDRES,GERARDO,CABRERA,GUAMAN),c(CABRERA,GUAMAN,GERARDO,ANDRES)) [[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] Jaccard index
Did you search the internet? At first attempt, vegdist {vegan}(worked well for me in the past) and dist.binary {ade4} seem to offer what you need. HTH, Michael -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of sreenath Sent: Mittwoch, 15. Juli 2015 09:35 To: r-help@r-project.org Subject: [R] Jaccard index How can i find jaccard index of two groups,which package is to be used? please help -- View this message in context: http://r.789695.n4.nabble.com/Jaccard-index- tp4709883.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] error message in package FD, function dbFD ()
Try doing rownames(x) - x[Species] before running dbFD. The function is probably using the row and column names of its inputs as species names, not a certain row or column of the data. Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Jul 15, 2015 at 6:47 AM, lauraRIG laura.ri...@slu.se wrote: Dear R community, I have some trouble with the dbFD function in the FD package. str(a) 'data.frame':150 obs. of 48 variables: str(x) 'data.frame':48 obs. of 9 variables: ex1 - dbFD(x,a) Error in dbFD(x, a) : Species labels in 'x' and 'a' need to be identical and ordered alphabetically (or simply in the same order). I have checked multiple time the data set but this message keeps on appearing. The names of the species are identical in both data.frames. I was wondering if you could help me by giving me an example of an excel trait and species matrix table to upload for this package. Below is a snapshop of my data. I have also checked that there are no NA’s problems and that there is no species abundance = 0 or no community with 0 species. Thank you for any advice! Best Laura Species table (a) Agonum_assimile Agonum_dorsale Agonum_gracile Agonum_gracilipes 2 3 0 0 0 6 0 0 1 10 0 0 1 5 0 0 0 8 0 0 2 7 0 0 1 6 0 0 Trait table(x) Species SizeCategoy EcologyReproductionDietWing Agonum_assimile C nocturnal spring Carnivorous Brachypterous Agonum_dorsale B nocturnal spring Carnivorous Macropterous Agonum_gracile Bdiurnal spring Carnivorous Macropterous Agonum_gracilipes B bothspring Carnivorous Macropterous -- View this message in context: http://r.789695.n4.nabble.com/error-message-in-package-FD-function-dbFD-tp4709896.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. [[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] error message in package FD, function dbFD ()
Thank you for making an effort, but your example is still not reproducible. Study something like [1] for more clarity on how to communicate online. Problems that you encounter in getting your data into R are different than problems with the functions in base R or contributed packages, and a reproducible example using dput to give us the data allows us to distinguish the two. Regarding your request for an Excel example, that is unlikely to occur given that this is an R help mailing list. There are many example data sets in base R and contributed packages. Have you read the examples on the help page for the FD package? Try ?FD-package [1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On July 15, 2015 6:47:22 AM PDT, lauraRIG laura.ri...@slu.se wrote: Dear R community, I have some trouble with the dbFD function in the FD package. str(a) 'data.frame':150 obs. of 48 variables: str(x) 'data.frame':48 obs. of 9 variables: ex1 - dbFD(x,a) Error in dbFD(x, a) : Species labels in 'x' and 'a' need to be identical and ordered alphabetically (or simply in the same order). I have checked multiple time the data set but this message keeps on appearing. The names of the species are identical in both data.frames. I was wondering if you could help me by giving me an example of an excel trait and species matrix table to upload for this package. Below is a snapshop of my data. I have also checked that there are no NA’s problems and that there is no species abundance = 0 or no community with 0 species. Thank you for any advice! Best Laura Species table (a) Agonum_assimileAgonum_dorsale Agonum_gracile Agonum_gracilipes 2 3 0 0 0 6 0 0 1 10 0 0 1 5 0 0 0 8 0 0 2 7 0 0 1 6 0 0 Trait table(x) Species SizeCategoy EcologyReproductionDietWing Agonum_assimileC nocturnal spring Carnivorous Brachypterous Agonum_dorsale B nocturnal spring Carnivorous Macropterous Agonum_gracileBdiurnal spring Carnivorous Macropterous Agonum_gracilipes B bothspring Carnivorous Macropterous -- View this message in context: http://r.789695.n4.nabble.com/error-message-in-package-FD-function-dbFD-tp4709896.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.
[R] error message in package FD, function dbFD ()
Dear R community, I have some trouble with the dbFD function in the FD package. str(a) 'data.frame':150 obs. of 48 variables: str(x) 'data.frame':48 obs. of 9 variables: ex1 - dbFD(x,a) Error in dbFD(x, a) : Species labels in 'x' and 'a' need to be identical and ordered alphabetically (or simply in the same order). I have checked multiple time the data set but this message keeps on appearing. The names of the species are identical in both data.frames. I was wondering if you could help me by giving me an example of an excel trait and species matrix table to upload for this package. Below is a snapshop of my data. I have also checked that there are no NA’s problems and that there is no species abundance = 0 or no community with 0 species. Thank you for any advice! Best Laura Species table (a) Agonum_assimile Agonum_dorsale Agonum_gracile Agonum_gracilipes 2 3 0 0 0 6 0 0 1 10 0 0 1 5 0 0 0 8 0 0 2 7 0 0 1 6 0 0 Trait table(x) Species SizeCategoy EcologyReproductionDietWing Agonum_assimile C nocturnal spring Carnivorous Brachypterous Agonum_dorsale B nocturnal spring Carnivorous Macropterous Agonum_gracile Bdiurnal spring Carnivorous Macropterous Agonum_gracilipes B bothspring Carnivorous Macropterous -- View this message in context: http://r.789695.n4.nabble.com/error-message-in-package-FD-function-dbFD-tp4709896.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] nls singular gradient matrix with an integrand
Hi. I am trying to make a nls fit for a little bit complicated expression that includes two integrals (please find enclosed the equations). I got the error Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at initial parameter estimates. First of all, I have searched already in the previous answers, but didn´t help. The parameters initialization seems to be ok, I have tried to change the parameters but no one works. If my function has just one integral everything works very nicely, but when adding a second integral term just got the error. I don´t believe the function is over-parametrized, as I have performed other fits with much more parameters and they worked. I am enclosing the data too (file.csv). And the minimal example is the following: # read the data from a csv file dados = read.csv(file.csv, header=FALSE, stringsAsFactors=FALSE) x = 0*(1:97) y = 0*(1:97) for(i in 1:97){ x[i] = dados[i,1] y[i] = dados[i,2] } integrand - function(X) { return(X^4/(2*sinh(X/2))^2) } fitting = function(T1, T2, N, D, x){ int1 = integrate(integrand, lower=0, upper = T1)$value int2 = integrate(integrand, lower=0, upper = T2)$value return(N*(D/x)^2*(exp(D/x)/(1+exp(D/x))^2 )+(448.956*(x/T1)^3*int1)+(299.304*(x/T2)^3*int2)) } fit = nls(y ~ fitting(T1, T2, N, D, x), start=list(T1=400,T2=200,N=0.01,D=2)) --For reference, the fit that worked is the following: # read the data from a csv file dados = read.csv(file.csv, header=FALSE, stringsAsFactors=FALSE) x = 0*(1:97) y = 0*(1:97) for(i in 1:97){ x[i] = dados[i,1] y[i] = dados[i,2] } integrand - function(X) { return(X^4/(2*sinh(X/2))^2) } fitting = function(T1, N, D, x){ int = integrate(integrand, lower=0, upper = T1)$value return(N*(D/x)^2*(exp(D/x)/(1+exp(D/x))^2 )+(748.26)*(x/T1)^3*int) } fit = nls(y ~ fitting(T1 , N, D, x), start=list(T1=400,N=0.01,D=2)) I cannot figure out what happen. I need to perform this fit for three integral components, but even for two I have this problem. I appreciate so much your help. Thank you. __ 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] cronbachs alpha and missing values
Sorry, ESP not functioning. Reproducible example missing. There is always more than one way to do things in R, so you need to be specific. Protip: learn to use the help system. For example, of the function you are using is called alpha, then type ?alpha at the R prompt and read. If the function is in a contributed package then you should load that package first. Documentation quality may vary due to volunteer dedication, but it often answers questions like this. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On July 15, 2015 1:50:46 AM PDT, penv254 penv...@uni-hamburg.de wrote: i want to calculate cronbachs alpha for my df. my df has some missing values so that there are only 23 out of 56 complete cases. if i run alpha on only the complete cases, i get a value of .79 and if i run it on the whole df, I get .82. My question is: what does alpha do with those missing values, if i include the incomplete cases? are they imputed in some way? -- View this message in context: http://r.789695.n4.nabble.com/cronbachs-alpha-and-missing-values-tp4709885.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] ‘ips’ had non-zero exit status
Your error says the XML package was not installed because you are missing xml2-config... if you search the web for that term you will find that your operating system needs to have libxml2 installed, including the development tools. There is a SystemRequirements entry on the CRAN web page for the XML package mentions libxml2. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On July 15, 2015 3:09:43 AM PDT, giovanni_gmail giovanni.fran...@gmail.com wrote: dear all, sorry for the naive question, I'm trying to install (in R version 3.2.1 (2015-06-18)) the ips package for phylogenetic analysis. However I get the following message: install.packages(ips,dependencies = T) Installing package into ‘/home/giovanni/R/x86_64-pc-linux-gnu-library/3.2’ (as ‘lib’ is unspecified) also installing the dependency ‘XML’ provo con l'URL 'https://cran.rstudio.com/src/contrib/XML_3.98-1.3.tar.gz' Content type 'application/x-gzip' length 1607725 bytes (1.5 MB) == downloaded 1.5 MB provo con l'URL 'https://cran.rstudio.com/src/contrib/ips_0.0-7.tar.gz' Content type 'application/x-gzip' length 62904 bytes (61 KB) == downloaded 61 KB * installing *source* package ‘XML’ ... ** package ‘XML’ successfully unpacked and MD5 sums checked checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking how to run the C preprocessor... gcc -E checking for sed... /bin/sed checking for pkg-config... /usr/bin/pkg-config checking for xml2-config... no Cannot find xml2-config ERROR: configuration failed for package ‘XML’ * removing ‘/home/giovanni/R/x86_64-pc-linux-gnu-library/3.2/XML’ Warning in install.packages : installation of package ‘XML’ had non-zero exit status ERROR: dependency ‘XML’ is not available for package ‘ips’ * removing ‘/home/giovanni/R/x86_64-pc-linux-gnu-library/3.2/ips’ Warning in install.packages : installation of package ‘ips’ had non-zero exit status The downloaded source packages are in ‘/tmp/RtmpbTmMtc/downloaded_packages’ can anybody help me? best regards Giovanni __ 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] nls singular gradient matrix with an integrand
Very few attachment types are permitted on the R mailing lists... apparently whatever file you attached did not qualify. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On July 15, 2015 7:26:59 AM PDT, Laura Teresa Corredor Bohórquez ltcorred...@gmail.com wrote: Hi. I am trying to make a nls fit for a little bit complicated expression that includes two integrals (please find enclosed the equations). I got the error Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at initial parameter estimates. First of all, I have searched already in the previous answers, but didn´t help. The parameters initialization seems to be ok, I have tried to change the parameters but no one works. If my function has just one integral everything works very nicely, but when adding a second integral term just got the error. I don´t believe the function is over-parametrized, as I have performed other fits with much more parameters and they worked. I am enclosing the data too (file.csv). And the minimal example is the following: # read the data from a csv file dados = read.csv(file.csv, header=FALSE, stringsAsFactors=FALSE) x = 0*(1:97) y = 0*(1:97) for(i in 1:97){ x[i] = dados[i,1] y[i] = dados[i,2] } integrand - function(X) { return(X^4/(2*sinh(X/2))^2) } fitting = function(T1, T2, N, D, x){ int1 = integrate(integrand, lower=0, upper = T1)$value int2 = integrate(integrand, lower=0, upper = T2)$value return(N*(D/x)^2*(exp(D/x)/(1+exp(D/x))^2 )+(448.956*(x/T1)^3*int1)+(299.304*(x/T2)^3*int2)) } fit = nls(y ~ fitting(T1, T2, N, D, x), start=list(T1=400,T2=200,N=0.01,D=2)) --For reference, the fit that worked is the following: # read the data from a csv file dados = read.csv(file.csv, header=FALSE, stringsAsFactors=FALSE) x = 0*(1:97) y = 0*(1:97) for(i in 1:97){ x[i] = dados[i,1] y[i] = dados[i,2] } integrand - function(X) { return(X^4/(2*sinh(X/2))^2) } fitting = function(T1, N, D, x){ int = integrate(integrand, lower=0, upper = T1)$value return(N*(D/x)^2*(exp(D/x)/(1+exp(D/x))^2 )+(748.26)*(x/T1)^3*int) } fit = nls(y ~ fitting(T1 , N, D, x), start=list(T1=400,N=0.01,D=2)) I cannot figure out what happen. I need to perform this fit for three integral components, but even for two I have this problem. I appreciate so much your help. Thank you. __ 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.