[R] Getting and using a function

2007-04-13 Thread Thomas L Jones
I am trying to do what is perhaps the most basic procedure which can be done 
with the R software.

Under Windows XP Home Edition, I want to get a copy of the function gam, 
then put it in and use it. I intentionaly use informal terms, rather than 
technical terms whose exact meaning I might or might not know.

I am finding this extremely frustrating. Every time I try to do anything, 
all I get is error messages. Hey, this isn't rocket science; there are only 
three or four or five steps involved. Well, what are they? There is all this 
opaque terminology. There are libraries, and packages, and one downloads 
them, loads them, and installs them, but just what all this means is 
unclear.

One example among many: I tell it

library (gam)  all I get is an error message.

Error in library (gam)  : there is no package called 'gam'

Well, does this mean what it says, or does it mean something different? For 
example, does it mean that such-and-such computer program has not yet been 
downloaded?

I did download and install the 2.4.1 flavor (version?) of the gui. I infer, 
reading between the lines a bit, that there may be a sort of standard 
procedure for setting things up, perhaps downloading and installing the 
utils package, or something.

The R software has much gold in it, but, as far as learnability/usability is 
concerned, I give it poor marks.

Tom Jones
DrJones at alum.MIT.edu

__
[EMAIL PROTECTED] 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] go or goto command

2007-01-10 Thread Thomas L Jones
Some computer languages, including C, have a go or go to command 
which can be used to shift control to a different part of a function.

Question: Does the R language have a corresponding command? (Yes, I am 
aware that it can be abused; but, in the hands of a good programmer, 
it is simple to use.)

Tom Jones

__
R-help@stat.math.ethz.ch 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] Question about predict function

2006-12-27 Thread Thomas L Jones
I am working with a non-parametic smoothing operation using a 
Generalized Additive Model. It is a bivariate data set. I know how to 
do the smooth, and out comes a nice smooth curve.

Now I want to find the value of the smoothed curve for several values 
of x (the abscissa). This can be done (please correct me if I am 
wrong) by using the predict.gam function. You feed the predict.gam 
function a data frame, telling it what you want.

Let's start with the predict.gam function. Are you supposed to be able 
to look up how to use it? E.g., what goes into the various columns of 
the data frame? I do have a working function call for predict. It 
says:

pred_out - predict (mod, data.frame (x = x), type = response)

(mod is the model)

Now, if you tell me that x = x, I will believe you. But what is meant 
by data.frame (x = x), I know not.

Or would it better to call the class, names, and str functions, using 
some well chosen objects?

Tom Jones

__
R-help@stat.math.ethz.ch 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] Extracting the results of a gam smooth

2006-04-15 Thread Thomas L Jones
I am conducting a gam smooth and having a devil of a time getting out 
the answers so I can work with them.

Here are the two lines of code:

 model - gam(y~lo(x, span=0.75, degree=2), family=poisson)

 resp_pout - predict (model, data.frame (x=x), type = 'response')

The problem comes when I try to get the answers out. I cannot for the 
life of me figure out the format of resp_pout, and I have been trying 
literally for WEEKS to get the answer. Surely this is a perfectly 
standard question which has been asked and answered dozens of times. 
Let's see if I can rephrase the question.

There are 118 response points generated by the smoothing operation. I 
need a function f such that v - f(resp_pout) is a vector with 118 
components comprising the 118 response points. Would some kind soul 
provide it? Or is my entire research effort going to be BLOWN UP 
because I can't figure out how to do this?

Thomas Jones

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Finding the format of an object redux

2006-04-13 Thread Thomas L Jones
Okay, I am dealing with an object. Without going into too much detail, 
a gam (Generalized Additive Model) is involved. Assume that the name 
of the object is obj without the quotes. I tell it:

print (obj) inside a function.

I get out a bunch of pairs of lines.

(1) Odd-numbered lines are integers.
(2) Even-numbered lines have real/floating point numbers.

For example, the first two lines are:

   1234567 
8
5.354175 5.328358 5.293970 5.264434 5.235172 5.206112 5.177180 
5.148305

[snip]

The last two integers are 117 and 118; the corresponding real numbers 
are 4.354862 and 4.196938.

Jeepers, creepers, what does all this -MEAN?- Are the integers part of 
the object, or are they indices or subscripts or names or something?

The value of class (obj) is numeric including the quotes.
The value of is.numeric (obj) is TRUE.
The value of length (obj) is 118.

Well, is this a data frame or a matrix or a table or a vector whose 
elements are vectors of length two? Or a vector with two elements, 
each of which is a vector of length 118? Surely there is a way of 
finding out the answer to this question. Every time I look at the 
documentation, it just tells me to look somewhere else. Is there a 
function f such that f (obj) will tell you a little bit about the 
format of the object?

Tom
Thomas L. Jones, Ph.D., Computer Science

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Finding out the format of an object

2006-04-06 Thread Thomas L Jones
Suppose I have an arbitrary R object. Is there a way to find out its 
format? There are 118 points, each described by two numbers. Let the 
name of the object be obj without the quotes. I can do a print 
(obj), but all I get is a bunch of numbers. I can do a ls.str (obj), 
but all I get is a bunch of numbers. Is it a data frame? A vector with 
118 elements, each having two sub-elements? Or ---?

The object in question is of the class gam (Generalized Additive 
Model). I know how to pull out some data with the predict function, 
but, when I try to print the value of the predict function, all I get 
is a bunch of numbers.

Also, how could I have looked this up without having to post a 
question here?

Tom
Thomas L. Jones, Ph.D., Computer Science

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Debugging a program written in the R language

2006-03-08 Thread Thomas L Jones
From Tom:

The subject is debugging a program written in the R language,under 
Windows. (Sorry, but I do not know either the Apple OS or *nix.) A 
computer program will usually not work on the first try, if only 
because of the risk of typos. Instead, it must be debugged. Roughly, 
here is the sequence:

(1) One codes a program using the R language,  and stores it on the 
hard drive, using some particular editor.

(2) The program is fed to the R software, together with test data, 
etc.

(3) A test computation is run and bugs are spotted.

(4) The program is corrected, using an editor, and the revised version 
is stored on the hard drive.

(5) The sequence goes back to step (2) and is repeated until the 
program hopefully works.

Unfortunately, the documentation doesn't really explain how to do all 
of this, or if it is explained in the documentation, I can't find it.

Reading between the lines a bit, I infer that you are supposed to be 
able to use something called a History file, then sort of work 
backward in the code and make corrections. I never got it to work for 
me. Also, it is unclear how you would handle code entered six weeks or 
six months ago.

That is the bad news; the good news is that some kind soul told me 
about a key trick; prepare the program in Windows text format (.txt) 
and copy it and paste it into the console. The program will now run 
from a user-defined wrapper or driver function.

I am aware that there is an editor called Emacs which you can use if 
you are a member of the *nix community, which I am not.

Question: How are you -supposed- to debug a program which you have 
written in the R language?

Tom
Thomas L. Jones, Ph.D., Computer Science

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] How do I tell it which directory to use?

2006-02-21 Thread Thomas L Jones
From Tom:

In R 2.2.0 under Windows, I want to be able to give it a filename such 
as myFile.txt without the quotes. But actually I mean:

C:\Documents and Settings\Tom\My Documents\qpaper7\R Project Started 
19 Dec 05\myFile.txt

If I were to repeat this each time, my computer would get all bored 
and cranky and start to drop bits (only a joke, of course). I think I 
want to set the Home directory or the working directory or some 
directory or other to the above directory. I may or may not want to 
set some environmental variables.

R 2.2.0; working directly from the console and copying and pasting 
code which I want to test into the console. Windows XP Home Edition. 
Administrator privileges are enabled. A curve ball: There are two 
accounts, Tom and Jones; the data are stored under Tom, whereas 
the computation is being done under the Jones account. I won't bore 
you with the details of why I am doing this.

I was able to call Sys.getenv (R_USER) and get the home directory.

I am a newbie to R and not familiar with the terminology.

Tom
Thomas L. Jones, Ph.D., Computer Science

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Scatterplot with corner at (0, 0)

2006-02-06 Thread Thomas L Jones
I have two vectors, x and y, and I want to create a scatterplot. I 
want the lower left corner to be at (0, 0). I can create a scatterplot 
just by calling plot (x, y), but I am quite throroughly stymied and 
frustrated by the problem of putting the lower left corner at (0, 0), 
despite many tries.

Thomas L. Jones, Ph.D., Computer Science

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] (newbie) Saving the workspace in .txt format

2006-02-02 Thread Thomas L Jones
(newbie question) How do I save the workspace in Windows text format 
(with the file extension .txt)? Also, having saved it and edited it, 
how do I load it back into the workspace?

The setup is:

Windows XP Home Edition Service Pack 2
R 2.2.0
English language
Administrator privileges are enabled

Tom Jones, a veteran computer professional who is a newbie to R

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Defining and running a simple function

2006-02-01 Thread Thomas L Jones
I am trying, with extremely limited success, to get the R software to 
do some simple computations. Specifically, I defined a test function 
as follows:

fn - function () {

hw - hello world

hw

s - seq (0, 0.98, 0.02)

s

}

The output should just be the words hello world, followed by a 
sequence going from 0 to 0.98.

However, when I call the little test function:

fn ()

the words hello world get lost and do not come out. Instead, the 
output begins with

[1] 0.00 0.02, etc

However, when I write a test function for just the words hello 
world, the words come out just fine.

Here is the setup:

R-2.2.0 using the English language and the console
Windows XP Home Edition Service Pack 2
AVG Antivirus Free Version
Windows built-in firewall
The R buffered output is disabled.
Mozilla Firefox 1.5
Administrator privileges are enabled.

Your advice?

Tom Jones

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Newbie question--locally weighted regression

2006-01-04 Thread Thomas L Jones

I have a dataset, a time series comprising count data at five minute
intervals. These are the number of people who voted at a particular
voting place during a recent election. The next step is to smooth the
data and estimate a demand vs time-of-day function; the problem is of
interest in preventing long lines at voting places. I am using the R
Project software.

However, I am not a statistician, and I am somewhat baffled by how to
do the smoothing. These are integers with roughly Poisson
distribution, and the use of a least-squares regression would create
large errors. Apparently something called a link function factors
into the equation somehow.

Question: Do I want a link function? If so, do I want a logarithmic
link function? Unless I change my mind, I will use lowess or loess for
the smoothing; how do I tell it to use a link function?

Doc

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] An embarrassment of riches

2006-01-02 Thread Thomas L Jones
I have a dataset which I am trying to smooth, using locally weighted 
regression. The y values are count data, integers with Poisson 
distribution, and it is important for the regression function to know 
this, since assuming a Gaussian distribution will lead to substantial 
errors. It is a time series; the x values have equal five minute 
intervals.

Here is the problem: I have an embarrassment of riches. Unless I am 
mistaken, the following R packages will do this: locfit, aws, sm, gss, 
semipar, pgam, gregmisc, to name just a few. Questions: Which package 
should I use, and which function in the package should I use for the 
regression?

Here is the Google search result, restricted to r-project.org:

http://www.google.com/search?as_q=locally+weighted+poisson+regressionnum=10hl=enbtnG=Google+Searchas_epq=as_oq=as_eq=lr=as_ft=ias_filetype=as_qdr=allas_occt=anyas_dt=ias_sitesearch=r-project.orgas_rights=safe=images

If the above hyperlink does not work, please try 
http://tinyurl.com/exw7e

Doc

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Bookmarking a page inside r-project.org

2006-01-02 Thread Thomas L Jones
By way of review, most large Web sites allow the user to create 
*bookmarks* which link to pages inside the Web site. However, here, 
the pages have one of just two URL's:

http://www.r-project.org and

http://cran.r-project.org

The reason is the way HTML *frames* are used in setup of the Web site. 
It would be very helpful if the Web site were revised so that many if 
not most pages had their own URL's, allowing the use of bookmarks.

Tom
Thomas L. Jones, Ph.D., Computer Science

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] More on bookmarking a page

2006-01-02 Thread Thomas L Jones
The subject is how to bookmark a page inside r-project.orgFrom Peter 
Dalgaard:At least in Firefox, one thing you can do is to bring up the 
relevant
link in a new window or tab (just right-click it) and bookmark 
that.From
 
Thomas Jones:Well, learn something every day! I stand corrected.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] loess smoothing question

2005-12-19 Thread Thomas L Jones
I am trying to smooth a dataset with evenly spaced values of x, 
perhaps using loess smoothing or something similar. However, the y 
values are hypergeometrically distributed; I think I want to use a 
logarithmic link function. It falls under the general heading of 
non-parametric regression. The problem is of interest in predicting 
the demand at a voting place, in order to avoid long lines.

Questions: Should I use loess smoothing?
   Do I want a logarithmic link function? If so,
   How do I tell loess to use a logarithmic link function?

Tom, a newbie to the R project, and not really a statistician

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html