Displaying 20 results from an estimated 1776 matches for "x3".
Did you mean:
0x3
2006 Jul 08
2
String mathematical function to R-function
hello
I make a subroutine that give-me a (mathematical)
function in string format.
I would like transform this string into function ( R
function ).
thanks for any tips.
cleber
#e.g.
fun_String = "-100*x1 + 0*x2 + 100*x3"
fun <- function(x1,x2,x3){
return(
############
evaluation( fun_String )
############
)
True String mathematical function :-( :-(
> nomes
[1] "8.49*x1*z1 + 6.13*x1*z2 + 6.4*x1*z3 + 6.9*x2*z1 +
4.54*x2*z2 + 3.99*x2*z3 + 19.31*x3*z1 + 12.49*x3*z2 +
3.86*x3*z3 + 5.25*x1*z1*z...
2008 Mar 29
1
Tabulating Sparse Contingency Table
I have a sparse contingency table (most cells are 0):
> xtabs(~.,data[,idx:(idx+4)])
, , x3 = 1, x4 = 1, x5 = 1
x2
x1 1 2 3
1 0 0 31
2 0 0 112
3 0 0 94
, , x3 = 2, x4 = 1, x5 = 1
x2
x1 1 2 3
1 0 0 0
2 0 0 0
3 0 0 0
, , x3 = 3, x4 = 1, x5 = 1
x2
x1 1 2 3
1 0 0 0
2 0 0 0
3 0 0 0
, , x3 =...
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 by setting my...
2010 Dec 14
2
How to bind models into a list of models?
...rmula contained within quotation marks. Here's what it
looks like:
> dd
[1] "lm(y ~ 1,data=Cement)" "lm(y ~
X,data=Cement)" "lm(y ~ X1,data=Cement)"
[4] "lm(y ~ X2,data=Cement)" "lm(y ~
X3,data=Cement)" "lm(y ~ X4,data=Cement)"
[7] "lm(y ~ X + X1,data=Cement)" "lm(y ~ X +
X2,data=Cement)" "lm(y ~ X + X3,data=Cement)"
[10] "lm(y ~ X + X4,data=Cement)" "lm(y ~ X1...
2005 Oct 05
0
Ad: Re: Ad: Re: R crashes for large formulas in lm() (PR#8180)
Dette er en melding med flere deler i MIME-format.
--=_alternative 004C4E4A00257091_=
Content-Type: text/plain; charset="US-ASCII"
Yes.
so (x1*x2*x3*x4*x5*x6*x7*x8)^2 = (x1+x2+x3+x4+x5+x6+x7+x8)^8 ?
and there is a difference in
(x1*x2*x3*x4*x5*x6*x7*x8)^2
and
(x1*x2*x3*x4*x5*x6*x7*x8)
althoug the resulting formulas are the same, or?
This fikses my problem, but R still crashes for the large formula. It may
be due to stack owerflow, but i guess...
2009 Mar 31
5
Using apply to get group means
...le. For example, if I were measuring weight, I might want to have each individual's weight, and also the group mean by, say, race, sex, and geographic region. The following code works:
> x1<-rep(c("A","B","C"),3)
> x2<-c(rep(1,3),rep(2,3),1,2,1)
> x3<-c(1,2,3,4,5,6,2,6,4)
> x<-as.data.frame(cbind(x1,x2,x3))
> x3.mean<-rep(0,nrow(x))
> for (i in 1:nrow(x)){
+ x3.mean[i]<-mean(as.numeric(x[,3][x[,1]==x[,1][i]&x[,2]==x[,2][i]]))
+ }
> cbind(x,x3.mean)
x1 x2 x3 x3.mean
1 A 1...
2005 Oct 05
0
Ad: Re: R crashes for large formulas in lm() (PR#8180)
On Wed, 5 Oct 2005 Hallgeir.Grinde at elkem.no wrote:
> And some more informastion I forgot.
> R does not crash if I write out the formula:
>
> set.seed(123)
> x1 <- runif(1000)
> x2 <- runif(1000)
> x3 <- runif(1000)
> x4 <- runif(1000)
> x5 <- runif(1000)
> x6 <- runif(1000)
> x7 <- runif(1000)
> x8 <- runif(1000)
> y <- rnorm(1000)
> fit <- lm(y~(x1*x2*x3*x4*x5*x6*x7*x8)^2)
> -> R crashes
>
> fit <- lm(y~x1+x2+x3+x4+x5+x6+x7+x8
>...
2005 Oct 05
0
Ad: Re: Ad: Re: R crashes for large formulas in lm() (PR#8181)
On Wed, 5 Oct 2005 Hallgeir.Grinde at elkem.no wrote:
> Yes.
> so (x1*x2*x3*x4*x5*x6*x7*x8)^2 = (x1+x2+x3+x4+x5+x6+x7+x8)^8 ?
Yes in the sense that the simplified formula given by terms() is the same.
> and there is a difference in
> (x1*x2*x3*x4*x5*x6*x7*x8)^2
> and
> (x1*x2*x3*x4*x5*x6*x7*x8)
> althoug the resulting formulas are the same, or?
The first...
2006 Oct 27
2
all.names() and all.vars(): sorting order of functions' return vector
Dear list-subscriber,
in the process of writing a general code snippet to extract coefficients
in an expression (in the example below: 0.5 and -0.7), I stumbled over
the following peculiar (at least peculiar to me:-) ) sorting behaviour
of the function all.names():
> expr1 <- expression(x3 = 0.5 * x1 - 0.7 * x2)
> all.names(expr1)
[1] "-" "*" "x1" "*" "x2"
> all.vars(expr1)
[1] "x1" "x2"
> expr2 <- expression(x3 <- 0.5 * x1 - 0.7 * x2)
> all.names(expr2)
[1] "<-" "x3" &q...
2012 Dec 04
3
reformatting some data
Hello,
I am trying to reformat some data so that it is organized by group in the
columns. The data currently looks like this:
group X3.Hydroxybutyrate X3.Hydroxyisovalerate ADP
347 4 4e-04 3e-04 5e-04
353 3 5e-04 3e-04 6e-04
359 4 4e-04 3e-04 6e-04
365 4 6e-04...
2009 Feb 23
2
Formula that includes previous row values
Hi R users,
Is there an easy way in R to generate the results table below using table 1
and the formula (simplified version of the real problem)? It would be easy
if I knew the R equivalent of SAS's retain function, but could not find one.
Thanks in Advance for any help!
table1:
ID X2 X3
1.00 1.00 0
2.00 0.00
3.00 1.00
4.00 3058
5.00 0.00
6.00 6.00
Formula: X3 = x2 + (.24 * x3)
where the values in the x3 column of the result table are retained from
previous x3 rows.. Also the first x3 value is initialized to 0 to start
e.g.
for ID=1 we have 1 + .24(0) = 1.0...
2004 Feb 18
4
How to repeat a procedure
Hello,
1. After I generate a 100x50 matrix by x3<-matrix(0,100,50);for (i in
1:100) {x1<-rpois(50, mu[i]);x2<-x1; x2[runif(50)<.01]<-0; x3[i,]<-x2},
2. I want to calculate means and sample variances of each row and create a
new matrix 100x2;
3. I then want to repeat above procedure 500 times so that eventually I
will have 500...
2012 Feb 13
3
mgcv: increasing basis dimension
hi
Using a ts or tprs basis, I expected gcv to decrease when increasing the
basis dimension, as I thought this would minimise gcv over a larger
subspace. But gcv increased. Here's an example. thanks for any comments.
greg
#simulate some data
set.seed(0)
x1<-runif(500)
x2<-rnorm(500)
x3<-rpois(500,3)
d<-runif(500)
linp<--1+x1+0.5*x2+0.3*exp(-2*d)*sin(10*d)*x3
y<-rpois(500,exp(linp))
sum(y)
library(mgcv)
#basis dimension k=5
m1<-gam(y~x1+x2+te(d,bs="ts")+te(x3,bs="ts")+te(d,x3,bs="ts"),family="poisson")
#basis dimension k=10...
2008 Jul 03
3
apply with a division
Hi,
I'd like to normalize a dataset by dividing each row by the first row.
Very simple, right?
I tried this:
> expt.fluor
X1 X2 X3
1 124 120 134
2 165 163 174
3 52 51 43
4 179 171 166
5 239 238 235
>first.row <- expt.fluor[1,]
> normed <- apply(expt.fluor, 1, function(r) {r / first.row})
>normed
[[1]]
X1 X2 X3
1 1 1 1
[[2]]
X1 X2 X3
1 1.330645 1.358333 1.298507
[[3]]
X1...
2012 Jan 05
1
delete.response leaves response in attribute dataClasses
...the name of the dependent variable first in the in
"dataClasses". It caused an unexpected behavior in my code, so (as
usual) the bug may be mine, but in my heart, I believe it belongs to
delete.response.
To illustrate, here's a terms object from a regression.
> tt
y ~ x1 * x2 + x3 + x4
attr(,"variables")
list(y, x1, x2, x3, x4)
attr(,"factors")
x1 x2 x3 x4 x1:x2
y 0 0 0 0 0
x1 1 0 0 0 1
x2 0 1 0 0 1
x3 0 0 1 0 0
x4 0 0 0 1 0
attr(,"term.labels")
[1] "x1" "x2" "x3"...
2017 Oct 12
2
Bug in model.matrix.default for higher-order interaction encoding when specific model terms are missing
...ariables when the full hierarchy of effects is not present. Depending on
which lower level interactions are specified, the factor encoding changes
for a higher level interaction. Consider the following minimal reproducible
example:
--------------
> runmatrix = expand.grid(X1=c(1,-1),X2=c(1,-1),X3=c("A","B","C"))> model.matrix(~(X1+X2+X3)^3,data=runmatrix) (Intercept) X1 X2 X3B X3C X1:X2 X1:X3B X1:X3C X2:X3B X2:X3C X1:X2:X3B X1:X2:X3C
1 1 1 1 0 0 1 0 0 0 0
0 0
2 1 -1 1 0 0 -1 0 0...
2009 Jun 08
5
if else
Hi R-helpers!
I have the following dataframe:
firm<-c(rep(1:3,4))
year<-c(rep(2001:2003,4))
X1<-rep(c(10,NA),6)
X2<-rep(c(5,NA,2),4)
data<-data.frame(firm, year,X1,X2)
data
So I want to obtain the same dataframe with a variable X3
that is:
X1, if X2=NA
X2, if X1=NA
X1+X2 if X1 and X2 are not NA
So my final data is
X3<-c(15,NA,12,5,10,2,15,NA,12,5,10,2)
finaldata<-data.frame(firm, year,X1,X2,X3)
I've tried this
finaldata<-ifelse(data$X1==NA,ifelse(data$X2==NA,NA,X2),ifelse(data$varvendas==NA,X1,X1+X2))
But I g...
2007 Apr 08
1
Relative GCV - poisson and negbin GAMs (mgcv)
...m I totally missing something (I'm quite new to this, as I'm sure is obvious). Why such a difference in GCV change between poisson and negbin?
Thanks in advance!
Jordan
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 <- runif(n, 0, 1)
f0 <- function(x) 2 * sin(pi * x)
f1 <- function(x) exp(2 * x)
f2 <- function(x) 0.2*x^11*(10*(1-x))^6+10*(10*x)^3*(1-x)^10
f <- f0(x0) + f1(x1) + f2(x2)
g<-exp(f/4)
y<-rpois(rep(1,n),g)
summary(gam(y~s(x0)+s(x1)+s(x2)+s(x3),family=poisson,scale=-1))$gcv
summa...
2005 Oct 05
1
Ad: Re: R crashes for large formulas in lm() (PR#8180)
Dette er en melding med flere deler i MIME-format.
--=_alternative 004613C000257091_=
Content-Type: text/plain; charset="US-ASCII"
And some more informastion I forgot.
R does not crash if I write out the formula:
set.seed(123)
x1 <- runif(1000)
x2 <- runif(1000)
x3 <- runif(1000)
x4 <- runif(1000)
x5 <- runif(1000)
x6 <- runif(1000)
x7 <- runif(1000)
x8 <- runif(1000)
y <- rnorm(1000)
fit <- lm(y~(x1*x2*x3*x4*x5*x6*x7*x8)^2)
-> R crashes
fit <- lm(y~x1+x2+x3+x4+x5+x6+x7+x8
+x1:x2+x1:x3+x1:x4+x1:x5+x1:x6+x1:x7+x1:...
2012 May 29
2
setting parameters equal in lm
Forgive me if this is a trivial question, but I couldn't find it an answer
in former forums. I'm trying to reproduce some SAS results where they set
two parameters equal. For example:
y = b1X1 + b2X2 + b1X3
Notice that the variables X1 and X3 both have the same slope and the
intercept has been removed. How do I get an estimate of this regression
model? I know how to remove the intercept ("-1" somewhere after the tilde).
But how about setting parameters equal? I have used the car package to...