[R] extract minimal variables from model

2017-01-06 Thread Jacob Wegelin
Given any regression model, created for instance by lm, lme, lmer, or rqs, such as z1<-lm(weight~poly(Time,2), data=ChickWeight) I would like a general way to obtain only those variables used for the model. In the current example, this "minimal data frame" would consist of the "weight" and "T

[R] confirm family==binomial and link==logistic

2016-02-12 Thread Jacob Wegelin
To check that a regression object comes from logistic regression, I employ the following two lines: stopifnot(glmObject$family$family=="binomial") stopifnot(glmObject$family$link=="logit") For instance: toyfunction<-function(glmObject) { stopifnot(inherits(glmObject, "

Re: [R] ggplot2 geom_boxplot limits

2015-07-20 Thread Jacob Wegelin
tally *and* to zoom in? myplot+coord_cartesian(ylim=mylimits) # zooms in myplot+coord_cartesian(ylim=mylimits) + coord_flip() # flips but does not zoom myplot + coord_flip()+coord_cartesian(ylim=mylimits) # zooms but does not flip Jacob Wegelin Op 20-jul.-2015 20:29 schreef "Jacob Wege

[R] ggplot2 geom_boxplot limits

2015-07-20 Thread Jacob Wegelin
With base graphics, one can use the "ylim" argument to zoom in on a boxplot. With ggplot2, using "limits" to try to zoom in on a boxplot *changes the box*. Since the box usually indicates the 25th and 75th percentiles of a quantitative variable, this is puzzling. The toy code below demonstrat

Re: [R] nlme splines model.frame.default error

2015-06-02 Thread Jacob Wegelin
On 2015-06-02 Tue 14:20, Jacob Wegelin wrote: I want to use a specialized function to compute knots on the fly to pass to splines::bs within a call to nlme::lme. The specialized function will compute knots from the x-axis variable (the x argument in a call to splines::bs). The syntax works

[R] nlme splines model.frame.default error

2015-06-02 Thread Jacob Wegelin
o error: mylme<- with(toydat, lme(fixed=why~bs(eks,knots=customKnotsFn(some=eks)),random=~1|ID)) print(mylme$call) Of course, with the workaround the resulting mylme does not know where the data came from. Why should a workaround be necessary? Is there something inherently misguided about

Re: [R] scales percent precision

2014-02-27 Thread Jacob Wegelin
Incidentally, ?scales::percent brings up exactly the same text as ?scales::percent_format On 2014-02-27 Thu 14:47, Jacob Wegelin wrote: But percent_format() does not take the argument, multiply it by 100, and paste on a percent sign, as we see here: ?scales::percent_format percent_format

Re: [R] scales percent precision

2014-02-27 Thread Jacob Wegelin
: Hi: On Thu, Feb 27, 2014 at 8:49 AM, Jacob Wegelin wrote: scales::percent appears not to be documented. ?scales::percent_format where it tells you that it takes its argument, multiplies it by 100 and then attaches a percent sign to it. For most situations, the data should be relative f

[R] scales percent precision

2014-02-27 Thread Jacob Wegelin
path. Nor does round_any(). percent(0.010101) [1] "1.01%" percent function (x) { x <- round_any(x, precision(x)/100) str_c(comma(x * 100), "%") } find("precision") character(0) find("round_any") character(0) Thanks for any insights Jacob

[R] plus/minus +/- in factor; not plotmath not expression

2013-12-02 Thread Jacob Wegelin
I want to put the "plus or minus" symbol into a character variable, so that this can be turned into a factor and be displayed in the "strip" of a faceted ggplot2 plot. A very nice solution, thanks to Professor Ripley's post of Nov 16, 2008; 3:13pm, visible at http://r.789695.n4.nabble.com/Sym

Re: [R] scope, lme, ns, nlme, splines

2012-12-19 Thread Jacob Wegelin
PRETTYNEWDATA$fitlme<-predict(thislme,level=0, newdata=PRETTYNEWDATA) thislme } Jake Wegelin On Thu, 6 Dec 2012, Duncan Murdoch wrote: On 06/12/2012 2:28 PM, Jacob Wegelin wrote: I want to fit a series of lme() regression models that differ only in the degrees of freedom of a ns() spline.

[R] scope, lme, ns, nlme, splines

2012-12-06 Thread Jacob Wegelin
I want to fit a series of lme() regression models that differ only in the degrees of freedom of a ns() spline. I want to use a wrapper function to do this. The models will be of the form y ~ ns(x, df=splineDF) where splineDF is passed as an argument to a wrapper function. This works fine if th

[R] lme(y ~ ns(x, df=splineDF)) error

2012-09-26 Thread Jacob Wegelin
I would like to fit regression models of the form y ~ ns(x, df=splineDF) where splineDF is passed as an argument to a wrapper function. This works fine if the regression function is lm(). But with lme(), I get two different errors, depending on how I handle splineDF inside the wrapper function

[R] lme( y ~ ns(x, df=splineDF)) error

2012-09-06 Thread Jacob Wegelin
I would like to fit regression models of the form y ~ ns(x, df=splineDF) where splineDF is passed as an argument to a wrapper function. This works fine if the regression function is lm(). But with lme(), I get two different errors, depending on how I handle splineDF inside the wrapper function

[R] unable to load Hmisc in R 2.14.0

2011-11-10 Thread Jacob Wegelin
On my MacBook Pro (OS 10.6.8), after updating to R version 2.14.0 (2011-10-31) and reinstalling the Hmisc package, I am unable to load the Hmisc library. Hmisc was working *before* I updated R. Any idea what's wrong? Details below. install.packages("Hmisc", dependencies=TRUE) trying URL 'h

[R] ggplot2 boxplot: horizontal, univariate

2010-06-18 Thread Jacob Wegelin
In ggplot2, I would like to make a boxplot that has the following properties: (1) Contrary to default, the meaningful axis should be the horizontal axis. Lattice does this, for instance, by library(lattice);bwplot(~mtcars$mpg) (2) It is *univariate*, i.e., of a single vector, say mtcars$mpg.

[R] fixed portion of lme4 model in newdata

2010-04-15 Thread Jacob Wegelin
Suppose we have • An lmer{lme4} model, MyModel, computed on dataframe SomeDATA; • Dataframe NEWDATA, which contains the variables used in computing MyModel, but different values for these variables. In NEWDATA I would like to compute (in an automated, quick, easy,

[R] fisher.test gives p>1

2010-03-04 Thread Jacob Wegelin
The purpose of this email is to (1) report an example where fisher.test returns p > 1 (2) ask if there is a reliable way to avoid p>1 with fisher.test. If one has designed one's code to return an error when it finds a "nonsensical" probability, of course a value of p>1 can cause havoc. Examp

[R] match.call to obtain the name of a function

2010-02-26 Thread Jacob Wegelin
ordering a chicken sandwich and then telling the waitress to hold (that is, to subtract) the meat, lettuce, and mayonnaise. Thanks for any insights Jacob Wegelin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help

[R] conditioned xyplot, many y variables

2010-02-07 Thread Jacob Wegelin
The example below creates parallel time-series plots of three different y variables conditioned by a dichotomous factor. In the graphical layout, • Each y variable inhabits its own row and is plotted on its own distinct scale. • Each level of the factor has its own

[R] parallel xyplot, different y scales, conditioned

2010-02-05 Thread Jacob Wegelin
The syntax below creates parallel time-series plots of three different y variables conditioned by a dichotomous factor. (Thanks to several people who answered an earlier post from Thursday, http://tolstoy.newcastle.edu.au/R/e9/help/10/02/3848.html. The syntax below is based on their helpful

[R] xyplot 3 panels 3 different Y variables

2010-02-04 Thread Jacob Wegelin
Often, when exploring a dataset, I'd like to plot several very different Y variables against the same X variable, in panels stacked one over the other. Is there an easy way to do this? I'd like to achieve an elegant look similar to the look achieved by lattice in conditioned plots--for instan

Re: [R] wilcox.test loop through variable names

2009-11-15 Thread Jacob Wegelin
On Sun, 15 Nov 2009 14:33 -0500, "Jacob Wegelin" wrote: > > Often I perform the same task on a series of variables in a dataframe, > by looping through a character vector that holds the names and using > paste(), eval(), and parse() inside the loop. > > For ins

[R] wilcox.test loop through variable names

2009-11-15 Thread Jacob Wegelin
Often I perform the same task on a series of variables in a dataframe, by looping through a character vector that holds the names and using paste(), eval(), and parse() inside the loop. For instance: rm(environmental) thesevars<-names(environmental) environmental$ToyReal <-rnorm(nrow(environmen

[R] loop through variable names

2009-11-11 Thread Jacob Wegelin
Often I perform the same task on a series of variables in a dataframe, by looping through a character vector that holds the names and using paste(), eval(), and parse() inside the loop. For instance: thesevars<-names(environmental) environmental$ToyOutcome<-rnorm(nrow(environmental)) tableOf

[R] variable labels to accompany data.frame

2009-10-28 Thread Jacob Wegelin
Often it is useful to keep a "codebook" to document the contents of a dataset. (By "dataset" I mean a rectangular structure such as a dataframe.) The codebook has as many rows as the dataset has columns (variables, fields). The columns (fields) of the codebook may include: • va

[R] xyplot does not find variable in data

2009-10-12 Thread Jacob Wegelin
When we call a lattice function such as xyplot, to what extent does the "data" designation cause the function to look inside the "data" for variables? In the examples below, the "subset" argument understands that "Variety" is a variable in the data. But the "scales" argument does not understand t

Re: [R] lattice auto.key drop unused levels

2009-10-10 Thread Jacob Wegelin
=T) whereas dropping levels in the "group" argument does not create the desired effect xyplot(yield~nitro, subset=(Block=="I" | Block=="II"), data=Oats, group=Block [, drop=T], auto.key=T) Jacob Wegelin >  -Peter Ehlers > > Jacob Wegelin wrote: >

[R] lattice auto.key drop unused levels

2009-10-10 Thread Jacob Wegelin
The following code produces a legend ("key") that mentions the unused levels of Block. library(MEMSS) xyplot(yield~nitro, subset=(Block=="I" | Block=="II"), data=Oats, group=Block, auto.key=T) and adding "drop.unused.levels=T" does not fix it. And in fact even the following does not solve the pro

[R] symbols(x,y, circles=sqrt(N)) with lattice xyplot

2009-09-14 Thread Jacob Wegelin
How would I create the following plot using lattice? symbols( combPsummary$pastRate, combPsummary$finRate, circles=sqrt(combPsummary$N) ) The idea is to plot finRate vs pastRate using circles whose areas are proportional to the number of people in each group. The following attempt does not reall

[R] lattice: control size of axis title and axis labels

2009-08-08 Thread Jacob Wegelin
Was: Re: Adjusting x/y text labels for a bwplot using cex.lab The purpose of this email is merely to explain how to control, separately, two different text sizes on the axes in an R plot, in traditional or lattice graphics. I did not find an explicit exposition of this, with examples, in a quick

[R] lattice: simultaneously control aspect & outer whitespace

2009-08-07 Thread Jacob Wegelin
Suppose we wish to achieve the following three aims: (1) Control the aspect ratio of our plot (i.e., tweak this till it looks great) (2) Save the plot as a PDF with zero or minimal white space outside it. (3) Preserve this in code, so that in the future the exact same plot can be reproduced by si

[R] specify lattice black-and-white theme

2009-08-05 Thread Jacob Wegelin
Is there a simple way to specify a theme or trellis (lattice) parameters so that, in a multipanel (conditioned) plot, there is no color and in the strips there is no shading? This is the effect achieved on page 124 of Deepayan Sarkar's "Lattice" (figure 7.2). I managed to trick lattice into making

Re: [R] multiple lty on same panel in xyplot

2009-08-05 Thread Jacob Wegelin
On Wed, 5 Aug 2009, Deepayan Sarkar wrote: > On 8/5/09, Jacob Wegelin wrote: >> I would like to use lattice graphics to plot multiple functions (or groups >> or subpopulations) on the same plot region, using different line types "lty" >> or colors "col"

Re: [R] multiple lty on same panel in xyplot

2009-08-05 Thread Jacob Wegelin
On Wed, Aug 5, 2009 at 1:30 PM, Jacob Wegelin wrote: > I would like to use lattice graphics to plot multiple functions (or groups > or subpopulations) on the same plot region, using different line types "lty" > or colors "col" to distinguish the functions (or groups)

[R] multiple lty on same panel in xyplot

2009-08-05 Thread Jacob Wegelin
I would like to use lattice graphics to plot multiple functions (or groups or subpopulations) on the same plot region, using different line types "lty" or colors "col" to distinguish the functions (or groups). In traditional graphics, this seems straightforward: First plot all the data using 'type

Re: [R] session logging

2009-08-04 Thread Jacob Wegelin
t the beginning of your > session should do it? > > Jacob Wegelin wrote: > >> >> Consider all the text that one sees on the console during an R session. >> >> Is there a way, within R, to make all this text--both the "output" and the >> "messages"

Re: [R] session logging

2009-08-03 Thread Jacob Wegelin
4558University of Illinois > fax: 217-244-6678Urbana, IL 61801 > > > > > On Aug 3, 2009, at 3:01 PM, Jacob Wegelin wrote: > > Consider all the text that one sees on the console during an R session. >> >> Is there a way, withi

[R] session logging

2009-08-03 Thread Jacob Wegelin
Consider all the text that one sees on the console during an R session. Is there a way, within R, that all this text--i.e., both the "output" and the "messages"--can be automatically copied to a single file, in addition to its being visible on the console? If I remember to save the console to a f

[R] session logging

2009-08-03 Thread Jacob Wegelin
Consider all the text that one sees on the console during an R session. Is there a way, within R, to make all this text--both the "output" and the "messages"--automatically get copied to a single text file, in addition to seeing it on the console? If I remember to save the console to a file a

[R] obtain names of variables and data from glm object

2009-07-26 Thread Jacob Wegelin
Suppose we have some glm object such as: myglm <- glm( y ~ x, data=DAT) Is there an elegant way--or the "right way" within the R way of thinking--to obtain the names of the response variable, the predictor variables, and the dataset, as character strings? For instance, suppose the "right way" wa

Re: [R] nested calls, variable scope

2008-08-01 Thread Jacob Wegelin
, > > Bert Gunter > Genentech > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > On > Behalf Of Jacob Wegelin > Sent: Thursday, July 17, 2008 1:58 PM > To: [EMAIL PROTECTED] > Subject: [R] nested calls, variable scope > > Below i

[R] dput vs unclass to see what a factor really is composed of

2008-07-31 Thread Jacob Wegelin
I used read.dta() to read in a Stata 9 dataset to R. The "Sex01" variable takes on two values in Stata: 0 and 1, and it is labeled "M" and "F" respectively, analogous to an R factor. Thus, read.dta reads it in as a factor. Now, I wanted to see what this variable *really* is, in R. For instance, so

[R] nested calls, variable scope

2008-07-17 Thread Jacob Wegelin
Below is an example of a problem I encounter repeatedly when I write functions. A call works at the command line, but it does not work inside a function, even when I have made sure that all required variables are available within the function. The only way I know to solve it is to make the require

[R] nested calls, variable scope

2008-07-17 Thread Jacob Wegelin
Below is an example of a problem I encounter repeatedly when I write functions. A call works at the command line, but it does not work inside a function, even when I have made sure that all required variables are available within the function. The only way I know to solve it is to make the re