Displaying 20 results from an estimated 200 matches similar to: "PDF output problem"
2025 Mar 29
4
Creating model formulas programmatically
Note: I am almost certain that this has been asked and answered here
before, so my apologies for the redundant query.
I also know that there are several packages that will do this, but I wish
to do it using base R functions only (see below).
The query: Suppose I have a character vector of names like this:
somenames <- c("Heigh", "Ho", "Silver", "Away")
2025 Mar 30
1
Creating model formulas programmatically
Gabor, Duncan, et. al.
1. Thank you for your great comments and solutions. This is what I was
hoping for!
2. Duncan: I completely agree with your criticisms. In fact, I realized the
for() loop only needed the <- assignment, but your comment is important to
note. However, I didn't like the for() loop either; I *much* preferred your
Reduce() solution which is exactly the sort of elegant
2025 Mar 30
1
Creating model formulas programmatically
Another solution. reformulate + substitute + as.formula:
substitute(~ (.)^2, list(. = reformulate(somenames)[[2]])) |> as.formula()
On Sat, Mar 29, 2025 at 5:31?PM Bert Gunter <bgunter.4567 at gmail.com> wrote:
>
> Note: I am almost certain that this has been asked and answered here
> before, so my apologies for the redundant query.
>
> I also know that there are several
2025 Mar 29
1
[External] Creating model formulas programmatically
> somenames <- c("Heigh", "Ho", "Silver", "Away")
> as.formula(paste("~(",paste(somenames, collapse="+"),")^2"))
~(Heigh + Ho + Silver + Away)^2
>
> On Mar 29, 2025, at 14:30, Bert Gunter <bgunter.4567 at gmail.com> wrote:
>
> somenames <- c("Heigh", "Ho", "Silver",
2025 Mar 30
1
[External] Creating model formulas programmatically
As always, I would like to thank all who responded for their insights and
suggestions. I have learned from them.
Thus far, my own aesthetic preference -- and therefore not to be considered
in any sense as a "best" approach -- is to use Duncan's suggestion to
produce the call directly with call() rather than substitute in my simple
for() loop; i.e.
somenames <-
2025 Mar 29
2
[External] Creating model formulas programmatically
Thanks, Rich.
I thought of that, too, but it violates the spirit of my restraints (to
avoid character strings), which I unfortunately did not clearly articulate.
So my apologies for that failure. My concern is that with more complex
model formula, using as.formula, etc. to parse/convert character strings
can get a bit hairy. But in most cases, as here maybe, it may be perfectly
fine. So think of
2025 Mar 30
1
[External] Creating model formulas programmatically
my take of the assignment was to avoid 'parse' specifically.
we start with a character vector, so avoiding characters is not possible. i was dealing with the fortune "if parse is the answer, you have the wrong question"
Sent from my iPhone
On Mar 29, 2025, at 15:39, Bert Gunter <bgunter.4567 at gmail.com> wrote:
?
Thanks, Rich.
I thought of that, too, but it violates
2025 Mar 30
1
[External] Creating model formulas programmatically
I am confused. Richard's answer that Bert did not like did not use parse explicitly. Richard pasted together a string that a function like lm() will have to parse to run the analysis. However, the answers so far do not use parse(). In the reply to Richard, Bert indicated we cannot use strings. Even if I pass a vector where R can assume that the first variable is the dependent variable and all
2025 Mar 30
1
[External] Creating model formulas programmatically
Hello,
I thought of answering "reformulate can solve the problem" but how do
you create quadratic terms with reformulate?
~(Heigh + Ho + Silver + Away)^2
is still a problem with no solution that I know of but paste/as.formula.
Or Bert's bquote or substitute.
Rui Barradas
?s 23:18 de 29/03/2025, Ebert,Timothy Aaron escreveu:
> The general formula is y ~ a + b + c + ...
>
2025 Mar 29
1
[External] Creating model formulas programmatically
The general formula is y ~ a + b + c + ...
There is this approach:
formula <- reformulate(independent_vars, response = "y")
model <- lm(formula, data = mydata)
summary(model)
It does not generate a string object, but the formula is still a string even if it is of class formula. Also, in this approach you only get + and if you want interactions or such you will need to code them
2002 Apr 17
1
No output from (lattice) xyplot called within loops
Hello
>From the following script I received
a grafic output when I called:
- xyplot.test( 'green3' )
- call.xyplot.test( 'blue3' )
I did NOT receive a grafic output
when I called:
- loop.xyplot.test( 'red3' )
What's the Problem?
NB: I am using R 1.4.1 on Linux.
--------- START OF SCRIPT ----------------
n <- 1000
x <- seq( 1, n )
y <- rnorm( n )
2008 Jan 04
1
Sorting of captions on axes
Hello,
I think this might be a beginner question, but I couldn't find the answer in
the manual...
http://www.nabble.com/file/p14618947/at-modality.png
I created this image with R by using the following code:
modality <- read.table("results.table", header=TRUE, sep=",")
color <-
2009 Nov 30
1
Continuous legend colors
Dear List,
I am trying to get a basic plot to show a continuous range of fill colors. It is probably easiest to demonstrate. I would like a legend like in the following example:
Satellite.Palette <-colorRampPalette(c("blue3","cyan","aquamarine","yellow","orange","red"))
require(fields)
image.plot(volcano, col = Satellite.Palette
2008 Jan 07
4
Orientation of labels on axes
http://www.nabble.com/file/p14664173/at-modality.png
I created the above image with R and I have one problem left:
Some of the labels of the axes do not show up, probably because there's not
enough space.
I use the following code to create the plot:
modality <- read.table("results.table", header=TRUE, sep=",")
color <-
2005 Jul 27
3
Asymmetric colors for heatmap
> Dear expeRts,
>
> Currently, my colors are as follows:
> mycol <-
> c("blue1","blue2","blue3","blue4","black","yellow4","yellow3","yellow2","y
> ellow1")
> heatmap(snp, Rowv=NA, Colv=NA, col=mycol)
>
> However, I would like to have the following colors:
> bright blue ->
2010 Dec 12
4
legend not appearing in Word document
I need help with using graphics in Word 2007 that will later be converted into a
pdf document.? I have tried several formats and found that?I get the best
quality of graphics using .wmf, .eps format, but when I convert it to .pdf I get
a bunch of lines across the figures.? I also tried .tiff and .png but they give
me much lower quality.? The best quality that converts to pdf appears to be
2007 Nov 21
1
fitting a line to a logaritmic plot
Hi,
I have processed measurements of a rough surface to a heigh-height
correlation plot. What the meaning of this exactly is, is not important.
Only that it is a plot that had two (almost ) linear parts when plotted on a
logaritmic scale. In this plot, I want to draw the best fitting lines for
these linear parts but I just can't get it done. It is easy when the scales
are linear but as you
2008 Dec 12
1
How to mimic select.list using RGtk2/gWidgetsRGtk2?
I want to write a function mimic the function of select.list(), here
is my preliminary version.
select <- function(x,multiple=TRUE,...){
ans<-new.env()
g <- gwindow(title=title,wid=200,heigh=500)
x1<-ggroup(FALSE,con=g)
x2<-gtable(x,multiple=multiple,con=x1,expand=TRUE)
gbutton("OK",con=x1,handler=function(h,...){
value <- svalue(x2)
if (length(value)==0)
2009 Nov 30
1
Plotting color.legend() outside of plot region
Dear List,
I am trying to plot a color.legend() in the right outer margin of my device region. I have read multiple threads on the subject and still can't get it right. I have stolen an example from one of the threads to demonstrate my problem. I have extended the outer margin using par(oma()), and have used par(xpd=NA) to tell it to plot in the device region. I can get the legend to plot
2010 Nov 08
2
Several lattice plots on one page
Dear all,
I am trying (!!!) to generate pdfs that have 8 plots on one page:
df = data.frame(
day = c(1,2,3,4),
var1 = c(1,2,3,4),
var2 = c(100,200,300,4000),
var3 = c(10,20,300,40000),
var4 = c(100000,20000,30000,4000),
var5 = c(10,20,30,40),
var6 = c(0.001,0.002,0.003,0.004),
var7 = c(123,223,123,412),
var8 = c(213,123,234,435),
all = as.factor(c(1,1,1,1)))