[R] Goodreader: Scrape and Analyze 'Goodreads' Book Data

2024-09-03 Thread Chao Liu
ids(input_data = AI_df, file_name = "AI_books.txt") # Get book-related information scrape_books(book_ids_path = "AI_books.txt") # Scrape book reviews scrape_reviews(book_ids_path = "AI_books.txt", num_reviews = 10) For more details, please visit: https://liu-chao.site/G

Re: [R] Error in if (class(networks) == "matrix") from a function

2022-09-22 Thread Chao Liu
if(is.matrix(networks)) > > i.e., I'd try to see if the fast is.matrix(.) applies to your 'networks' > (and I'm guessing "yes" with high confidence ..). > > Martin > > > HTH, > > Eric > > > > On Wed, Se

[R] Error in if (class(networks) == "matrix") from a function

2022-09-21 Thread Chao Liu
Dear R-Help community, This is a crosspost on SO but I've had no luck so far. So I have a function which computes a centrality index for the nodes in a network or matrix. Here is the function: library(igraph) #load package igraph centrality <- function (networks, type = c("indegree", "outdegree",

[R] Simulate type I error

2022-01-26 Thread Chao Liu
Dear R-help community, I would like to simulate type I error for a random-effects model I generated. The statistic of interest is standard deviations of the random intercept and random slope. Specifically, for random intercept, H_{0}: lambda_{0} =2 and H_{1}: lambda_{0} not equal to 2; for random

[R] Problem with updating terms in the multinom function

2021-03-30 Thread Chao Liu
Dear R-help, I am trying to add1() all interaction terms on top of a multinomial baseline model using multinom() but it shows the error "trying + x1:x2 Error in if (trace) { : argument is not interpretable as logical Called from: nnet.default(X, Y, w, mask = mask, size = 0, skip = TRUE, softmax =

Re: [R] Alternative to mapply to select samples

2021-02-04 Thread Chao Liu
1) > > blf <- bl_func() > > set.seed(111) > > blm <- mapply(sample, bl, kn, replace=TRUE) > > all.equal(blf, blm) > [1] TRUE > > > Cheers > Petr > > > -Original Message- > > From: R-help On Behalf Of Chao Liu > > Sent: Tuesday, Fe

[R] Alternative to mapply to select samples

2021-02-02 Thread Chao Liu
Dear R-Help, I created a mapply function to select samples from a dataset but are there any faster ways to do it by avoiding mapply because it is slow and I have a larger dataset? My goal is to use more matrix / vector operations and less in terms of lists (the format of the output can be flexible

Re: [R] Print out progress reports of add1()

2021-01-18 Thread Chao Liu
Thank you Duncan. Do you by chance know any way around this? On Mon, Jan 18, 2021 at 11:58 AM Duncan Murdoch wrote: > You are using add1 on an "lm" object, and add1.lm doesn't have a trace > parameter. > > Duncan Murdoch > > On 18/01/2021 10:55 a.m., Chao Liu

[R] Print out progress reports of add1()

2021-01-18 Thread Chao Liu
I have a few questions about using add1(). First of all, according to the R document of add1(), the trace = TRUE function prints out progress reports but my attempts to do this have failed several times. So how do we print out the progress reports of adding terms to the model so as to test for impr

Re: [R] Use mapply or lapply to a nested list

2020-12-22 Thread Chao Liu
do exactly what you request but worth a > look. > > Jim > > On Tue, Dec 22, 2020 at 6:36 AM Chao Liu wrote: > > > > I want to apply a sample function to a nested list (I will call this list > > `bb`) and I also have a list of numbers (I will call this list `k`) to

[R] Use mapply or lapply to a nested list

2020-12-21 Thread Chao Liu
I want to apply a sample function to a nested list (I will call this list `bb`) and I also have a list of numbers (I will call this list `k`) to be supplied in the sample function. I would like each of the numbers in k to iterate through all the values of each list in bb. How to do this using `mapp

Re: [R] Problem in cluster sampling: 'mixed with negative subscripts'

2020-12-19 Thread Chao Liu
66 0.5672552 > # What the extraction operator does is attempt to get valid {positive} > integer indices > # or zeros. Then it can use the positive values and discard the zeros > as.integer(abs(x1)) > [1] 0 1 0 0 1 3 2 1 0 0 > > Now the error message makes a lot more sense. &g

[R] Problem in cluster sampling: 'mixed with negative subscripts'

2020-12-19 Thread Chao Liu
Hi, I was trying to do a cluster sampling but came across this error: Error in xj[i] : only 0's may be mixed with negative subscripts. What is the cause and how to get around? Thank you for your help! Here is the code: #simulate some data y <- rnorm(20) x <- rnorm(20) z <- rep(1:5, 4) w <- rep(1

Re: [R] Help with simulation of unbalanced clustered data

2020-12-17 Thread Chao Liu
Thank you for your help Abby! On Wed, Dec 16, 2020 at 11:32 PM Abby Spurdle wrote: > Hi Chao Liu, > > I'm having difficulty following your question, and examples. > And also, I don't see the motivation for increasing, then decreasing > the sample sizes. > Intuit

Re: [R] Help with simulation of unbalanced clustered data

2020-12-16 Thread Chao Liu
you are stuck or why the result you are getting does not exhibit the > desired properties. > > On December 15, 2020 6:48:12 PM PST, Chao Liu > wrote: > >Dear R experts, > > > >I want to simulate some unbalanced clustered data. The number of > >clusters > &

[R] Help with simulation of unbalanced clustered data

2020-12-16 Thread Chao Liu
Dear R experts, I want to simulate some unbalanced clustered data. The number of clusters is 20 and the average number of observations is 30. However, I would like to create an unbalanced clustered data per cluster where there are 10% more observations than specified (i.e., 33 rather than 30). I t