similar to: How to specify a variable name in the regression formula without hard coding it

Displaying 20 results from an estimated 3000 matches similar to: "How to specify a variable name in the regression formula without hard coding it"

2011 Sep 08
2
Variable scoping question
I modified an example in the object.size help page to create a function I want to be able to run: "mysize" <- function() { z <- sapply(ls(), function(w) object.size(get(w))) as.matrix(rev(sort(z))[1:5]) } mysize() When I test the lines inside the function it works fine: > z <- sapply(ls(), function(w) object.size(get(w))) > as.matrix(rev(sort(z))[1:5])
2003 Oct 02
4
using a string as the formula in rlm
Hi, I am trying to build a series of rlm models. I have my data frame and the models will be built using various coulmns of the data frame. Thus a series of models would be m1 <- rlm(V1 ~ V2 + V3 + V4, data) m2 <- rlm(V1 ~ V2 + V5 + V7, data) m3 <- rlm(V1 ~ V2 + V8 + V9, data) I would like to automate this. Is it possible to use a string in place of the formula? I tried doing: fmla
2011 Sep 06
1
How to speed up regressions (related to data.frame)
All, I have a function that runs a set of regressions (using the rlm function) and I notice that it run much slower on my 64-bit R than it does on my 32-bit R. I guess the bigger bit size slows it down. Anyway, I looked into Rprof to see how I can speed it up. I saw that 78% of the total time is spent in [.data.frame, so I tried converting my data to a matrix using data.matrix, but then rlm
2009 Jan 21
1
Two similar zoo objects with different structures, how to get same structure?
Dear all, I have a zoo object that has following structure: > str(bldata) zoo [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ... - attr(*, "index")=Classes 'dates', 'times' atomic [1:5219] 7305 7306 7307 7308 7309 ... .. ..- attr(*, "format")= chr "m/d/y" .. ..- attr(*, "origin")= Named num [1:3] 1 1 1970 .. .. ..- attr(*,
2009 Nov 20
3
Remove leading and trailing white spaces
I have a character string and I would like to remove the leading and tailing white spaces. The example for 'sub' shows how to remove the trailing white spaces, but I still can't figure out how to remove both trailing and leading white spaces because I can't find any documentation for what "+$" means or what "\\s+$" means. Maybe its because I don't have a
2006 Apr 06
5
pros and cons of "robust regression"? (i.e. rlm vs lm)
Can anyone comment or point me to a discussion of the pros and cons of robust regressions, vs. a more "manual" approach to trimming outliers and/or "normalizing" data used in regression analysis?
2010 Aug 26
3
Help with ddply to eliminate a for..loop
I created a small example to show something that I do a lot of. "scale" data by month and return a data.frame with the output. "id" represents repeated observations over "time" and I want to scale the "slope" variable. The "out" variable shows the output I want. My for..loop does the job but is probably very slow versus other methods. ddply
2008 Jun 10
1
Sweave, ggplot2 and two-page figures
I am using Sweave to generate a document in which ggplot2 figures are embedded. I am using the following code in a particular plot within a subfloat environment: <<qplotARbosreg, echo = FALSE, fig = TRUE>>= print(qplot(bosday2, Arday2, data= arbostimearonlyNArm, colour=factor(bos2), shape=factor(bos2), size=factor(cumARscore), position="jitter", main="Days to BOS by
2011 Jul 18
1
R on a server (Windows Server 2008)
Apologies for a naive question: Can R be installed and run on a server (operating system Windows Server 2008)? Thank you! -- Dimitri Liakhovitski
2012 Feb 15
1
LaTeX and Sweave on windows
I am completely new to LaTeX and Sweave, so I am trying to follow the tutorial in the following link: http://www.r-bloggers.com/using-latex-r-and-sweave-to-create-reports-in- windows/ I installed MiKTeX 2.9 and TeXnicCenter, but I get a build error when compiler the example file: The two errors are: "Error: running 'texi2dvi' on 'test.tex' failed" and "R> !
2010 Mar 23
2
Creating pdfs using qplot in qqplot2
I am trying to create plots within a for loop and output them to a pdf. Here is a working example using plot: gg <- data.frame(datadate=1:4, spread=5:8) pdf() for (i in 1:3) { plot(gg$datadate, gg$spread, main=i) } dev.off() I am trying to learn more about ggplot2 so I try a slight modification and it doesn't work. Anyone
2008 Aug 20
1
How to send Html using SQL Server db mail
All, I have a variable called `go` and it has a single quote in the name column of line 47 that I am trying to get rid of. I have tried using gsub, but I cannot get the syntax correct to tell R to remove the ' (single quote). > go[47,] gvkey Symbol Name Rank MarketCap MemoDate Action Analyst Reason SharesHeld 75 065105 BJ BJ'S WHOLESALE CLUB INC 0.9579
2005 Aug 16
4
as.character and a formula
Dear list, given this formula: > fmla <- formula(y1 ~ spp1 + spp2 + spp3 + spp5) > fmla[[3]] spp1 + spp2 + spp3 + spp5 is this the intended behaviour of as.character: > as.character(fmla[[3]]) [1] "+" "spp1 + spp2 + spp3" "spp5" ? Where does the extra "+" come from? > as.character(fmla) [1] "~"
2007 Feb 22
3
How to print a double quote
Can anyone tell me how to get R to include a double quote in the middle of a character string? For example, the following code is close: > fnd<-"Open fnd 'test'" > cat(fnd) Open fnd 'test'> > But instead of Open fnd 'test' I need: Open fnd "test". Difference seems minor, but I am writing batch files for another
2008 May 02
1
How to parse XML
I would like to learn how to parse a mixed text/xml document I downloaded from the sec.gov website (see example below). I would like to parse this to get the value for each xml tag and then access it within R, but I don't know much about xml so I don't even know where to start debugging the errors I am getting in this example code. Can anyone help me get started? Thanks, Roger ftp
2011 Jul 12
2
foreach not recognizing functions in memory
All, I am not understanding the scoping used in foreach when it is used inside a function. I keep getting "could not find function" errors for functions that are in memory when I try to use foreach within a function call. I have a simple example below. "testFun" is in memory and works when called by foreach directly, but when I place foreach in a function called
2007 Mar 01
2
FTP download from ftp.sec.gov
All, I have managed to download files from web sites and ftp sites using R, so just for fun I tried to do so from the SEC's ftp site using the following code: ftp <- "ftp://anonymous:test at ftp.sec.gov/edgar/full-index/company.idx" download.file(url=ftp, destfile="test.txt") And it does not work. R says it cannot open the URL. If I paste the ftp part into IE it
2011 Sep 19
1
Constrained regressions (suggestions welcome)
All, Could anyone recommend a package that allows the user to constrain the coefficients from a multiple regression equation? I tried using the gl1ce function in lasso2, but couldn't get it to work. I created a contrived example to illustrate my starting point. data(cars) fmla <- formula(dist ~ speed) gl1c.E <- gl1ce(fmla, data = cars) gl1c.E gl1c.E <- gl1ce(fmla, data =
2012 Feb 28
2
update.formula has 512 char buffer?
Hello, I am trying to "paste" together a formula to use in the mob function of party. This means the formula will be of the form y ~ x1+ ...+xM | z1+..zN. I am doing some preliminary fits of y ~ x1+ ...+xM, then want to add the conditional part of the equation using update(). Here's the test code: var1 <- 1:78 x1 <- paste("x", var1, sep="") f1 <-
2012 Jan 25
4
formula error inside function
I want use survfit() and basehaz() inside a function, but it doesn't work. Could you take a look at this problem. Thanks for your help. Following is my codes: library(survival) n <- 50 # total sample size nclust <- 5 # number of clusters clusters <- rep(1:nclust,each=n/nclust) beta0 <- c(1,2) set.seed(13) #generate phmm data set Z <- cbind(Z1=sample(0:1,n,replace=TRUE),