[R] start values for random effects in nlme
Hi Lindsey, Yeah, I do realize that this answer gets to you 12 years too late, however, it may be helpful to others in future. I have been struggling with the same issue. When analysing the source code (https://svn.r-project.org/R-packages/trunk/nlme/R/nlme.R) I found out that the E matrix needs rownames referring to the random effect of each group in the dataset, something like: rownames(E) <- c("subjectname1","subjectname2","subjectname3",.). Then your code should run perfectly OK. Example: -- library(nlme) data <- data.frame(a=c(1,2,3,4,5,1,2,3,4,5,1,2,3,4,5), b=c(2,3,4,5,7,3,4,5,7,8,3,5,6,8,9), ID=c(rep('X',5),rep('Y',5),rep('Z',5))) # Random effect matrix E: E <- as.matrix(c(-0.1,0.2,0.3)) rownames(E) <- c('X','Y','Z') fm1 <- nlme(b ~ par1*a + par2*exp(IIV), data = data, fixed = list(par1 ~ 1, par2 ~ 1), random = IIV ~ 1 | ID, start = list(fixed = c(1,1), random= E)) summary(fm1) - Kind regards, Jos Lommerse, Certara NOTICE: The information contained in this electronic mail message is intended only for the personal and confidential use of the designated recipient(s) named above. This message may be an attorney-client communication, may be protected by the work product doctrine, and may be subject to a protective order. As such, this message is privileged and confidential. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by telephone and e-mail and destroy any and all copies of this message in your possession (whether hard copies or electronically stored copies). Thank you. buSp9xeMeKEbrUze [[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] raster package: OpenStreetMap broken on Ubuntu, works on Mac
Hi, I'm a novice in R and I was trying to play with OpenStreetMap package as in a few examples on the web. And the examples worked on my Mac but on Ubuntu (12.04) they fail to work. The simplest one is: library(OpenStreetMap) library(rgdal) map - openmap(c(70,-179), c(-70,179)) plot(map) (OpenStreetMap, rgdal, rJava etc..) packages have to be installed first. On the Mac - it worked without any problems from the first try (shows a picture of world map). On Ubuntu, I get: 'merge' is not an exported object from 'namespace:raster' when I execute the openmap function. Now, at first I thought that the problem was in different library versions and it was quite a pain to make ubuntu install everything I wanted (rgdal being the biggest - unless one knows exactly what to look for on the internet, instructions are vague and there is a lot of outdated versions out there). But even after that, when version numbers matched on both OSes in R console, it still failed to work on Ubuntu. So the versions are: library(rgdal) Loading required package: sp rgdal: version: 0.8-11, (SVN revision 479M) Geospatial Data Abstraction Library extensions to R successfully loaded Loaded GDAL runtime: GDAL 1.9.2, released 2012/10/08 Path to GDAL shared files: /usr/local/share/gdal Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480] Path to PROJ.4 shared files: (autodetected) Still didn't work with identical output on both machines. Then I thought that the problem must be in raster library, but both have the same version number: packageVersion(raster) [1] ‘2.1.49’ but after showing all the functions in raster package, although both have 235 elements: basevals - ls(pos=package:raster) basevals the Mac one has merge listed and Ubuntu - doesn't. Also on Mac, the array begins with %in% and on Ubuntu with addLayer... so there is more than one inconsistency and merge is actually breaking openmap(). My questions are: *is this a bug? *is there a workaround (eg. can I export merge from raster namespace myself by copying potentially the code from Mac)? Thanks in advance, J __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] r help: source-function is very slow
Hello everybody, I noticed a performance problem when using the source-function in R. When I try to source an r script that is located in the same directory as the script I execute via command line ('R -f file.r' contents 'source(someOtherScript.r)') it's very fast. But if I put 'someOtherScript.r' in another directory (say ../../R) R takes moments, if not minutes to locate and load the script. Is there another way to do this that is not slow? Thanks, Jos -- Jos van Nijnatten, BSc Candidate Erasmus MC, Rotterdam, NL Department of Bioinformatics (ph) +31 1 07 04 45 51 (mob) +31 6 14 92 14 01 (e) j.vannijnat...@erasmusmc.nl [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] r help: source-function is very slow
Hello Uwe, Duncan and the rest of the community, It indeed seemed to be a file system problem and I'm lucky to figure that out before it crashed. New computer's great and everything is working fine again. Sorry for wasting your time ;-) On Thursday, January 19, 2012 15:16, Duncan Murdoch wrote: On 12-01-19 8:25 AM, Jos van Nijnatten wrote: Hello everybody, I noticed a performance problem when using the source-function in R. When I try to source an r script that is located in the same directory as the script I execute via command line ('R -f file.r' contents 'source(someOtherScript.r)') it's very fast. But if I put 'someOtherScript.r' in another directory (say ../../R) R takes moments, if not minutes to locate and load the script. Is there another way to do this that is not slow? R uses the same method in both instances. If there's a difference in timing, it's almost certainly because there's something going on with your OS or file system. Duncan Murdoch -- Jos van Nijnatten, BSc Candidate Erasmus MC, Rotterdam, NL Department of Bioinformatics (ph) +31 1 07 04 45 51 (mob) +31 6 14 92 14 01 (e) j.vannijnat...@erasmusmc.nl __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Rmpi installation problems
Hi all, I am trying to install the Rmpi package in R and, while the installation itself works, it breaks down when trying to load the library. I think it has something to do with shared vs static loading of helper libraries, or the order in which shared libraries are loaded, but I am not sure. R version: 2.14.0 Linux version: Gentoo, i686-pc-linux-gnu (32-bit) GCC version: 4.5.3 (Gentoo 4.5.3-r1 p1.0) OpenMPI version: 1.5.4 Output from R CMD INSTALL . in Rmpi source directory: * installing to library ‘/home/jos/R/i686-pc-linux-gnu-library/2.14’ * installing *source* package ‘Rmpi’ ... checking for gcc... i686-pc-linux-gnu-gcc -std=gnu99 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 i686-pc-linux-gnu-gcc -std=gnu99 accepts -g... yes checking for i686-pc-linux-gnu-gcc -std=gnu99 option to accept ISO C89... none needed I am here /usr and it is OpenMPI Trying to find mpi.h ... Found in /usr/include Trying to find libmpi.so or libmpich.a ... Found libmpi in /usr/lib checking for openpty in -lutil... yes checking for main in -lpthread... yes configure: creating ./config.status config.status: creating src/Makevars ** Creating default NAMESPACE file ** libs make: Nothing to be done for `all'. installing to /home/jos/R/i686-pc-linux-gnu-library/2.14/Rmpi/libs ** R ** demo ** inst ** preparing package for lazy loading ** help *** installing help indices ** building package indices ... ** testing if installed package can be loaded /usr/lib/R/bin/exec/R: symbol lookup error: /usr/lib/openmpi/mca_paffinity_hwloc.so: undefined symbol: mca_base_param_reg_int ERROR: loading failed * removing ‘/home/jos/R/i686-pc-linux-gnu-library/2.14/Rmpi’ Any help would be greatly appreciated! Jos __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] (svy)glm and weights question
Hi all, I am running a set of logistic regressions, where we want to use some weights, and I am not sure whether what I am doing is reasonable or not. The dependent variable is turnout in an election - i.e. survey respondents were asked whether or not they voted. The percentage of those who say they voted is much higher than the actual turnout, probably due both to non-response bias and social desirability issues. So now the suggestion is to weigh the cases, to weigh down the respondents who say they voted and weigh more heavily those who did say they did not vote. So the questions that arise from this are: 1) Is it reasonable to use the distribution of the dependent variable to calculate the weights used in a logistic regression? It feels wrong, but I cannot find, so far, any sources on this. 2) How to implement this in R? I tried the weights option in glm(), but I think that is meant for when you have one row in your data for multiple observations, not for this kind of weight. Although I have the McCullagh and Nelder book explaining in detail how glm() operates, I cannot find a similar book for svyglm(). Is svyglm() better for this type of weighting? 3) Where would I find a good source describing the estimation procedure, including weighting, applied in svyglm()? Thanks in advance for any help! Jos -- Johan A. Elkink Lecturer in Social Science Research Methods School of Politics and International Relations CHS Graduate School University College Dublin Ph. +353 1 716 8150 | Newman Building, Rm F304 http://jaeweb.cantr.net __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] sample unique pairs from a matrix
Dear R users, I have a matrix of both negative and positive values that I would like to randomly sample with the following 2 conditions: 1. only sample positive values 2. once a cell in the matrix has been sampled the row and column of that cell cannot be sampled from again. #some dummy data set.seed(101) dataf - matrix(rnorm(36,1,2), nrow=6) I can do this quite simply if all the values are positive by using the sample function without replacement on the column and row indices. samrow - sample(6,replace=F) samcol - sample(6,replace=F) values - numeric(6) for(i in 1:6){ values[i] - dataf[samrow[i], samcol[i]] } However, I am not sure how to include the logical condition to only include postitive values Any help would be gratefully received. Jos __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sample unique pairs from a matrix
Dear Ritchie and David, Thanks very much for your advice. I had thought of this potential solution, however it doesn't really fullfill my second criteria which is that once a particular cell has been sampled, the row and column of that cell can't be sampled from subsequently. In other words, the next sample would be taken from a 5x5 matrix, and then a 4x4 matrix and so on until I have my 6 values. I will keep thinking! Cheers Jos 2009/5/28 David Winsemius dwinsem...@comcast.net: On May 28, 2009, at 6:33 AM, jos matejus wrote: Dear R users, I have a matrix of both negative and positive values that I would like to randomly sample with the following 2 conditions: 1. only sample positive values 2. once a cell in the matrix has been sampled the row and column of that cell cannot be sampled from again. #some dummy data set.seed(101) dataf - matrix(rnorm(36,1,2), nrow=6) I can do this quite simply if all the values are positive by using the sample function without replacement on the column and row indices. samrow - sample(6,replace=F) samcol - sample(6,replace=F) values - numeric(6) for(i in 1:6){ values[i] - dataf[samrow[i], samcol[i]] } However, I am not sure how to include the logical condition to only include postitive values Any help would be gratefully received. Jos M - matrix(rnorm(36),nrow=6) M[M[,]0] [1] 1.65619781 0.56182830 0.23812890 0.81493915 1.01279243 1.29188874 0.64252343 0.53748655 0.31503112 [10] 0.37245358 0.07942883 0.56834586 0.62200056 0.39478167 0.02374574 0.04974857 0.56219171 0.52901658 sample(M[M[,]0],6,replace=F) [1] 0.56834586 0.07942883 0.31503112 0.62200056 0.02374574 0.64252343 -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sample unique pairs from a matrix
Dear All, Many thanks for all your useful suggestions. Much appreciated. Jos 2009/5/28 David Winsemius dwinsem...@comcast.net: Your last step will either be a single number (not really a sampling operation) or a non-positive number. So at best you really only have an number that depends entirely on the prior sequence of draws. -- David. On May 28, 2009, at 8:21 AM, jos matejus wrote: Dear Ritchie and David, Thanks very much for your advice. I had thought of this potential solution, however it doesn't really fullfill my second criteria which is that once a particular cell has been sampled, the row and column of that cell can't be sampled from subsequently. In other words, the next sample would be taken from a 5x5 matrix, and then a 4x4 matrix and so on until I have my 6 values. I will keep thinking! Cheers Jos 2009/5/28 David Winsemius dwinsem...@comcast.net: On May 28, 2009, at 6:33 AM, jos matejus wrote: Dear R users, I have a matrix of both negative and positive values that I would like to randomly sample with the following 2 conditions: 1. only sample positive values 2. once a cell in the matrix has been sampled the row and column of that cell cannot be sampled from again. #some dummy data set.seed(101) dataf - matrix(rnorm(36,1,2), nrow=6) I can do this quite simply if all the values are positive by using the sample function without replacement on the column and row indices. samrow - sample(6,replace=F) samcol - sample(6,replace=F) values - numeric(6) for(i in 1:6){ values[i] - dataf[samrow[i], samcol[i]] } However, I am not sure how to include the logical condition to only include postitive values Any help would be gratefully received. Jos M - matrix(rnorm(36),nrow=6) M[M[,]0] [1] 1.65619781 0.56182830 0.23812890 0.81493915 1.01279243 1.29188874 0.64252343 0.53748655 0.31503112 [10] 0.37245358 0.07942883 0.56834586 0.62200056 0.39478167 0.02374574 0.04974857 0.56219171 0.52901658 sample(M[M[,]0],6,replace=F) [1] 0.56834586 0.07942883 0.31503112 0.62200056 0.02374574 0.64252343 -- David Winsemius, MD Heritage Laboratories West Hartford, CT David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] reference category for factor in regression
Hi all, I am struggling with a strange issue in R that I have not encountered before and I am not sure how to resolve this. The model looks like this, with all irrelevant variables left out: LABOUR - a dummy variable NONLABOUR = 1 - LABOUR AGE - a categorical variable / factor VOTE - a dummy variable glm(VOTE ~ 0 + LABOUR + NONLABOUR + LABOUR : AGE + NONLABOUR : AGE, family=binomial(link=logit)) In other words, a standard interaction model, but I want to know the intercepts and coefficients for each of the two cases (LABOUR and NONLABOUR), instead of getting coefficients for the differences as in a normal interaction model. But the strange thing is, for the two occurances of the AGE variable, it makes a different choice as to which AGE category to leave out of the regression. The cross-table of AGE with LABOUR does not have empty cells. Anyone any idea what might be going wrong? Or what I could do about this? Thanks in advance for any help! Regards, Jos -- Johan A. Elkink Lecturer School of Politics and International Relations CHS Graduate School University College Dublin Ph. +353 1 716 7026 | Library Building, Rm 512 http://jaeweb.cantr.net __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reference category for factor in regression
Hi Thierry, Thanks for your quick answer. The problem is not so much the LABOUR variable, however, but the AGE variable, which consists of about 5 categories for which I do indeed not create separate dummy variables. But R does not behave as expected when deciding on which dummy to use as reference category ... Jos On Mon, Jan 19, 2009 at 2:37 PM, ONKELINX, Thierry thierry.onkel...@inbo.be wrote: Dear Jos, In R you don't need to create you own dummy variables. Just create a factor variable LABOUR (with two levels) and rerun your model. Then you should be able to calculate all coefficients. HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Jos Elkink Verzonden: maandag 19 januari 2009 15:16 Aan: r-help@r-project.org Onderwerp: [R] reference category for factor in regression Hi all, I am struggling with a strange issue in R that I have not encountered before and I am not sure how to resolve this. The model looks like this, with all irrelevant variables left out: LABOUR - a dummy variable NONLABOUR = 1 - LABOUR AGE - a categorical variable / factor VOTE - a dummy variable glm(VOTE ~ 0 + LABOUR + NONLABOUR + LABOUR : AGE + NONLABOUR : AGE, family=binomial(link=logit)) In other words, a standard interaction model, but I want to know the intercepts and coefficients for each of the two cases (LABOUR and NONLABOUR), instead of getting coefficients for the differences as in a normal interaction model. But the strange thing is, for the two occurances of the AGE variable, it makes a different choice as to which AGE category to leave out of the regression. The cross-table of AGE with LABOUR does not have empty cells. Anyone any idea what might be going wrong? Or what I could do about this? Thanks in advance for any help! Regards, Jos -- Johan A. Elkink Lecturer School of Politics and International Relations CHS Graduate School University College Dublin Ph. +353 1 716 7026 | Library Building, Rm 512 http://jaeweb.cantr.net __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. -- Johan A. Elkink Lecturer School of Politics and International Relations CHS Graduate School University College Dublin Ph. +353 1 716 7026 | Library Building, Rm 512 http://jaeweb.cantr.net __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reference category for factor in regression
Hi all, Thanks for the advice. See ?relevel for information on how to reorder the levels of a factor, while being able to specify the reference level. Basically, the first level of the factor is taken as the reference. Yes, that is how I always used it. But the problem is, in this particular regression R does *not* take the first level as reference. In fact, AGE appears twice in the same regression (two different interactions) and in one case it selects the 1st category and in another case a different one. BTW, you might want to review Frank Harrell's page on why categorizing a continuous variable is not a good idea: I most certainly agree, but the categorisation has been imposed in the survey itself, so it is all the data I have. I did not design the questions :-) ... Thanks for this reference, though, as it is certainly interesting to inform my teaching. str(AGE) Factor w/ 5 levels 65+,18-24,..: 5 5 1 4 5 5 2 4 1 3 ... So I expect 65+ to be the reference category, but it is not. Here is a little bit more R code to show the problem: str(AGE) Factor w/ 5 levels 65+,18-24,..: 5 5 1 4 5 5 2 4 1 3 ... table(LABOUR) LABOUR 01 692 1409 NONLABOUR - 1 - LABOUR m - glm(NOVOTE ~ 0 + LABOUR + NONLABOUR + AGE : LABOUR + AGE : NONLABOUR, family=binomial) m Call: glm(formula = NOVOTE ~ 0 + LABOUR + NONLABOUR + AGE:LABOUR + AGE:NONLABOUR, family = binomial) Coefficients: LABOUR NONLABOUR LABOUR:AGE65+ LABOUR:AGE18-24 -0.35110-0.30486-0.11890-0.66444 LABOUR:AGE25-34 LABOUR:AGE35-49 LABOUR:AGE50-64 NONLABOUR:AGE18-24 -0.23893-0.15860 NA-0.65655 NONLABOUR:AGE25-34 NONLABOUR:AGE35-49 NONLABOUR:AGE50-64 -0.72815 0.04951 0.17481 As you can see, 65+ is taken as reference category in the interaction with NONLABOUR, but not in the interaction with LABOUR. I know glm(NOVOTE ~ LABOUR * AGE, family=binomial) would be a more conventional specification, but the above should be equivalent and should give me the coefficients and standard errors for the two groups (LABOUR and NONLABOUR) separately, rather than for the difference / interaction term). Perhaps the NA in the above output (which I only notice now) is a hint at the problem, but I am not sure why that occurs. table(m$model$AGE, m$model$LABOUR, m$model$NOVOTE) , , = 0 0 1 65+ 137 24 18-24 68 127 25-34 59 267 35-49 71 298 50-64 82 179 , , = 1 0 1 65+ 101 15 18-24 26 46 25-34 21 148 35-49 55 179 50-64 72 126 Anyone any idea? So there must be a reason R decides *not* to use 65+ as reference in that particular scenario, and I am missing why. Jos __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Port package
Hi When I type: ?nls I come across this section: algorithm: character string specifying the algorithm to use. The default algorithm is a Gauss-Newton algorithm. Other possible values are 'plinear' for the Golub-Pereyra algorithm for partially linear least-squares models and 'port' for the 'nl2sol' algorithm from the Port package. The simple question is: where's the Port package? I can't find it on cran. Thanks, Jos __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.