similar to: How to get objects from a "formula" specification?

Displaying 20 results from an estimated 20000 matches similar to: "How to get objects from a "formula" specification?"

2008 Mar 27
1
A faster way to compute finite-difference gradient of a scalar function of a large number of variables
Hi All, I would like to compute the simple finite-difference approximation to the gradient of a scalar function of a large number of variables (on the order of 1000). Although a one-time computation using the following function grad() is fast and simple enough, the overhead for repeated evaluation of gradient in iterative schemes is quite significant. I was wondering whether there are
2006 Sep 29
2
X-axis labels in histograms drawn by the "truehist" function
Hi, I have a simple problem that I would appreciate getting some tips. I am using the "truehist" function within an "apply" call to plot multiple histograms. I can't figure out how to get truehist to use the column names of the matrix as the labels for the x-axis of the histograms. Here is a simple example: X <- matrix(runif(4000),ncol=4) colnames(X)
2009 Jul 01
2
Difficulty in calculating MLE through NLM
Hi R-friends, Attached is the SAS XPORT file that I have imported into R using following code library(foreign) mydata<-read.xport("C:\\ctf.xpt") print(mydata) I am trying to maximize logL in order to find Maximum Likelihood Estimate (MLE) of 5 parameters (alpha1, beta1, alpha2, beta2, p) using NLM function in R as follows. # Defining Log likelihood - In the function it is noted as
2008 Jul 27
1
A easy way to write formula
Hi I have a data frame, including x1, x2, x3, and y. I use lm() to fit second-order linear model, like the following: ft <- lm(y ~ x1 + x2 + x3 + I(x1 * x1) + I(x1 * x2) + I(x1 * x3) + I(x2 * x2) + I(x2 * x3) + I(x3 * x3), mydata) if the independent variable number is large, the formula will be very long. Is there a easy way to write formula like the above one? I have read the R
2009 Jul 23
1
Non-negative solutions to complicated equations
Hi all, I have a system of 3 equations with many defined parameters and 3 variables I need to find solutions to. I actually know the solutions I'm aiming for (0.07,0.287,0.0061) but R tends to give me (0,0,0). I tried the "BB" package but don't really follow how to refine my solutions from that; these are wrong so far. Here's my code from trying that: > f<-function(x){
2009 Apr 07
1
get optim results into a model object
Hello all, I have an optimization routine that is giving me good results, but the results are not in the nice "model" format like "lm". How can I get optim results into a model so that I can use the clever 'fitted', 'residuals', and 'summary' functions? Using optim is the only way that I was able to make a model that 1) sums the betas to 1, 2)
2009 Nov 04
3
Constrained Optimization
Hi All, I'm trying to do the following constrained optimization example. Maximize x1*(1-x1) + x2*(1-x2) + x3*(1-x3) s.t. x1 + x2 + x3 = 1 x1 >= 0 and x1 <= 1 x2 >= 0 and x2 <= 1 x3 >= 0 and x3 <= 1 which are the constraints. I'm expecting the answer x1=x2=x3 = 1/3. I tried the "constrOptim" function in R and I'm running into some issues. I first start off
2008 Apr 09
4
Skipping specified rows in scan or read.table
Hi, I have a data file, certain lines of which are character fields. I would like to skip these rows, and read the data file as a numeric data frame. I know that I can skip lines at the beginning with read.table and scan, but is there a way to skip a specified sequence of lines (e.g., 1, 2, 10, 11, 19, 20, 28, 29, etc.) ? If I read the entire data file, and then delete the character
2009 May 26
2
Linear Regression with Constraints
Hi! I am a bit new to R. I am looking for the right function to use for a multiple regression problem of the form: y = c1 + x1 + (c2 * x2) - (c3 * x3) Where c1, c2, and c3 are the desired regression coefficients that are subject to the following constraints: 0.0 < c2 < 1.0, and 0.0 < c3 < 1.0 y, x1, x2, and x3 are observed data. I have a total of 6 rows of data in a data set. Is
2012 Aug 01
2
sub setting a data frame with binomial responses
Hi everyone, Let me have a dataframe named ?mydata? and created as below, *> n=c(5,5,5,5) #number of trils > x1=c(2,3,1,3) ) #number of successes > x2=c(5,5,5,5) #number of successes > x3=c(0,0,0,0) #number of successes > x4=c(5,0,5,0) #number of successes > mydata=data.frame(n,x1,x2,x3,x4) > mydata* n x1 x2 x3 x4 1 5 2 5 0 5 2 5 3 5 0 0 3 5 1 5 0 5 4 5 3 5 0
2007 Aug 26
3
subset using noncontiguous variables by name (not index)
Hi All, I'm using the subset function to select a list of variables, some of which are contiguous in the data frame, and others of which are not. It works fine when I use the form: subset(mydata,select=c(x1,x3:x5,x7) ) In reality, my list is far more complex. So I would like to store it in a variable to substitute in for c(x1,x3:x5,x7) but cannot get it to work. That use of the c function
2002 Nov 01
1
Manipulating dataframe
Hi: Suppose, I have a dataframe (with N rows) containing the following variables: ID X82 X85 X88 >From this, I'd like to create a new dataframe (with 3*N rows), which will have the following variables: ID X82 X85 X88 Xrep where: each ID is duplicated 3 times; X82 equals its original value for the first row and equals NA for the other two; X85 equals its original value for
2010 Dec 03
1
"Nash Equilibrium"
Dear R experts: I searched cran (and r-help) for "nash equilibrium" and "game" but nothing stuck out. has someone written a numerical nash optimizer for two players? player a has choices x1,x2,x3,... and cares about (maximizes) pa(x1,x2,x3,...,y1,y2,y3) player b has choices y1,y2,y3,..., and cares about (maximizes) pb(x1,x2,x3,...,y1,y2,y3) I can tune it to my problem, but
2009 Aug 02
1
Competing Risks Regression with qualitative predictor with more than 2 categories
Hello, I have a question regarding competing risk regression using cmprsk package (function crr()). I am using R2.9.1. How can I do to assess the effect of qualitative predictor (gg) with more than two categories (a,b,c) categorie c is the reference category. See above results, gg is considered like a ordered predictor ! Thank you for your help Jan > # simulated data to test > set.seed(10)
2010 Sep 02
2
lower triangle of the correlation matrix with xtable
Dear all, mydata<-data.frame(x1=c(1,4,6),x2=c(3,1,2),x3=c(2,1,3)) cor(mydata) x1 x2 x3 x1 1.0000000 -0.5960396 0.3973597 x2 -0.5960396 1.0000000 0.5000000 x3 0.3973597 0.5000000 1.0000000 I wonder if it is possible to fill only lower triangle of this correlation matrix? Using 'dist' doesn't seem to be useful as it doesnt allow to convert this table
2007 Feb 13
1
Missing variable in new dataframe for prediction
Hi, I'm using a loop to evaluate several models by taking adjacent variables from my dataframe. When i try to get predictions for new values, i get an error message about a missing variable in my new dataframe. Below is an example adapted from ?gam in mgcv package library(mgcv) set.seed(0) n<-400 sig<-2 x0 <- runif(n, 0, 1) x1 <- runif(n, 0, 1) x2 <- runif(n, 0, 1) x3 <-
2007 Feb 13
1
Multidimensional Integration over arbitrary sets
Hi, I need to integrate a 2D function over range where the limits depend on the other e.g integrate f(x,y)=x*y over {x,0,1} and {y,x,1}. i.e \int_0^1 \int_x^1 xy dydx I checked adapt but it doesn't seem to help here. Are they any packages for this sort of thing? I tried RSitesearch but couldn't find the answer to this. Many thanks for you help. Regards Saptarshi Saptarshi Guha
2010 Mar 05
1
How to parse the arguments from a function call and evaluate them in a dataframe?
Hi, I would like to write a function which has the following syntax: myfn <- function(formula, ftime, fstatus, data) { # step 1: obtain terms in `formula' from dataframe `data' # step 2: obtain ftime from `data' # step 3: obtain fstatus from `data' # step 4: do model estimation # step 5: return results } The user would call this function as: myfn(formula=myform,
2003 Apr 07
5
How to sort a dataframe?
Dear R-helpers, for the purpose of plotting a dataframe, i am trying to sort a dataframe by one column, for example tester <- data.frame(one=c(3,2,1), two=c(2,3,1)) #> tester # one two #1 3 2 #2 2 3 #3 1 1 # I want to sort "tester" by column "one", so that i get a dataframe # that looks like: #one two #1 1 #2 3 #3 2 I know of 'sort' but
2011 Jan 10
2
Integration in R
Dear all, It has been ages since I studied integration in college. Right now I try to recover all this kind of knowledge and then try to understand how integration works. Thus I am doing some first 'experiments' and I would like to request your help and comments. I have the function: p2<-function(x){0.5*(3*x^2-1)} # I found the square of p2 by using some pencil and